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())
def test_valid_user_data_type_reference(self, yaml_ast, tmp_path): service = ServiceTemplate.parse_service_template( yaml_ast( # language=yaml """ tosca_definitions_version: tosca_simple_yaml_1_3 data_types: my.Type: derived_from: float """), tmp_path, tmp_path, set())[0] ref = DataTypeReferenceWrapper("my.Type", None) ref.section_path = ("data_types", ) assert service.data_types["my.Type"] == ref.resolve_reference(service)
def test_invalid_reference(self, yaml_ast, tmp_path): service = ServiceTemplate.parse_service_template( yaml_ast( # language=yaml """ tosca_definitions_version: tosca_simple_yaml_1_3 node_types: my.Type: derived_from: tosca.nodes.Root """), tmp_path, tmp_path, set())[0] 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, tmp_path): service = ServiceTemplate.parse_service_template( yaml_ast( # language=yaml """ tosca_definitions_version: tosca_simple_yaml_1_3 topology_template: node_templates: my_node: type: tosca.nodes.Root """), tmp_path, tmp_path, set())[0] 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)