Skip to content

Commit

Permalink
Multivio bug (#728)
Browse files Browse the repository at this point in the history
* Set expiration and force auth

* TST: create bug

* BUG: fixed, now allowing the unexpected single survey ID with vioscreen status case

* kick travis

* pg9.5

* sty
  • Loading branch information
wasade authored and ElDeveloper committed Aug 14, 2019
1 parent 822f5a1 commit 049d860
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 10 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ language: python
python:
- "2.7"
sudo: false
addons:
postgresql: "9.5"
services:
- redis-server
addons:
postgresql: "9.3"
- postgresql
before_install:
- redis-server --version
- sudo mount -o remount,size=25% /var/ramfs
Expand Down
8 changes: 6 additions & 2 deletions amgut/handlers/add_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class AddHumanFFQHandler(BaseHandler):
def post(self):
self.redirect(media_locale['SITEBASE'] + '/authed/portal/')

@authenticated
def get(self):
ag_login_id = ag_data.get_user_for_kit(self.current_user)
barcode = self.get_secure_cookie('barcode')
Expand Down Expand Up @@ -111,8 +112,11 @@ def post(self):
self.redirect(media_locale['SITEBASE'] + '/authed/portal/')
else:
self.set_secure_cookie('participant_name',
escape.json_encode(participant_name))
self.set_secure_cookie('barcode', escape.json_encode(barcode))
escape.json_encode(participant_name),
expires_days=1)
self.set_secure_cookie('barcode',
escape.json_encode(barcode),
expires_days=1)
url = media_locale['SITEBASE'] + '/authed/add_sample_human_ffq/'
self.redirect(url)

Expand Down
28 changes: 22 additions & 6 deletions amgut/lib/data_access/ag_data_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,19 +547,35 @@ def logParticipantSample(self, ag_login_id, barcode, sample_site,
# implicit, and currently limited to vioscreen FFQs
# We do not want to associate timepoint specific surveys
# with the wrong barcode
sql = """SELECT survey_id
sql = """SELECT survey_id, vioscreen_status
FROM ag_login_surveys
WHERE ag_login_id = %s
AND participant_name = %s
AND vioscreen_status is null"""
AND participant_name = %s"""

TRN.add(sql, (ag_login_id, participant_name))
survey_ids = TRN.execute_fetchindex()
if not survey_ids:
results = TRN.execute_fetchindex()
survey_ids = [x[0] for x in results]
statuses = [x[1] for x in results]

# if we have more than 1 ID, filter out those associated to
# vioscreen
if len(survey_ids) > 1:
keep = []
for sid, vs in zip(survey_ids, statuses):
if vs is None:
keep.append(sid)
survey_ids = keep

# if we only have a single survey ID then advance regardless
# of vioscreen status
if len(survey_ids) == 1:
pass

if len(survey_ids) == 0:
raise ValueError("No survey IDs for ag_login_id %s and "
"participant name %s" %
(ag_login_id, participant_name))
survey_ids = [x[0] for x in survey_ids]

else:
# otherwise, it is an environmental sample
survey_ids = []
Expand Down
16 changes: 16 additions & 0 deletions amgut/lib/data_access/test/test_ag_data_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,22 @@ def test_get_new_survey_id(self):
new_id = self.ag_data.get_new_survey_id()
self.assertNotIn(new_id, results)

@rollback
def test_logParticipantSample_bug_only_one_surveyid(self):
# before ag.source_barcodes_survey was added, it used to be that
# the survey ID used for the main survey was what was used for
# vioscreen. So for those who had created a survey before this
# switch, we have to treat them a little different.
# In addition, it seems that some samples prior to the PR which allowed
# for per sample vioscreen surveys ended up a vioscreen_status set
# but only a single survey, and it isn't obvious how.
id_ = 'c5b3ee5d-c143-4253-8dae-2722637fb08f'
bc = '000070778'
name = 'Name - Ø6CTz2LLqn'
self.ag_data.logParticipantSample(id_, bc, 'stool', None,
datetime.date(2015, 9, 27),
datetime.time(15, 54), name, '')

def test_logParticipantSample_badinfo(self):
# bad ag_login_id
with self.assertRaises(ValueError):
Expand Down

0 comments on commit 049d860

Please sign in to comment.