def test_post(self):
        details = db.getAGBarcodeDetails('000004216')
        payload = {
            'barcode': '000004216',
            'ag_kit_id': details['ag_kit_id'],
            'site_sampled': details['site_sampled'],
            'sample_date': details['sample_date'],
            'sample_time': details['sample_time'],
            'participant_name': details['participant_name'],
            'notes': details['notes'],
            'environment_sampled': details['environment_sampled'],
            'refunded': details['refunded'] or 'N'
        }

        self.mock_login_admin()
        # Missing a parameters ('withdrawn')
        response = self.post('/ag_edit_barcode/', payload)
        self.assertEqual(response.code, 400)

        payload['withdrawn'] = details['withdrawn'] or 'N'
        payload['notes'] = 'Some new notes'
        response = self.post('/ag_edit_barcode/', payload)
        self.assertEqual(response.code, 200)
        self.assertIn("Barcode was updated successfully", response.body)
        self.assertEqual(
            db.getAGBarcodeDetails('000004216')['notes'], 'Some new notes')

        payload['ag_kit_id'] = 'notInDB'
        response = self.post('/ag_edit_barcode/', payload)
        # TODO: think about returning a non-OK status code to better report
        # this error, see issue #139
        self.assertEqual(response.code, 200)
        self.assertIn("Error Updating Barcode Info", response.body)
    def test_edit_none_participant(self):
        self.mock_login_admin()

        barcode = '000023125'  # current survey_id = "a4f1061f5bac9ae3"
        details = db.getAGBarcodeDetails(barcode)
        payload = {
            'barcode': barcode,
            'ag_kit_id': details['ag_kit_id'],
            'site_sampled': details['site_sampled'],
            'sample_date': details['sample_date'],
            'sample_time': details['sample_time'],
            'participant_name': details['participant_name'],
            'notes': details['notes'],
            'environment_sampled': details['environment_sampled'],
            'refunded': details['refunded'] or 'N',
            'withdrawn': details['withdrawn'] or 'N'
        }

        old_sourcename = payload['participant_name']
        payload['participant_name'] = None
        response = self.post('/ag_edit_barcode/', payload)
        obs_details = db.getAGBarcodeDetails(barcode)
        obs_surveys = db.get_barcode_survey(barcode)

        # revert to old participant_name to leave a clean DB
        payload['participant_name'] = old_sourcename
        response = self.post('/ag_edit_barcode/', payload)

        self.assertEqual(response.code, 200)
        self.assertIsNone(obs_details['participant_name'])
        self.assertIsNone(obs_surveys)
        self.assertIsNotNone(db.get_barcode_survey(barcode))
    def test_post(self):
        details = db.getAGBarcodeDetails('000004216')
        payload = {'barcode': '000004216',
                   'ag_kit_id': details['ag_kit_id'],
                   'site_sampled': details['site_sampled'],
                   'sample_date': details['sample_date'],
                   'sample_time': details['sample_time'],
                   'participant_name': details['participant_name'],
                   'notes': details['notes'],
                   'environment_sampled': details['environment_sampled'],
                   'refunded': details['refunded'] or 'N'}

        self.mock_login_admin()
        # Missing a parameters ('withdrawn')
        response = self.post('/ag_edit_barcode/', payload)
        self.assertEqual(response.code, 400)

        payload['withdrawn'] = details['withdrawn'] or 'N'
        payload['notes'] = 'Some new notes'
        response = self.post('/ag_edit_barcode/', payload)
        self.assertEqual(response.code, 200)
        self.assertIn("Barcode was updated successfully", response.body)
        self.assertEqual(db.getAGBarcodeDetails('000004216')['notes'],
                         'Some new notes')

        payload['ag_kit_id'] = 'notInDB'
        response = self.post('/ag_edit_barcode/', payload)
        # TODO: think about returning a non-OK status code to better report
        # this error, see issue #139
        self.assertEqual(response.code, 200)
        self.assertIn("Error Updating Barcode Info", response.body)
 def test_getAGBarcodeDetails(self):
     obs = db.getAGBarcodeDetails('000018046')
     exp = {
         'status': 'Received',
         'ag_kit_id': '0060a301-e5c0-6a4e-e050-8a800c5d49b7',
         'barcode': '000018046',
         'environment_sampled': None,
         # 'name': 'REMOVED',
         'ag_kit_barcode_id': '0060a301-e5c1-6a4e-e050-8a800c5d49b7',
         'sample_time': datetime.time(11, 15),
         # 'notes': 'REMOVED',
         'overloaded': 'N',
         'withdrawn': None,  # 'email': 'REMOVED',
         'other': 'N',
         # 'deposited': False,
         # 'participant_name': 'REMOVED-0',
         'refunded': None,
         'moldy': 'N',
         'sample_date': datetime.date(2014, 8, 13),
         'date_of_last_email': datetime.date(2014, 8, 15),
         # 'other_text': 'REMOVED',
         'site_sampled': 'Stool'
     }
     # only look at those fields, that are not subject to scrubbing
     self.assertEqual({k: obs[k] for k in exp}, exp)
    def test_get_ag_details(self):
        self.mock_login_admin()

        # test if AGP data are rendered correctly
        barcode = '000029153'
        response = self.get('/barcode_util/', {'barcode': barcode})
        self.assertEqual(response.code, 200)
        self.assertIn('<h2>%s Details</h2>' % 'American Gut', response.body)
        ag_details = db.getAGBarcodeDetails(barcode)
        self.assertIn('<tr><td>Sample Date</td><td>%s</td></tr>'
                      % ag_details['sample_date'], response.body)
        self.assertIn('<tr><td>Sample Time</td><td>%s</td></tr>'
                      % ag_details['sample_time'], response.body)
        self.assertIn('<tr><td>Sample Site</td><td>%s</td></tr>'
                      % ag_details['site_sampled'], response.body)

        self.assertIn('<label for="moldy"> moldy (current: %s) </label> <br />'
                      % ag_details['moldy'], response.body)
        self.assertIn(('<label for="overloaded"> overloaded (current: %s) '
                       '</label> <br />') % ag_details['overloaded'],
                      response.body)
        self.assertIn(('<label for="other"> other (current: %s) '
                       '</label> <br />') % ag_details['other'], response.body)

        self.assertIn(('<textarea name="other_text" onclick="this.select()'
                       '">%s</textarea>') %
                      xhtml_escape(ag_details['other_text']),
                      response.body)
        self.assertIn(('<label for="send_mail" style="display:block;">send kit'
                       ' owner %s (%s) an email </label>')
                      % (xhtml_escape(ag_details['name']),
                         xhtml_escape(ag_details['email'])),
                      response.body)
Exemple #6
0
 def test_getAGBarcodeDetails(self):
     obs = db.getAGBarcodeDetails("000018046")
     exp = {
         "status": "Received",
         "ag_kit_id": "0060a301-e5c0-6a4e-e050-8a800c5d49b7",
         "barcode": "000018046",
         "environment_sampled": None,
         "name": "REMOVED",
         "ag_kit_barcode_id": "0060a301-e5c1-6a4e-e050-8a800c5d49b7",
         "sample_time": datetime.time(11, 15),
         "notes": "REMOVED",
         "overloaded": "N",
         "withdrawn": None,
         "email": "REMOVED",
         "other": "N",
         "deposited": False,
         "participant_name": "REMOVED-0",
         "refunded": None,
         "moldy": "N",
         "sample_date": datetime.date(2014, 8, 13),
         "date_of_last_email": datetime.date(2014, 8, 15),
         "other_text": "REMOVED",
         "site_sampled": "Stool",
     }
     self.assertEqual(obs, exp)
    def test_get(self):
        self.mock_login_admin()

        # check that error is raised for unknown barcode
        response = self.get("/ag_edit_barcode/", {"barcode": "unknown"})
        self.assertEqual(response.code, 500)

        # make sure return code 400 is returned, if barcode is not given
        response = self.get("/ag_edit_barcode/", {})
        self.assertEqual(response.code, 400)

        # check if page is rendered properly
        barcode = db.get_barcodes_with_results()[0]
        response = self.get("/ag_edit_barcode/", {"barcode": barcode})
        self.assertEqual(response.code, 200)
        details = db.getAGBarcodeDetails(barcode)
        l = db.search_kits(details["ag_kit_id"])[0]
        self.assertIn('name="barcode" id="barcode" value="%s"' % barcode, response.body)
        for s in db.human_sites:
            if details["site_sampled"] == str(s):
                self.assertIn('<option value="%s" selected>%s</option>' % (str(s), str(s)), response.body)
            else:
                self.assertIn('<option value="%s">%s</option>' % (str(s), str(s)), response.body)
        for e in db.general_sites:
            if details["environment_sampled"] == str(e):
                self.assertIn('<option value="%s" selected>%s</option>' % (str(e), str(e)), response.body)
            else:
                self.assertIn('<option value="%s">%s</option>' % (str(e), str(e)), response.body)
        for p in db.getHumanParticipants(l) + db.getAnimalParticipants(l):
            if details["participant_name"] == str(p):
                self.assertIn('<option value="%s" selected>%s</option>' % (str(p), str(p)), response.body)
            else:
                self.assertIn('<option value="%s" >%s</option>' % (str(p), str(p)), response.body)
    def test_get_ag_details(self):
        self.mock_login_admin()

        # test if AGP data are rendered correctly
        barcode = "000029153"
        response = self.get("/barcode_util/", {"barcode": barcode})
        self.assertEqual(response.code, 200)
        self.assertIn("<h2>%s Details</h2>" % "American Gut", response.body)
        ag_details = db.getAGBarcodeDetails(barcode)
        self.assertIn("<tr><td>Sample Date</td><td>%s</td></tr>" % ag_details["sample_date"], response.body)
        self.assertIn("<tr><td>Sample Time</td><td>%s</td></tr>" % ag_details["sample_time"], response.body)
        self.assertIn("<tr><td>Sample Site</td><td>%s</td></tr>" % ag_details["site_sampled"], response.body)

        self.assertIn('<label for="moldy"> moldy (current: %s) </label> <br />' % ag_details["moldy"], response.body)
        self.assertIn(
            ('<label for="overloaded"> overloaded (current: %s) ' "</label> <br />") % ag_details["overloaded"],
            response.body,
        )
        self.assertIn(
            ('<label for="other"> other (current: %s) ' "</label> <br />") % ag_details["other"], response.body
        )

        self.assertIn(
            ('<textarea name="other_text" onclick="this.select()' '">%s</textarea>') % ag_details["notes"],
            response.body,
        )
        self.assertIn(
            ('<label for="send_mail" style="display:block;">send kit' " owner %s (%s) an email </label>")
            % (ag_details["name"], ag_details["email"]),
            response.body,
        )
    def test_get(self):
        self.mock_login_admin()

        # check that error is raised for unknown barcode
        response = self.get('/ag_edit_barcode/', {'barcode': 'unknown'})
        self.assertEqual(response.code, 500)

        # make sure return code 400 is returned, if barcode is not given
        response = self.get('/ag_edit_barcode/', {})
        self.assertEqual(response.code, 400)

        # check if page is rendered properly
        barcode = '000004216'
        response = self.get('/ag_edit_barcode/', {'barcode': barcode})
        self.assertEqual(response.code, 200)
        self.assertIn('name="barcode" id="barcode" value="%s"' %
                      barcode, response.body)
        self.assertIn('<option value="Stool" selected>Stool</option>',
                      response.body)
        self.assertIn('2013-10-15', response.body)

        hs = db.human_sites
        hs.remove('Stool')
        for s in hs:
            self.assertIn('<option value="%s">%s</option>' %
                          (str(s), str(s)), response.body)

        for e in db.general_sites:
            self.assertIn('<option value="%s">%s</option>' %
                          (str(e), str(e)), response.body)

        pname = xhtml_escape(
            db.getAGBarcodeDetails(barcode)['participant_name'])
        self.assertIn('<option value="%s" selected>%s</option>' %
                      (pname, pname), response.body)
Exemple #10
0
 def test_getAGBarcodeDetails(self):
     obs = db.getAGBarcodeDetails('000018046')
     exp = {
         'status': 'Received',
         'ag_kit_id': '0060a301-e5c0-6a4e-e050-8a800c5d49b7',
         'barcode': '000018046',
         'environment_sampled': None,
         'name': 'REMOVED',
         'ag_kit_barcode_id': '0060a301-e5c1-6a4e-e050-8a800c5d49b7',
         'sample_time': datetime.time(11, 15),
         'notes': 'REMOVED',
         'overloaded': 'N',
         'withdrawn': None,
         'email': 'REMOVED',
         'other': 'N',
         'deposited': False,
         'participant_name': 'REMOVED-0',
         'refunded': None,
         'moldy': 'N',
         'sample_date': datetime.date(2014, 8, 13),
         'date_of_last_email': datetime.date(2014, 8, 15),
         'other_text': 'REMOVED',
         'site_sampled': 'Stool'
     }
     self.assertEqual(obs, exp)
Exemple #11
0
    def get_ag_details(self, barcode):
        ag_details = db.getAGBarcodeDetails(barcode)
        _, failures = db.pulldown([barcode], [])

        if len(ag_details) == 0 and failures:
            div_id = "no_metadata"
            message = "Cannot retrieve metadata: %s" % failures[barcode]
        elif len(ag_details) > 0:
            for col, val in ag_details.iteritems():
                if val is None:
                    ag_details[col] = ''
            ag_details['other_checked'] = ''
            ag_details['overloaded_checked'] = ''
            ag_details['moldy_checked'] = ''
            ag_details['login_user'] = ag_details['name']
            if ag_details['moldy'] == 'Y':
                ag_details['moldy_checked'] = 'checked'
            if ag_details['overloaded'] == 'Y':
                ag_details['overloaded_checked'] = 'checked'
            if ag_details['other'] == 'Y':
                ag_details['other_checked'] = 'checked'

            survey_id = db.get_barcode_survey(barcode)

            # it has all sample details
            # (sample time, date, site)
            if failures:
                div_id = "no_metadata"
                message = "Cannot retrieve metadata: %s" % failures[barcode]
                ag_details['email_type'] = "-1"
            elif (survey_id is None and ag_details['environment_sampled']) \
                    or survey_id in survey_type:
                div_id = "verified"
                message = "All good"
                ag_details['email_type'] = "1"
            else:
                # should never get here (this would happen
                # if the metadata
                # pulldown returned more than one row for a
                # single barcode)
                div_id = "md_pulldown_error"
                message = ("This barcode has multiple entries "
                           "in the database, which should "
                           "never happen. Please notify "
                           "someone on the database crew.")
                ag_details['email_type'] = "-1"
        else:
            # TODO: Stefan Janssen: I cannot see how this case should ever be
            # reached, since failures will be set to 'Unknown reason' at the
            # outmost.
            div_id = "not_assigned"
            message = ("In American Gut project group but no "
                       "American Gut info for barcode")
            ag_details['email_type'] = "-1"
        return div_id, message, ag_details
Exemple #12
0
    def get_ag_details(self, barcode):
        ag_details = db.getAGBarcodeDetails(barcode)
        _, failures = db.pulldown([barcode], [])

        if len(ag_details) == 0 and failures:
            div_id = "no_metadata"
            message = "Cannot retrieve metadata: %s" % failures[barcode]
        elif len(ag_details) > 0:
            for col, val in ag_details.iteritems():
                if val is None:
                    ag_details[col] = ''
            ag_details['other_checked'] = ''
            ag_details['overloaded_checked'] = ''
            ag_details['moldy_checked'] = ''
            ag_details['login_user'] = ag_details['name']
            if ag_details['moldy'] == 'Y':
                ag_details['moldy_checked'] = 'checked'
            if ag_details['overloaded'] == 'Y':
                ag_details['overloaded_checked'] = 'checked'
            if ag_details['other'] == 'Y':
                ag_details['other_checked'] = 'checked'

            survey_id = db.get_barcode_survey(barcode)

            # it has all sample details
            # (sample time, date, site)
            if failures:
                div_id = "no_metadata"
                message = "Cannot retrieve metadata: %s" % failures[barcode]
                ag_details['email_type'] = "-1"
            elif (survey_id is None and ag_details['environment_sampled']) \
                    or survey_id in survey_type:
                div_id = "verified"
                message = "All good"
                ag_details['email_type'] = "1"
            else:
                # should never get here (this would happen
                # if the metadata
                # pulldown returned more than one row for a
                # single barcode)
                div_id = "md_pulldown_error"
                message = ("This barcode has multiple entries "
                           "in the database, which should "
                           "never happen. Please notify "
                           "someone on the database crew.")
                ag_details['email_type'] = "-1"
        else:
            # TODO: Stefan Janssen: I cannot see how this case should ever be
            # reached, since failures will be set to 'Unknown reason' at the
            # outmost.
            div_id = "not_assigned"
            message = ("In American Gut project group but no "
                       "American Gut info for barcode")
            ag_details['email_type'] = "-1"
        return div_id, message, ag_details
Exemple #13
0
 def get(self):
     barcode = self.get_argument('barcode', None)
     if barcode is not None:
         details = db.getAGBarcodeDetails(barcode)
         site_sampled = db.human_sites
         environment_sampled = db.general_sites
         logins = db.getAGKitsByLogin()
         self.render("ag_edit_barcode.html", response=None, barcode=barcode,
                     sites_sampled=site_sampled, details=details,
                     environments_sampled=environment_sampled,
                     logins=logins, currentuser=self.current_user)
Exemple #14
0
 def test_post_update_ag(self):
     db.alter_access_levels("test", [3])
     notes = "".join([choice(ascii_letters) for x in range(40)])
     self.data["other_text"] = notes
     self.mock_login()
     response = self.post("/barcode_util/", data=self.data)
     self.assertEqual(response.code, 200)
     self.assertIn("Barcode %s general details updated" % self.ag_good, response.body)
     self.assertIn("Barcode %s AG info was successfully updated" % self.ag_good, response.body)
     obs = db.getAGBarcodeDetails(self.ag_good)
     self.assertEqual(obs["other_text"], notes)
Exemple #15
0
 def test_post_update_ag(self):
     db.alter_access_levels('test', [3])
     notes = ''.join([choice(ascii_letters) for x in range(40)])
     self.data['other_text'] = notes
     self.mock_login()
     response = self.post('/barcode_util/', data=self.data)
     self.assertEqual(response.code, 200)
     self.assertIn('Barcode %s general details updated' % self.ag_good,
                   response.body)
     self.assertIn(
         'Barcode %s AG info was successfully updated' % self.ag_good,
         response.body)
     obs = db.getAGBarcodeDetails(self.ag_good)
     self.assertEqual(obs['other_text'], notes)
 def get(self):
     barcode = self.get_argument('barcode', None)
     if barcode is not None:
         details = db.getAGBarcodeDetails(barcode)
         ag_login_id = db.search_kits(details['ag_kit_id'])[0]
         site_sampled = db.human_sites
         environment_sampled = db.general_sites
         participants = db.getHumanParticipants(ag_login_id) + \
             db.getAnimalParticipants(ag_login_id)
         self.render("ag_edit_barcode.html", response=None, barcode=barcode,
                     sites_sampled=site_sampled, details=details,
                     environments_sampled=environment_sampled,
                     participants=participants,
                     currentuser=self.current_user)
Exemple #17
0
 def get(self):
     barcode = self.get_argument('barcode', None)
     if barcode is not None:
         details = db.getAGBarcodeDetails(barcode)
         site_sampled = db.human_sites
         environment_sampled = db.general_sites
         logins = db.getAGKitsByLogin()
         self.render("ag_edit_barcode.html",
                     response=None,
                     barcode=barcode,
                     sites_sampled=site_sampled,
                     details=details,
                     environments_sampled=environment_sampled,
                     logins=logins,
                     currentuser=self.current_user)
Exemple #18
0
 def get(self):
     barcode = self.get_argument('barcode', None)
     if barcode is not None:
         details = db.getAGBarcodeDetails(barcode)
         ag_login_id = db.search_kits(details['ag_kit_id'])[0]
         site_sampled = db.human_sites
         environment_sampled = db.general_sites
         participants = db.getHumanParticipants(ag_login_id) + \
             db.getAnimalParticipants(ag_login_id)
         self.render("ag_edit_barcode.html", response=None, barcode=barcode,
                     sites_sampled=site_sampled, details=details,
                     environments_sampled=environment_sampled,
                     participants=participants,
                     currentuser=self.current_user)
     else:
         self.set_status(400)
 def test_getAGBarcodeDetails(self):
     obs = db.getAGBarcodeDetails('000018046')
     exp = {'status': 'Received',
            'ag_kit_id': '0060a301-e5c0-6a4e-e050-8a800c5d49b7',
            'barcode': '000018046',
            'environment_sampled': None,
            'name': 'REMOVED',
            'ag_kit_barcode_id': '0060a301-e5c1-6a4e-e050-8a800c5d49b7',
            'sample_time': datetime.time(11, 15),
            'notes': 'REMOVED',
            'overloaded': 'N',
            'withdrawn': None, 'email': 'REMOVED',
            'other': 'N', 'deposited': False,
            'participant_name': 'REMOVED-0',
            'refunded': None, 'moldy': 'N',
            'sample_date': datetime.date(2014, 8, 13),
            'date_of_last_email': datetime.date(2014, 8, 15),
            'other_text': 'REMOVED',
            'site_sampled': 'Stool'}
     self.assertEqual(obs, exp)
Exemple #20
0
 def test_getAGBarcodeDetails(self):
     obs = db.getAGBarcodeDetails('000018046')
     exp = {'status': 'Received',
            'ag_kit_id': '0060a301-e5c0-6a4e-e050-8a800c5d49b7',
            'barcode': '000018046',
            'environment_sampled': None,
            # 'name': 'REMOVED',
            'ag_kit_barcode_id': '0060a301-e5c1-6a4e-e050-8a800c5d49b7',
            'sample_time': datetime.time(11, 15),
            # 'notes': 'REMOVED',
            'overloaded': 'N',
            'withdrawn': None,  # 'email': 'REMOVED',
            'other': 'N',
            # 'deposited': False,
            # 'participant_name': 'REMOVED-0',
            'refunded': None, 'moldy': 'N',
            'sample_date': datetime.date(2014, 8, 13),
            'date_of_last_email': datetime.date(2014, 8, 15),
            # 'other_text': 'REMOVED',
            'site_sampled': 'Stool'}
     # only look at those fields, that are not subject to scrubbing
     self.assertEqual({k: obs[k] for k in exp}, exp)
Exemple #21
0
    def test_get_ag_details(self):
        self.mock_login_admin()

        # test if AGP data are rendered correctly
        barcode = '000029153'
        response = self.get('/barcode_util/', {'barcode': barcode})
        self.assertEqual(response.code, 200)
        self.assertIn('<h2>%s Details</h2>' % 'American Gut', response.body)
        ag_details = db.getAGBarcodeDetails(barcode)
        self.assertIn(
            '<tr><td>Sample Date</td><td>%s</td></tr>' %
            ag_details['sample_date'], response.body)
        self.assertIn(
            '<tr><td>Sample Time</td><td>%s</td></tr>' %
            ag_details['sample_time'], response.body)
        self.assertIn(
            '<tr><td>Sample Site</td><td>%s</td></tr>' %
            ag_details['site_sampled'], response.body)

        self.assertIn(
            '<label for="moldy"> moldy (current: %s) </label> <br />' %
            ag_details['moldy'], response.body)
        self.assertIn(('<label for="overloaded"> overloaded (current: %s) '
                       '</label> <br />') % ag_details['overloaded'],
                      response.body)
        self.assertIn(('<label for="other"> other (current: %s) '
                       '</label> <br />') % ag_details['other'], response.body)

        self.assertIn(
            ('<textarea name="other_text" onclick="this.select()'
             '">%s</textarea>') % xhtml_escape(ag_details['other_text']),
            response.body)
        self.assertIn(
            ('<label for="send_mail" style="display:block;">send kit'
             ' owner %s (%s) an email </label>') % (xhtml_escape(
                 ag_details['name']), xhtml_escape(ag_details['email'])),
            response.body)
    def test_get(self):
        self.mock_login_admin()

        # check that error is raised for unknown barcode
        response = self.get('/ag_edit_barcode/', {'barcode': 'unknown'})
        self.assertEqual(response.code, 500)

        # make sure return code 400 is returned, if barcode is not given
        response = self.get('/ag_edit_barcode/', {})
        self.assertEqual(response.code, 400)

        # check if page is rendered properly
        barcode = '000004216'
        response = self.get('/ag_edit_barcode/', {'barcode': barcode})
        self.assertEqual(response.code, 200)
        self.assertIn('name="barcode" id="barcode" value="%s"' % barcode,
                      response.body)
        self.assertIn('<option value="Stool" selected>Stool</option>',
                      response.body)
        self.assertIn('2013-10-15', response.body)

        hs = db.human_sites
        hs.remove('Stool')
        for s in hs:
            self.assertIn('<option value="%s">%s</option>' % (str(s), str(s)),
                          response.body)

        for e in db.general_sites:
            self.assertIn('<option value="%s">%s</option>' % (str(e), str(e)),
                          response.body)

        pname = xhtml_escape(
            db.getAGBarcodeDetails(barcode)['participant_name'])
        self.assertIn(
            '<option value="%s" selected>%s</option>' % (pname, pname),
            response.body)
Exemple #23
0
    def get_ag_details(self, barcode):
        ag_details = db.getAGBarcodeDetails(barcode)
        if len(ag_details) > 0:
            for col, val in ag_details.iteritems():
                if val is None:
                    ag_details[col] = ''
            ag_details['other_checked'] = ''
            ag_details['overloaded_checked'] = ''
            ag_details['moldy_checked'] = ''
            ag_details['login_user'] = ag_details['name']
            if ag_details['moldy'] == 'Y':
                ag_details['moldy_checked'] = 'checked'
            if ag_details['overloaded'] == 'Y':
                ag_details['overloaded_checked'] = 'checked'
            if ag_details['other'] == 'Y':
                ag_details['other_checked'] = 'checked'

            survey_id = db.get_barcode_survey(barcode)
            _, failures = db.pulldown([barcode])
            if not (ag_details['sample_date'] == ag_details['site_sampled'] ==
                    ag_details['sample_time'] == ''):
                # it has all sample details
                # (sample time, date, site)
                if survey_id is None:
                    div_id = "not_assigned"
                    message = "Missing info"
                    ag_details['email_type'] = "0"
                elif barcode in failures:
                    div_id = "no_metadata"
                    message = "Cannot retrieve metadata"
                    ag_details['email_type'] = "-1"
                elif survey_type[survey_id] == 'Human':
                    # and we can successfully retrieve sample
                    # metadata
                    div_id = "verified"
                    message = "All good"
                    ag_details['email_type'] = "1"
                elif survey_type[survey_id] == 'Animal':
                    div_id = "verified_animal"
                    message = "All good"
                    ag_details['email_type'] = "1"
                else:
                    # should never get here (this would happen
                    # if the metadata
                    # pulldown returned more than one row for a
                    # single barcode)
                    div_id = "md_pulldown_error"
                    message = ("This barcode has multiple entries "
                               "in the database, which should "
                               "never happen. Please notify "
                               "someone on the database crew.")
                    ag_details['email_type'] = "-1"
            else:
                div_id = "not_assigned"
                message = ("In American Gut project group but No "
                           "American Gut info for barcode")
                ag_details['email_type'] = "-1"
        else:
            div_id = "not_assigned"
            message = ("In American Gut project group but No "
                       "American Gut info for barcode")
            ag_details['email_type'] = "-1"
        return div_id, message, ag_details
    def test_source_reassignment(self):
        # Elaine Wolfe found this bug, May 13th:
        # Manually changing the survey a sample is assigned to is not saved
        # even after getting the "barcode has successfully been updated"
        # message. All other field changes (time, sample type, etc.) are
        # saving properly.
        self.mock_login_admin()

        # this is a barcode that belongs to a set of ag_kits which has multiple
        # participant_names, i.e. sources
        # SELECT barcode
        # FROM barcodes.barcode
        # JOIN ag.ag_kit_barcodes USING (barcode)
        # JOIN ag.ag_kit USING (ag_kit_id)
        # WHERE ag_login_id IN
        #       (SELECT ag_login_id
        #               FROM (SELECT array_agg(participant_name) as sources,
        #                            count(participant_name) as numsources,
        #                            ag_login_id FROM ag.ag_login_surveys
        #                     GROUP BY ag_login_id) as foo
        #               WHERE numsources > 2);
        barcode = '000023125'  # current survey_id = "a4f1061f5bac9ae3"
        details = db.getAGBarcodeDetails(barcode)
        payload = {
            'barcode': barcode,
            'ag_kit_id': details['ag_kit_id'],
            'site_sampled': details['site_sampled'],
            'sample_date': details['sample_date'],
            'sample_time': details['sample_time'],
            'participant_name': details['participant_name'],
            'notes': details['notes'],
            'environment_sampled': details['environment_sampled'],
            'refunded': details['refunded'] or 'N',
            'withdrawn': details['withdrawn'] or 'N'
        }
        response = self.post('/ag_edit_barcode/', payload)
        self.assertEqual(response.code, 200)
        # check that no actual change has happened

        dbinfo = db.getAGBarcodeDetails(barcode)
        for field in payload.keys():
            if field in self.none_fields:
                if details[field] in [None, 'N', 'None', '']:
                    details[field] = None
                if dbinfo[field] in [None, 'N', 'None', '']:
                    dbinfo[field] = None
            self.assertEqual(details[field], dbinfo[field])

        # obtain all participant_names
        sql = """SELECT DISTINCT participant_name
                 FROM ag.ag_kit_barcodes
                 LEFT JOIN ag.ag_kit USING (ag_kit_id)
                 LEFT JOIN ag.ag_login_surveys USING (ag_login_id)
                 WHERE barcode = %s"""
        sourcenames = db._con.execute_fetchall(sql, [barcode])
        self.assertIsNotNone(sourcenames)

        sourcenames = [x[0] for x in sourcenames]
        # changing source for the barcode
        old_sourcename = payload['participant_name']
        new_sourcename = list(set(sourcenames) - set(old_sourcename))[0]
        payload['participant_name'] = new_sourcename

        response = self.post('/ag_edit_barcode/', payload)
        obs_details = db.getAGBarcodeDetails(barcode)

        # revert to old participant_name to leave a clean DB
        payload['participant_name'] = old_sourcename
        response = self.post('/ag_edit_barcode/', payload)

        self.assertEqual(response.code, 200)
        self.assertEqual(obs_details['participant_name'], new_sourcename)
        self.assertTrue(obs_details['participant_name'] != old_sourcename)
Exemple #25
0
    def get_ag_details(self, barcode):
        ag_details = db.getAGBarcodeDetails(barcode)
        if len(ag_details) > 0:
            for col, val in ag_details.iteritems():
                if val is None:
                    ag_details[col] = ''
            ag_details['other_checked'] = ''
            ag_details['overloaded_checked'] = ''
            ag_details['moldy_checked'] = ''
            ag_details['login_user'] = ag_details['name']
            if ag_details['moldy'] == 'Y':
                ag_details['moldy_checked'] = 'checked'
            if ag_details['overloaded'] == 'Y':
                ag_details['overloaded_checked'] = 'checked'
            if ag_details['other'] == 'Y':
                ag_details['other_checked'] = 'checked'

            survey_id = db.get_barcode_survey(barcode)
            _, failures = db.pulldown([barcode])
            if not (ag_details['sample_date'] ==
                    ag_details['site_sampled'] ==
                    ag_details['sample_time'] == ''):
                # it has all sample details
                # (sample time, date, site)
                if survey_id is None:
                    div_id = "not_assigned"
                    message = "Missing info"
                    ag_details['email_type'] = "0"
                elif barcode in failures:
                    div_id = "no_metadata"
                    message = "Cannot retrieve metadata"
                    ag_details['email_type'] = "-1"
                elif survey_type[survey_id] == 'Human':
                    # and we can successfully retrieve sample
                    # metadata
                    div_id = "verified"
                    message = "All good"
                    ag_details['email_type'] = "1"
                elif survey_type[survey_id] == 'Animal':
                    div_id = "verified_animal"
                    message = "All good"
                    ag_details['email_type'] = "1"
                else:
                    # should never get here (this would happen
                    # if the metadata
                    # pulldown returned more than one row for a
                    # single barcode)
                    div_id = "md_pulldown_error"
                    message = ("This barcode has multiple entries "
                               "in the database, which should "
                               "never happen. Please notify "
                               "someone on the database crew.")
                    ag_details['email_type'] = "-1"
            else:
                div_id = "not_assigned"
                message = ("In American Gut project group but No "
                           "American Gut info for barcode")
                ag_details['email_type'] = "-1"
        else:
            div_id = "not_assigned"
            message = ("In American Gut project group but No "
                       "American Gut info for barcode")
            ag_details['email_type'] = "-1"
        return div_id, message, ag_details