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 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
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