From 9e8a39be415bb4eff098fe8749ae6b6fcc35c7d8 Mon Sep 17 00:00:00 2001 From: Michael Barrett Date: Mon, 25 Jun 2018 09:39:55 -0700 Subject: [PATCH] Add `add_output` helper method on Blueprints (#611) Got sick of constantly typing `Output("Blah", Value="foo")` and figured we could make this easier. --- stacker/blueprints/base.py | 12 +++++++++++- stacker/tests/blueprints/test_base.py | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/stacker/blueprints/base.py b/stacker/blueprints/base.py index c746b3a5b..0db30235e 100644 --- a/stacker/blueprints/base.py +++ b/stacker/blueprints/base.py @@ -6,9 +6,10 @@ from stacker.variables import Variable from troposphere import ( + Output, Parameter, Ref, - Template + Template, ) from ..exceptions import ( @@ -522,6 +523,15 @@ def set_template_description(self, description): """ self.template.add_description(description) + def add_output(self, name, value): + """Simple helper for adding outputs. + + Args: + name (str): The name of the output to create. + value (str): The value to put in the output. + """ + self.template.add_output(Output(name, Value=value)) + @property def requires_change_set(self): """Returns true if the underlying template has transforms.""" diff --git a/stacker/tests/blueprints/test_base.py b/stacker/tests/blueprints/test_base.py index 83639e209..f62443c2c 100644 --- a/stacker/tests/blueprints/test_base.py +++ b/stacker/tests/blueprints/test_base.py @@ -96,6 +96,25 @@ def create_template(self): ) +class TestBaseBlueprint(unittest.TestCase): + def test_add_output(self): + output_name = "MyOutput1" + output_value = "OutputValue" + + class TestBlueprint(Blueprint): + VARIABLES = {} + + def create_template(self): + self.template.add_version('2010-09-09') + self.template.add_description('TestBlueprint') + self.add_output(output_name, output_value) + + bp = TestBlueprint(name="test", context=mock_context()) + bp.render_template() + self.assertEqual(bp.template.outputs[output_name].properties["Value"], + output_value) + + class TestVariables(unittest.TestCase): def test_defined_variables(self):