def test_full(self, yaml_ast): ServiceTemplate.parse(yaml_ast( """ 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: {} """ ), None, None)
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_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"
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)
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)
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"
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)
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_minimal(self, yaml_ast): ServiceTemplate.parse(yaml_ast( """ tosca_definitions_version: tosca_simple_yaml_1_3 """ ), None, None)
def test_minimal(self, yaml_ast, tmp_path): ServiceTemplate.parse( yaml_ast(""" tosca_definitions_version: tosca_simple_yaml_1_3 """), tmp_path, tmp_path, set())