Пример #1
0
 def test_parameter_values(self, cfngin_context: CfnginContext,
                           tmp_path: Path) -> None:
     """Test parameter_values."""
     obj = RawTemplateBlueprint("test",
                                cfngin_context,
                                raw_template_path=tmp_path)
     assert obj.parameter_values == {}
     obj._resolved_variables = {"var": "val"}  # pylint: disable=protected-access
     del obj.parameter_values
     assert obj.parameter_values == {"var": "val"}
Пример #2
0
 def test_get_required_parameter_definitions_yaml(self):  # noqa pylint: disable=invalid-name
     """Verify get_required_param... method with yaml raw template."""
     blueprint = RawTemplateBlueprint(
         name="test",
         context=MagicMock(),
         raw_template_path=RAW_YAML_TEMPLATE_PATH)
     self.assertEqual(blueprint.get_required_parameter_definitions(),
                      {"Param1": {
                          "Type": "String"
                      }})
Пример #3
0
 def test_get_required_parameter_definitions_json(self, ):
     """Verify get_required_param... method with json raw template."""
     blueprint = RawTemplateBlueprint(
         name="test",
         context=MagicMock(),
         raw_template_path=RAW_JSON_TEMPLATE_PATH)
     self.assertEqual(
         blueprint.get_required_parameter_definitions(),
         {"Param1": {
             "Type": "String"
         }},
     )
Пример #4
0
 def test_variables(self, cfngin_context: CfnginContext,
                    tmp_path: Path) -> None:
     """Test variables."""
     obj = RawTemplateBlueprint("test",
                                cfngin_context,
                                raw_template_path=tmp_path)
     with pytest.raises(UnresolvedBlueprintVariables):
         _ = obj.variables
     # obj.resolve_variables([Variable("Var0", "test")])
     obj._resolved_variables = {"var": "val"}  # pylint: disable=protected-access
     assert obj.variables == {"var": "val"}
     obj.variables = {"key": "val"}
     assert obj.variables == {"key": "val"}
Пример #5
0
 def test_j2_to_json(self):
     """Verify jinja2 template parsing."""
     expected_json = json.dumps(
         {
             "AWSTemplateFormatVersion": "2010-09-09",
             "Description": "TestTemplate",
             "Parameters": {
                 "Param1": {
                     "Type": "String"
                 },
                 "Param2": {
                     "Default": "default",
                     "Type": "CommaDelimitedList"
                 },
             },
             "Resources": {
                 "Dummy": {
                     "Type": "AWS::CloudFormation::WaitConditionHandle"
                 }
             },
             "Outputs": {
                 "DummyId": {
                     "Value": "dummy-bar-param1val-foo-1234"
                 }
             },
         },
         sort_keys=True,
         indent=4,
     )
     blueprint = RawTemplateBlueprint(
         name="stack1",
         context=mock_context(
             extra_config_args={
                 "stacks": [{
                     "name": "stack1",
                     "template_path": "unused",
                     "variables": {
                         "Param1": "param1val",
                         "bar": "foo"
                     },
                 }]
             },
             environment={"foo": "bar"},
         ),
         raw_template_path=RAW_J2_TEMPLATE_PATH,
     )
     blueprint.resolve_variables([
         Variable("Param1", "param1val", "cfngin"),
         Variable("bar", "foo", "cfngin"),
     ])
     self.assertEqual(expected_json, blueprint.to_json())
Пример #6
0
 def test_to_json_cfn_template(self, cfngin_context: CfnginContext) -> None:
     """Test to_json."""
     expected_json = json.dumps(
         {
             "AWSTemplateFormatVersion": "2010-09-09",
             "Description": "TestTemplate",
             "Parameters": {
                 "Param1": {
                     "Type": "String"
                 },
                 "Param2": {
                     "Default": "default",
                     "Type": "CommaDelimitedList"
                 },
             },
             "Resources": {
                 "Dummy": {
                     "Type": "AWS::CloudFormation::WaitConditionHandle"
                 }
             },
             "Outputs": {
                 "DummyId": {
                     "Value": "dummy-1234"
                 }
             },
         },
         sort_keys=True,
         indent=4,
     )
     assert (RawTemplateBlueprint(
         name="test",
         context=cfngin_context,
         raw_template_path=RAW_JSON_TEMPLATE_PATH,
     ).to_json() == expected_json)
Пример #7
0
 def test_version(self, cfngin_context: CfnginContext,
                  mocker: MockerFixture, tmp_path: Path) -> None:
     """Test version."""
     mocker.patch.object(RawTemplateBlueprint, "rendered", "success")
     assert (RawTemplateBlueprint(
         "test", cfngin_context,
         raw_template_path=tmp_path).version == "260ca9dd")
Пример #8
0
 def test_to_json(self):
     """Verify to_json method operation."""
     expected_json = json.dumps(
         {
             "AWSTemplateFormatVersion": "2010-09-09",
             "Description": "TestTemplate",
             "Parameters": {
                 "Param1": {
                     "Type": "String"
                 },
                 "Param2": {
                     "Default": "default",
                     "Type": "CommaDelimitedList"
                 }
             },
             "Resources": {
                 "Dummy": {
                     "Type": "AWS::CloudFormation::WaitConditionHandle"
                 }
             },
             "Outputs": {
                 "DummyId": {
                     "Value": "dummy-1234"
                 }
             }
         },
         sort_keys=True,
         indent=4)
     self.assertEqual(
         RawTemplateBlueprint(
             name="test",
             context=mock_context(),
             raw_template_path=RAW_JSON_TEMPLATE_PATH).to_json(),
         expected_json)
Пример #9
0
 def test_get_parameter_definitions_yaml(self):  # noqa pylint: disable=invalid-name
     """Verify get_parameter_definitions method with yaml raw template."""
     blueprint = RawTemplateBlueprint(
         name="test",
         context=MagicMock(),
         raw_template_path=RAW_YAML_TEMPLATE_PATH)
     parameters = blueprint.get_parameter_definitions()
     self.assertEqual(
         parameters, {
             "Param1": {
                 "Type": "String"
             },
             "Param2": {
                 "Default": "default",
                 "Type": "CommaDelimitedList"
             }
         })
Пример #10
0
 def test_requires_change_set(self, cfngin_context: CfnginContext,
                              mocker: MockerFixture,
                              tmp_path: Path) -> None:
     """Test requires_change_set."""
     mock_to_dict = mocker.patch.object(
         RawTemplateBlueprint,
         "to_dict",
         side_effect=[{
             "Transform": "something"
         }, {}],
     )
     assert RawTemplateBlueprint(
         "test", cfngin_context,
         raw_template_path=tmp_path).requires_change_set
     mock_to_dict.assert_called_once_with()
     assert not RawTemplateBlueprint(
         "test", cfngin_context,
         raw_template_path=tmp_path).requires_change_set
Пример #11
0
 def test_get_parameter_definitions_json(self):
     """Verify get_parameter_definitions method with json raw template."""
     blueprint = RawTemplateBlueprint(
         name="test",
         context=MagicMock(),
         raw_template_path=RAW_JSON_TEMPLATE_PATH)
     parameters = blueprint.get_parameter_definitions()
     self.assertEqual(
         parameters,
         {
             "Param1": {
                 "Type": "String"
             },
             "Param2": {
                 "Default": "default",
                 "Type": "CommaDelimitedList"
             },
         },
     )
Пример #12
0
 def test_get_parameter_definitions(self, cfngin_context: CfnginContext,
                                    mocker: MockerFixture,
                                    tmp_path: Path) -> None:
     """Test get_parameter_definitions."""
     mock_parameter_definitions = mocker.patch.object(
         RawTemplateBlueprint, "parameter_definitions", "success")
     assert (RawTemplateBlueprint(
         name="test", context=cfngin_context,
         raw_template_path=tmp_path).get_parameter_definitions() ==
             mock_parameter_definitions)
Пример #13
0
 def test_required_parameter_definitions_yaml(self) -> None:
     """Verify required_parameter_definitions."""
     blueprint = RawTemplateBlueprint(
         name="test",
         context=MagicMock(),
         raw_template_path=RAW_YAML_TEMPLATE_PATH)
     assert blueprint.required_parameter_definitions == {
         "Param1": {
             "Type": "String"
         }
     }
Пример #14
0
 def test_render_template(self, cfngin_context: CfnginContext,
                          mocker: MockerFixture, tmp_path: Path) -> None:
     """Test render_template."""
     mock_rendered = mocker.patch.object(RawTemplateBlueprint, "rendered",
                                         "rendered")
     mock_version = mocker.patch.object(RawTemplateBlueprint, "version",
                                        "version")
     assert RawTemplateBlueprint(
         "test", cfngin_context,
         raw_template_path=tmp_path).render_template() == (mock_version,
                                                           mock_rendered)
Пример #15
0
 def test_to_dict(self, cfngin_context: CfnginContext,
                  mocker: MockerFixture, tmp_path: Path) -> None:
     """Test to_dict."""
     mock_parse_cloudformation_template = mocker.patch(
         f"{MODULE}.parse_cloudformation_template", return_value="success")
     mock_rendered = mocker.patch.object(RawTemplateBlueprint, "rendered",
                                         "rendered template")
     assert (RawTemplateBlueprint("test",
                                  cfngin_context,
                                  raw_template_path=tmp_path).to_dict() ==
             mock_parse_cloudformation_template.return_value)
     mock_parse_cloudformation_template.assert_called_once_with(
         mock_rendered)
Пример #16
0
 def test_parameter_definitions_yaml(self) -> None:
     """Verify parameter_definitions method with yaml raw template."""
     blueprint = RawTemplateBlueprint(
         name="test",
         context=MagicMock(),
         raw_template_path=RAW_YAML_TEMPLATE_PATH)
     assert blueprint.parameter_definitions == {
         "Param1": {
             "Type": "String"
         },
         "Param2": {
             "Default": "default",
             "Type": "CommaDelimitedList"
         },
     }
Пример #17
0
 def test_to_json(self, cfngin_context: CfnginContext,
                  mocker: MockerFixture, tmp_path: Path) -> None:
     """Test to_json."""
     mock_to_dict = mocker.patch.object(RawTemplateBlueprint,
                                        "to_dict",
                                        return_value="dict")
     mock_dumps = Mock(return_value="success")
     mocker.patch(f"{MODULE}.json", dumps=mock_dumps)
     assert (RawTemplateBlueprint(
         "test", cfngin_context,
         raw_template_path=tmp_path).to_json() == mock_dumps.return_value)
     mock_to_dict.assert_called_once_with()
     mock_dumps.assert_called_once_with(mock_to_dict.return_value,
                                        sort_keys=True,
                                        indent=4)
Пример #18
0
 def test_output_definitions(self, cfngin_context: CfnginContext,
                             mocker: MockerFixture, tmp_path: Path) -> None:
     """Test output_definitions."""
     mock_to_dict = mocker.patch.object(
         RawTemplateBlueprint,
         "to_dict",
         return_value={"Outputs": {
             "Test": {
                 "Value": "test"
             }
         }},
     )
     assert (RawTemplateBlueprint(
         "test", cfngin_context,
         raw_template_path=tmp_path).output_definitions ==
             mock_to_dict.return_value["Outputs"])
     mock_to_dict.assert_called_once_with()