Skip to content

Commit

Permalink
changes per suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
ayobi committed Apr 23, 2024
1 parent 1399fe1 commit 344e9f8
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 81 deletions.
32 changes: 13 additions & 19 deletions microsetta_interface/implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1304,10 +1304,19 @@ def post_create_human_source(*, account_id=None, body=None):

session.pop(SOURCE_ID)

return redirect(
"/accounts/%s/sources/%s/kits" %
(account_id, source_id)
)
# Yes, "None" is coming through as a string in this instance, not as
# an actual None type.
if body["sample_ids"] != "None":
return post_claim_samples(
account_id=account_id,
source_id=source_id,
sample_ids=body['sample_ids']
)
else:
return redirect(
"/accounts/%s/sources/%s/kits" %
(account_id, source_id)
)


@prerequisite([ACCT_PREREQS_MET])
Expand Down Expand Up @@ -2760,14 +2769,6 @@ def post_claim_samples(*, account_id=None, source_id=None, body=None,
if has_error:
return survey_output

# TODO: this will have to get more nuanced when we add animal surveys?
# Grab all primary and covid surveys from the source and associate with
# newly claimed samples; non-human sources always have none of these
survey_ids_to_associate_with_samples = [
x['survey_id'] for x in survey_output
if x['survey_template_id'] in [1, 6]
]

# TODO: Any of these requests may fail independently, but we don't
# have a good policy to deal with partial failures. Currently, we
# abort early but that will result in some set of associations being
Expand All @@ -2782,13 +2783,6 @@ def post_claim_samples(*, account_id=None, source_id=None, body=None,
if has_error:
return sample_output

# Associate the input answered surveys with this sample.
for survey_id in survey_ids_to_associate_with_samples:
sample_survey_output = _associate_sample_to_survey(
account_id, source_id, curr_sample_id, survey_id)
if sample_survey_output is not None:
return sample_survey_output

return redirect(
"/accounts/%s/sources/%s/kits" %
(account_id, source_id)
Expand Down
119 changes: 57 additions & 62 deletions microsetta_interface/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,68 +367,63 @@ def test_new_human_source_to_sample(self):
obs_barcodes = {d['sample_barcode'] for d in resp.json}
self.assertIn(TEST_KIT_1_SAMPLE_1_BARCODE, obs_barcodes)

# commenting this section out as we
# have moved survey to sample lock to api

# # claim a sample
# url = f'/accounts/{account_id}/sources/{source_id}/claim_samples'
# body = {'sample_id': [TEST_KIT_1_SAMPLE_1_SAMPLE_ID, ]}
# sample_id = TEST_KIT_1_SAMPLE_1_SAMPLE_ID
# # note the sample for clean up
# self.claimed_samples.append((account_id, source_id, sample_id))
# resp = self.app.post(url, data=body, follow_redirects=True)
# self.assertEqual(resp.status_code, 200)

# page_data = self._html_page(resp)
# con = "adult_biospecimen"
# consent_id = _get_consent_id_from_webpage(page_data, con)
# ADULT_CONSENT["consent_id"] = consent_id
# ADULT_CONSENT["consent_type"] = "adult_biospecimen"
# ADULT_CONSENT["sample_ids"] = sample_id
# url = f'/accounts/{account_id}/create_human_source'
# resp = self.app.post(url, data=ADULT_CONSENT)

# url = self.redirectURL(resp)
# resp = self.app.get(url)
# self.assertPageTitle(resp, 'My Kits')
# data = self._html_page(resp)
# self.assertIn('/static/img/edit.svg', data)

# # get collection info
# url = f'/accounts/{account_id}/sources/{source_id}
# /samples/{sample_id}'
# resp = self.app.get(url)
# self.assertEqual(resp.status_code, 200)
# self.assertPageTitle(resp, 'My Kits')

# # set collection info
# cur_date = datetime.datetime.now().strftime("%-m/%-d/%Y")
# collection_note = 'SAMPLE COLLECTED BY INTEGRATION TESTING'
# body = {'sample': TEST_KIT_1_SAMPLE_1_BARCODE,
# 'sample_date': cur_date,
# 'sample_date_normalized': cur_date,
# 'sample_time': '07:00 AM',
# 'sample_site': 'Stool',
# 'sample_notes': collection_note}
# resp = self.app.post(url, data=body)
# self.assertRedirect(resp, suffix_is_uuid=False)
# url = self.redirectURL(resp)
# # Flask's client.get() function doesn't like the query string being
# # attached to the url string. So we'll restructure it.
# url = url.replace("?check_survey_date=True", "")
# query_string = {"check_survey_date": "True"}
# resp = self.app.get(url, query_string=query_string)
# self.assertPageTitle(resp, 'My Kits')

# # verify we have our sample information
# # get collection info
# url = f'/accounts/{account_id}/sources/
# {source_id}/samples/{sample_id}'
# resp = self.app.get(url)
# self.assertEqual(resp.status_code, 200)
# self.assertPageTitle(resp, 'My Kits')
# data = self._html_page(resp)
# self.assertIn(collection_note, data)
# claim a sample
url = f'/accounts/{account_id}/sources/{source_id}/claim_samples'
body = {'sample_id': [TEST_KIT_1_SAMPLE_1_SAMPLE_ID, ]}
sample_id = TEST_KIT_1_SAMPLE_1_SAMPLE_ID
# note the sample for clean up
self.claimed_samples.append((account_id, source_id, sample_id))
resp = self.app.post(url, data=body, follow_redirects=True)
self.assertEqual(resp.status_code, 200)

page_data = self._html_page(resp)
con = "adult_biospecimen"
consent_id = _get_consent_id_from_webpage(page_data, con)
ADULT_CONSENT["consent_id"] = consent_id
ADULT_CONSENT["consent_type"] = "adult_biospecimen"
ADULT_CONSENT["sample_ids"] = sample_id
url = f'/accounts/{account_id}/create_human_source'
resp = self.app.post(url, data=ADULT_CONSENT)

url = self.redirectURL(resp)
resp = self.app.get(url)
self.assertPageTitle(resp, 'My Kits')
data = self._html_page(resp)
self.assertIn('/static/img/edit.svg', data)

# get collection info
url = f'/accounts/{account_id}/sources/{source_id}/samples/{sample_id}'
resp = self.app.get(url)
self.assertEqual(resp.status_code, 200)
self.assertPageTitle(resp, 'My Kits')

# set collection info
cur_date = datetime.datetime.now().strftime("%-m/%-d/%Y")
collection_note = 'SAMPLE COLLECTED BY INTEGRATION TESTING'
body = {'sample': TEST_KIT_1_SAMPLE_1_BARCODE,
'sample_date': cur_date,
'sample_date_normalized': cur_date,
'sample_time': '07:00 AM',
'sample_site': 'Stool',
'sample_notes': collection_note}
resp = self.app.post(url, data=body)
self.assertRedirect(resp, suffix_is_uuid=False)
url = self.redirectURL(resp)
# Flask's client.get() function doesn't like the query string being
# attached to the url string. So we'll restructure it.
url = url.replace("?check_survey_date=True", "")
query_string = {"check_survey_date": "True"}
resp = self.app.get(url, query_string=query_string)
self.assertPageTitle(resp, 'My Kits')

# verify we have our sample information
# get collection info
url = f'/accounts/{account_id}/sources/{source_id}/samples/{sample_id}'
resp = self.app.get(url)
self.assertEqual(resp.status_code, 200)
self.assertPageTitle(resp, 'My Kits')
data = self._html_page(resp)
self.assertIn(collection_note, data)

def test_take_survey_twice(self):
self._login(USER_WITH_VALID_SAMPLE)
Expand Down

0 comments on commit 344e9f8

Please sign in to comment.