Esempio n. 1
0
    def test_valid_section_merge(self, yaml_ast):
        template = ServiceTemplate.parse(
            yaml_ast("""
            tosca_definitions_version: tosca_simple_yaml_1_3
            node_types:
              type_a:
                derived_from: a
            """), None, None)
        template.merge(
            ServiceTemplate.parse(
                yaml_ast("""
            tosca_definitions_version: tosca_simple_yaml_1_3
            node_types:
              type_b:
                derived_from: b
            """), None, None))

        assert template.node_types.bare == {
            "type_a": {
                "derived_from": "a"
            },
            "type_b": {
                "derived_from": "b"
            },
        }
    def test_valid_section_merge(self, yaml_ast, tmp_path):
        template = ServiceTemplate.parse_service_template(
            yaml_ast(
                # language=yaml
                """
            tosca_definitions_version: tosca_simple_yaml_1_3
            node_types:
              type_a:
                derived_from: a
            """),
            tmp_path,
            tmp_path,
            set())[0]
        template.merge(
            ServiceTemplate.parse_service_template(
                yaml_ast(
                    # language=yaml
                    """
            tosca_definitions_version: tosca_simple_yaml_1_3
            node_types:
              type_b:
                derived_from: b
            """),
                tmp_path,
                tmp_path,
                set())[0])

        assert len(template.node_types.data) == 2
        assert template.node_types["type_a"].data["derived_from"].data == "a"
        assert template.node_types["type_b"].data["derived_from"].data == "b"
 def test_full(self, yaml_ast, tmp_path):
     ServiceTemplate.parse_service_template(
         yaml_ast(
             # language=yaml
             """
         tosca_definitions_version: tosca_simple_yaml_1_3
         namespace: some.namespace
         metadata: {}
         description: Text here
         dsl_definitions:
           arbitrary_data: can
           be: here
           since:
             - it
             - is
             - stripped: from
               the: doc
         repositories: {}
         imports: []
         artifact_types: {}
         data_types: {}
         capability_types: {}
         interface_types: {}
         relationship_types: {}
         node_types: {}
         group_types: {}
         policy_types: {}
         topology_template: {}
         """),
         tmp_path,
         tmp_path,
         set())
 def test_duplicates(self, yaml_ast, tmp_path):
     with pytest.raises(ParseError, match="type_a"):
         ServiceTemplate.parse_service_template(
             yaml_ast(
                 # language=yaml
                 """
             tosca_definitions_version: tosca_simple_yaml_1_3
             node_types:
               type_a:
                 derived_from: a
             """),
             tmp_path,
             tmp_path,
             set())[0].merge(
                 ServiceTemplate.parse_service_template(
                     yaml_ast(
                         # language=yaml
                         """
             tosca_definitions_version: tosca_simple_yaml_1_3
             node_types:
               type_a:
                 derived_from: b
             """),
                     tmp_path,
                     tmp_path,
                     set())[0])
 def test_minimal(self, yaml_ast, tmp_path):
     ServiceTemplate.parse_service_template(
         yaml_ast(
             # language=yaml
             """
         tosca_definitions_version: tosca_simple_yaml_1_3
         """),
         tmp_path,
         tmp_path,
         set())
Esempio n. 6
0
 def test_duplicates(self, yaml_ast):
     with pytest.raises(ParseError, match="type_a"):
         ServiceTemplate.parse(
             yaml_ast("""
             tosca_definitions_version: tosca_simple_yaml_1_3
             node_types:
               type_a:
                 derived_from: a
             """), None, None).merge(
                 ServiceTemplate.parse(
                     yaml_ast("""
             tosca_definitions_version: tosca_simple_yaml_1_3
             node_types:
               type_a:
                 derived_from: b
             """), None, None))
    def test_valid_merge(self, yaml_ast, tmp_path):
        template = ServiceTemplate.parse(
            yaml_ast("""
            tosca_definitions_version: tosca_simple_yaml_1_3
            data_types:
              type_a:
                derived_from: a
            """), tmp_path, tmp_path, set())[0]
        template.merge(
            ServiceTemplate.parse(
                yaml_ast("""
            tosca_definitions_version: tosca_simple_yaml_1_3
            node_types:
              type_a:
                derived_from: a
            """), tmp_path, tmp_path, set())[0])

        assert len(template.data_types.data) == 1
        assert template.node_types["type_a"].data["derived_from"].data == "a"
Esempio n. 8
0
    def test_valid_user_data_type_reference(self, yaml_ast):
        service = ServiceTemplate.parse(
            yaml_ast("""
            tosca_definitions_version: tosca_simple_yaml_1_3
            data_types:
              my.Type:
                derived_from: float
            """), None, None)
        ref = DataTypeReferenceWrapper("my.Type", None)
        ref.section_path = ("data_types", )

        assert service.data_types["my.Type"] == ref.resolve_reference(service)
Esempio n. 9
0
    def test_valid_type_reference(self, yaml_ast):
        service = ServiceTemplate.parse(
            yaml_ast("""
            tosca_definitions_version: tosca_simple_yaml_1_3
            node_types:
              my.Type:
                derived_from: tosca.nodes.Root
            """), None, None)
        ref = ReferenceWrapper("my.Type", None)
        ref.section_path = ("node_types", )

        assert service.node_types["my.Type"] == ref.resolve_reference(service)
Esempio n. 10
0
    def test_valid_section_merge(self, yaml_ast):
        template = ServiceTemplate.parse(yaml_ast(
            """
            tosca_definitions_version: tosca_simple_yaml_1_3
            node_types:
              type_a:
                derived_from: a
            """
        ), None, None)
        template.merge(ServiceTemplate.parse(yaml_ast(
            """
            tosca_definitions_version: tosca_simple_yaml_1_3
            node_types:
              type_b:
                derived_from: b
            """
        ), None, None))

        assert len(template.node_types.data) == 2
        assert template.node_types["type_a"].data["derived_from"].data == "a"
        assert template.node_types["type_b"].data["derived_from"].data == "b"
Esempio n. 11
0
    def test_invalid_reference(self, yaml_ast):
        service = ServiceTemplate.parse(
            yaml_ast("""
            tosca_definitions_version: tosca_simple_yaml_1_3
            node_types:
              my.Type:
                derived_from: tosca.nodes.Root
            """), None, None)
        ref = ReferenceWrapper("INVALID", None)
        ref.section_path = ("node_types", )

        with pytest.raises(ParseError):
            ref.resolve_reference(service)
Esempio n. 12
0
    def test_valid_template_reference(self, yaml_ast):
        service = ServiceTemplate.parse(
            yaml_ast("""
            tosca_definitions_version: tosca_simple_yaml_1_3
            topology_template:
              node_templates:
                my_node:
                  type: tosca.nodes.Root
            """), None, None)
        ref = ReferenceWrapper("my_node", None)
        ref.section_path = ("topology_template", "node_templates")

        target = service.topology_template.node_templates["my_node"]
        assert target == ref.resolve_reference(service)
 def test_noop_for_dicts_with_no_dsl_definitions(self):
     assert ServiceTemplate.normalize(Node({})).bare == {}
 def test_failure_with_non_dict_data(self, data):
     with pytest.raises(ParseError):
         ServiceTemplate.normalize(Node(data))
 def test_dsl_definitions_removal(self):
     assert ServiceTemplate.normalize(
         Node({Node("dsl_definitions"): "data"})).bare == {}
Esempio n. 16
0
 def test_minimal(self, yaml_ast):
     ServiceTemplate.parse(yaml_ast(
         """
         tosca_definitions_version: tosca_simple_yaml_1_3
         """
     ), None, None)