def test_add_parent(self): # Adding a parent should mutate the parents on self and the children on the parent civil_engineer = Occupation(identifier='12-3', name='Civil Engineer') engineers = Occupation(identifier='12', name='major group 12') civil_engineer.add_parent(engineers) assert engineers in civil_engineer.parents assert civil_engineer in engineers.children
def test_from_jsonld(self): jsonld_input = { '@type': 'Occupation', '@id': '12-3', 'name': 'Civil Engineer', 'hasChild': [], 'isChildOf': [{'@type': 'Occupation', '@id': '12'}], } target_occupation = Occupation(identifier='12-3', name='Civil Engineer') target_occupation.add_parent(Occupation(identifier='12', name='major group 12')) occupation = Occupation.from_jsonld(jsonld_input) assert occupation == target_occupation
def test_add_occupation_merge(self): # Should be able to add an occupation that already exists, and it will merge the attributes first_child = Occupation(identifier='456', name='Civil Engineer') parent_occupation = Occupation(identifier='45', name='Engineers') ontology = CompetencyOntology() first_child.add_parent(parent_occupation) ontology.add_occupation(first_child) ontology.add_occupation(parent_occupation) parent_occupation = Occupation(identifier='45', name='Engineers') second_child = Occupation(identifier='457', name='Structural Engineer') second_child.add_parent(parent_occupation) ontology.add_occupation(second_child) ontology.add_occupation(parent_occupation) assert len(ontology.occupations) == 3 assert len(list(ontology.filter_by(lambda edge: edge.occupation.identifier == '45').occupations)[0].children) == 2