From ab17370d0e81a274c8c7381d40d28b928f881158 Mon Sep 17 00:00:00 2001 From: Timothee Cezard Date: Fri, 25 Oct 2024 15:50:48 +0100 Subject: [PATCH] EVA-3681 Fix last updated (#227) * Last_updated_by needs to be a characteristics * update test --- .../biosamples_submitters.py | 6 +++-- tests/test_biosamples_submission.py | 24 +++++++++---------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/eva_submission/biosample_submission/biosamples_submitters.py b/eva_submission/biosample_submission/biosamples_submitters.py index 07f8200..77732e4 100644 --- a/eva_submission/biosample_submission/biosamples_submitters.py +++ b/eva_submission/biosample_submission/biosamples_submitters.py @@ -29,7 +29,8 @@ class BioSamplesSubmitter(AppLogger): valid_actions = ('create', 'overwrite', 'override', 'curate', 'derive') - characteristics_allowed_to_override = ('collection_date', 'geographic location (country and/or sea)') + characteristics_allowed_to_override = ('collection_date', 'geographic location (country and/or sea)', + 'last_updated_by') def __init__(self, communicators, submit_type=('create',), allow_removal=False): assert len(communicators) > 0, 'Specify at least one communicator object to BioSamplesSubmitter' @@ -467,7 +468,8 @@ def map_metadata_to_bsd_data(self): self.apply_mapping(bsd_sample_entry, 'organization', organisations) bsd_sample_entry['release'] = _now - bsd_sample_entry['last_updated_by'] = 'EVA' + # Custom attributes added to all the BioSample we create/modify + bsd_sample_entry['characteristics']['last_updated_by'] = [{'text': 'EVA'}] payloads.append(bsd_sample_entry) return payloads diff --git a/tests/test_biosamples_submission.py b/tests/test_biosamples_submission.py index b1b4afc..206acc0 100644 --- a/tests/test_biosamples_submission.py +++ b/tests/test_biosamples_submission.py @@ -208,7 +208,6 @@ def test_map_metadata_to_bsd_data(self): expected_payload = [ {'name': 'S%s' % (i + 1), 'taxId': 9606, 'release': now, - 'last_updated_by': 'EVA', 'contact': [{'LastName': 'John', 'FirstName': 'Doe', 'E-mail': 'john.doe@example.com'}, {'LastName': 'Jane', 'FirstName': 'Doe', 'E-mail': 'jane.doe@example.com'}], 'organization': [{'Name': 'GPE', 'Address': 'The place to be'}, @@ -218,7 +217,8 @@ def test_map_metadata_to_bsd_data(self): 'description': [{'text': 'Sample %s' % (i+1)}], 'scientific name': [{'text': 'Homo sapiens'}], 'collection_date': [{'text': '2020-01-15'}], - 'geographic location (country and/or sea)': [{'text': 'not provided'}] + 'geographic location (country and/or sea)': [{'text': 'not provided'}], + 'last_updated_by': [{'text': 'EVA'}] }} for i in range(100) ] @@ -239,29 +239,29 @@ def test_map_partial_metadata_to_bsd_data(self): ] organizations = [{'Name': 'GPE', 'Address': 'The place to be'}, {'Name': 'GPE', 'Address': 'The place to be'}] updated_samples = [{ - 'last_updated_by': 'EVA', 'accession': 'SAMD1234' + str(567 + i), 'name': 'S%s' % (i + 1), 'taxId': 9606, 'release': now, 'contact': contacts, 'organization': organizations, 'characteristics': { 'Organism': [{'text': 'Homo sapiens'}], 'description': [{'text': 'Sample %s' % (i + 1)}], - 'scientific name': [{'text': 'Homo sapiens'}] + 'scientific name': [{'text': 'Homo sapiens'}], + 'last_updated_by': [{'text': 'EVA'}] } } for i in range(10)] existing_samples = [{ - 'last_updated_by': 'EVA', 'accession': 'SAMD1234' + str(567 + i), 'contact': contacts, 'organization': organizations, - 'characteristics': {}, + 'characteristics': {'last_updated_by': [{'text': 'EVA'}]}, 'release': now } for i in range(10, 20)] - new_samples = [{'last_updated_by': 'EVA', 'name': 'S%s' % (i + 1), 'taxId': 9606, 'release': now, + new_samples = [{'name': 'S%s' % (i + 1), 'taxId': 9606, 'release': now, 'contact': contacts, 'organization': organizations, 'characteristics': { 'Organism': [{'text': 'Homo sapiens'}], 'description': [{'text': 'Sample %s' % (i + 1)}], - 'scientific name': [{'text': 'Homo sapiens'}] + 'scientific name': [{'text': 'Homo sapiens'}], + 'last_updated_by': [{'text': 'EVA'}] }} for i in range(20, 100)] expected_payload = updated_samples + existing_samples + new_samples @@ -343,16 +343,16 @@ def test_override_samples(self): with patch.object(BioSamplesSubmitter, '_get_existing_sample', side_effect=self._get_fake_sample), \ patch.object(HALCommunicator, 'follows_link') as m_follows_link: - sample_submitter = SampleMetadataSubmitter(self.metadata_file_ncbi, submit_type=('override',)) - sample_submitter.submit_to_bioSamples() - sample1 = copy.deepcopy(self.samples.get('SAMN1234567')) sample1['characteristics']['collection_date'] = [{'text': '2020-12-24'}] sample1['characteristics']['geographic location (country and/or sea)'] = [{'text': 'United Kingdom'}] + sample1['characteristics']['last_updated_by'] = [{'text': 'EVA'}] sample2 = copy.deepcopy(self.samples.get('SAMN1234568')) sample2['characteristics']['collection_date'] = [{'text': '1920-12-24'}] sample2['characteristics']['geographic location (country and/or sea)'] = [{'text': 'USA'}] - + sample2['characteristics']['last_updated_by'] = [{'text': 'EVA'}] + sample_submitter = SampleMetadataSubmitter(self.metadata_file_ncbi, submit_type=('override',)) + sample_submitter.submit_to_bioSamples() m_follows_link.assert_any_call('samples', method='PUT', join_url='SAMN1234567', json=sample1) m_follows_link.assert_any_call('samples', method='PUT', join_url='SAMN1234568', json=sample2)