Skip to content

Commit 773a1f1

Browse files
Merge pull request #584 from ayobi/claim_received_samples
allow users to claim received samples
2 parents d29a628 + 9f418e9 commit 773a1f1

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

microsetta_private_api/api/tests/test_api.py

+27-2
Original file line numberDiff line numberDiff line change
@@ -2319,6 +2319,7 @@ def test_associate_sample_locked(self):
23192319

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

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

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

23472349
# check response code
2348-
self.assertEqual(422, post_resp.status_code)
2350+
self.assertEqual(201, post_resp.status_code)
2351+
2352+
# delete as admin so that tearDown doesn't require admin
2353+
delete_resp = self.client.delete(
2354+
'%s?%s' % (sample_url, self.default_lang_querystring),
2355+
headers=make_headers(FAKE_TOKEN_ADMIN))
2356+
2357+
# verify the delete was successful
2358+
self.assertEqual(204, delete_resp.status_code)
23492359

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

2374+
# attempt to associate as a regular user
2375+
# where the sample does have associated source id
2376+
post_resp = self.client.post(
2377+
'%s?%s' % (base_url, self.default_lang_querystring),
2378+
content_type='application/json',
2379+
data=json.dumps(
2380+
{
2381+
'sample_id': MOCK_SAMPLE_ID,
2382+
}),
2383+
headers=self.dummy_auth
2384+
)
2385+
2386+
# check response code
2387+
self.assertEqual(422, post_resp.status_code)
2388+
23642389
def test_edit_sample_locked(self):
23652390
dummy_acct_id, dummy_source_id = create_dummy_source(
23662391
"Bo", Source.SOURCE_TYPE_HUMAN, DUMMY_HUMAN_SOURCE,

microsetta_private_api/repo/sample_repo.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,10 @@ def _update_sample_association(self, sample_id, source_id,
106106
override_locked=False):
107107
with self._transaction.cursor() as cur:
108108
existing_sample = self._get_sample_by_id(sample_id)
109-
if existing_sample.remove_locked and not override_locked:
109+
# if the sample is not associated with a source, then
110+
# we can skip the lock checks
111+
if existing_sample.source_id is not None \
112+
and existing_sample.remove_locked and not override_locked:
110113
raise RepoException(
111114
"Sample association locked: Sample already received")
112115

0 commit comments

Comments
 (0)