def test_flatten__has_ontology_property_with_single_element(self): # given self.content.update({ "organ_parts": [{ "ontology": "UBERON:0000376", "ontology_label": "hindlimb stylopod", "text": "hindlimb stylopod" }] }) metadata_entity = {'content': self.content, 'uuid': self.uuid} entity_list = [metadata_entity] # when flattener = Flattener() actual = flattener.flatten(Entity.from_json_list(entity_list)) self.flattened_metadata_entity['Project']['values'][0].update({ 'project.organ_parts.ontology': 'UBERON:0000376', 'project.organ_parts.ontology_label': 'hindlimb stylopod', 'project.organ_parts.text': 'hindlimb stylopod', }) self.flattened_metadata_entity['Project']['headers'].extend([ 'project.organ_parts.ontology', 'project.organ_parts.ontology_label', 'project.organ_parts.text' ]) # then self.assertEqual(actual, self.flattened_metadata_entity)
def test_flatten__entities_has_input(self): # given with open(self.script_dir + '/entities-with-inputs-specimen.json') as file: metadata_entity = Entity.from_json(json.load(file)) with open(self.script_dir + '/entities-with-inputs-donor.json') as file: input_entity = Entity.from_json(json.load(file)) with open(self.script_dir + '/entities-with-inputs-process.json') as file: process = Entity.from_json(json.load(file)) with open(self.script_dir + '/entities-with-inputs-protocols.json') as file: protocols = Entity.from_json_list(json.load(file)) metadata_entity.set_input([input_entity], [], process, protocols) # when flattener = Flattener() actual = flattener.flatten([metadata_entity, process] + protocols) with open(self.script_dir + '/entities-with-inputs-flattened.json') as file: expected = json.load(file) self.assertEqual(actual, expected)
def test_flatten__raises_error__given_multiple_schema_versions_of_same_concrete_entity( self): # given entity_json_list = [ { 'content': { "describedBy": "https://schema.humancellatlas.org/type/project/14.2.0/donor_organism", "schema_type": "biomaterial", "field": "value" }, 'uuid': { 'uuid': 'uuid1' } }, { 'content': { "describedBy": "https://schema.humancellatlas.org/type/project/14.3.0/donor_organism", "schema_type": "biomaterial", "field": "value" }, 'uuid': { 'uuid': 'uuid2' } }, ] entity_list = Entity.from_json_list(entity_json_list) # when/then flattener = Flattener() with self.assertRaisesRegex( ValueError, "Multiple versions of same concrete entity schema"): flattener.flatten(entity_list)
def test_flatten__has_project_modules(self): # given self.content.update({ "contributors": [{ "name": "Alex A,,Pollen", "email": "*****@*****.**", "institution": "University of California, San Francisco (UCSF)", "laboratory": "Department of Neurology", "country": "USA", "corresponding_contributor": True, "project_role": { "text": "experimental scientist", "ontology": "EFO:0009741", "ontology_label": "experimental scientist" } }] }) metadata_entity = { 'content': self.content, 'uuid': self.uuid } entity_list = [metadata_entity] # when flattener = Flattener() actual = flattener.flatten(Entity.from_json_list(entity_list)) self.flattened_metadata_entity.update({ 'Project - Contributors': { 'headers': [ 'project.contributors.name', 'project.contributors.email', 'project.contributors.institution', 'project.contributors.laboratory', 'project.contributors.country', 'project.contributors.corresponding_contributor', 'project.contributors.project_role.text', 'project.contributors.project_role.ontology', 'project.contributors.project_role.ontology_label' ], 'values': [{ 'project.contributors.corresponding_contributor': 'True', 'project.contributors.country': 'USA', 'project.contributors.email': '*****@*****.**', 'project.contributors.institution': 'University of California, San Francisco (UCSF)', 'project.contributors.laboratory': 'Department of Neurology', 'project.contributors.name': 'Alex A,,Pollen', 'project.contributors.project_role.ontology': 'EFO:0009741', 'project.contributors.project_role.ontology_label': 'experimental scientist', 'project.contributors.project_role.text': 'experimental scientist'} ]} }) # then self.assertEqual(actual, self.flattened_metadata_entity)
def test_flatten__project_metadata(self): # given with open(self.script_dir + '/project-list.json') as file: entity_list = json.load(file) # when flattener = Flattener() actual = flattener.flatten(Entity.from_json_list(entity_list)) with open(self.script_dir + '/project-list-flattened.json') as file: expected = json.load(file) # then self.assertEqual(actual, expected)
def test_flatten__has_different_entities(self): # given with open(self.script_dir + '/entities.json') as file: entity_list = json.load(file) # when flattener = Flattener() actual = flattener.flatten(Entity.from_json_list(entity_list)) with open(self.script_dir + '/entities-flattened.json') as file: expected = json.load(file) # then self.assertEqual(actual, expected)
def test_flatten__has_ontology_property_with_single_element_but_only_with_text_attr( self): # given self.content.update({'diseases': [{'text': 'dummytext2'}]}) metadata_entity = {'content': self.content, 'uuid': self.uuid} entity_list = [metadata_entity] # when flattener = Flattener() actual = flattener.flatten(Entity.from_json_list(entity_list)) self.flattened_metadata_entity['Project']['values'][0].update({ 'project.diseases.text': 'dummytext2', }) self.flattened_metadata_entity['Project']['headers'].extend( ['project.diseases.text']) # then self.assertEqual(actual, self.flattened_metadata_entity)
def test_flatten__has_ontology_property_with_multiple_elements_but_with_empty_ontology_values( self): # given self.content.update({ 'diseases': [{ 'ontology': 'UBERON:0000376', 'ontology_label': 'dummylabel1', 'text': 'dummytext1' }, { 'ontology': '', 'ontology_label': '', 'text': 'dummytext2' }] }) metadata_entity = {'content': self.content, 'uuid': self.uuid} entity_list = [metadata_entity] # when flattener = Flattener() actual = flattener.flatten(Entity.from_json_list(entity_list)) self.flattened_metadata_entity['Project']['values'][0].update({ 'project.diseases.ontology': 'UBERON:0000376', 'project.diseases.ontology_label': 'dummylabel1', 'project.diseases.text': 'dummytext1||dummytext2', }) self.flattened_metadata_entity['Project']['headers'].extend([ 'project.diseases.ontology', 'project.diseases.ontology_label', 'project.diseases.text' ]) # then self.assertEqual(self.flattened_metadata_entity, actual)