Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EVA-3681 Fix last updated #227

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions eva_submission/biosample_submission/biosamples_submitters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions tests/test_biosamples_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': '[email protected]'},
{'LastName': 'Jane', 'FirstName': 'Doe', 'E-mail': '[email protected]'}],
'organization': [{'Name': 'GPE', 'Address': 'The place to be'},
Expand All @@ -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)
]
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand Down
Loading