Skip to content

Commit

Permalink
EVA-3681 Fix last updated (#227)
Browse files Browse the repository at this point in the history
* Last_updated_by needs to be a characteristics

* update test
  • Loading branch information
tcezard authored Oct 25, 2024
1 parent 1a4bd35 commit ab17370
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
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': 'john.doe@example.com'},
{'LastName': 'Jane', 'FirstName': 'Doe', 'E-mail': 'jane.doe@example.com'}],
'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

0 comments on commit ab17370

Please sign in to comment.