Skip to content

Commit

Permalink
Merge pull request #584 from ayobi/claim_received_samples
Browse files Browse the repository at this point in the history
allow users to claim received samples
  • Loading branch information
cassidysymons authored Oct 2, 2024
2 parents d29a628 + 9f418e9 commit 773a1f1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
29 changes: 27 additions & 2 deletions microsetta_private_api/api/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2319,6 +2319,7 @@ def test_associate_sample_locked(self):

base_url = '/api/accounts/{0}/sources/{1}/samples'.format(
dummy_acct_id, dummy_source_id)
sample_url = "{0}/{1}".format(base_url, MOCK_SAMPLE_ID)

# "scan" the sample in
_ = create_dummy_acct(create_dummy_1=True,
Expand All @@ -2333,7 +2334,8 @@ def test_associate_sample_locked(self):
headers=make_headers(FAKE_TOKEN_ADMIN))
self.assertEqual(201, post_resp.status_code)

# attempt to associate as a regular user
# allow users to claim samples not
# currently associated with a source
post_resp = self.client.post(
'%s?%s' % (base_url, self.default_lang_querystring),
content_type='application/json',
Expand All @@ -2345,7 +2347,15 @@ def test_associate_sample_locked(self):
)

# check response code
self.assertEqual(422, post_resp.status_code)
self.assertEqual(201, post_resp.status_code)

# delete as admin so that tearDown doesn't require admin
delete_resp = self.client.delete(
'%s?%s' % (sample_url, self.default_lang_querystring),
headers=make_headers(FAKE_TOKEN_ADMIN))

# verify the delete was successful
self.assertEqual(204, delete_resp.status_code)

# associate as admin user
post_resp = self.client.post(
Expand All @@ -2361,6 +2371,21 @@ def test_associate_sample_locked(self):
# check response code
self.assertEqual(201, post_resp.status_code)

# attempt to associate as a regular user
# where the sample does have associated source id
post_resp = self.client.post(
'%s?%s' % (base_url, self.default_lang_querystring),
content_type='application/json',
data=json.dumps(
{
'sample_id': MOCK_SAMPLE_ID,
}),
headers=self.dummy_auth
)

# check response code
self.assertEqual(422, post_resp.status_code)

def test_edit_sample_locked(self):
dummy_acct_id, dummy_source_id = create_dummy_source(
"Bo", Source.SOURCE_TYPE_HUMAN, DUMMY_HUMAN_SOURCE,
Expand Down
5 changes: 4 additions & 1 deletion microsetta_private_api/repo/sample_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ def _update_sample_association(self, sample_id, source_id,
override_locked=False):
with self._transaction.cursor() as cur:
existing_sample = self._get_sample_by_id(sample_id)
if existing_sample.remove_locked and not override_locked:
# if the sample is not associated with a source, then
# we can skip the lock checks
if existing_sample.source_id is not None \
and existing_sample.remove_locked and not override_locked:
raise RepoException(
"Sample association locked: Sample already received")

Expand Down

0 comments on commit 773a1f1

Please sign in to comment.