def test_post_update_ag_project_change(self): db.alter_access_levels("test", [3]) self.data["project"] = "UNKNOWN" 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("Project successfully changed", response.body) barcode_projects, parent_project = db.getBarcodeProjType(self.ag_good) self.assertEqual(barcode_projects, "UNKNOWN") self.assertEqual(parent_project, "American Gut") # reset back db.setBarcodeProjects(self.ag_good, rem_projects=["UNKNOWN"]) barcode_projects, parent_project = db.getBarcodeProjType(self.ag_good) self.assertEqual(barcode_projects, "") self.assertEqual(parent_project, "American Gut")
def get(self): barcode = self.get_argument('barcode', None) if barcode is None: self.render("barcode_util.html", div_and_msg=None, barcode_projects=[], parent_project=None, project_names=[], barcode=None, email_type=None, barcode_info=None, proj_barcode_info=None, msgs=None, currentuser=self.current_user) return # gather info to display barcode_details = db.get_barcode_details(barcode) if len(barcode_details) == 0: div_id = "invalid_barcode" message = ("Barcode %s does not exist in the database" % barcode) self.render("barcode_util.html", div_and_msg=(div_id, message, barcode), barcode_projects=[], parent_project=None, project_names=[], barcode=barcode, email_type=None, barcode_info=None, proj_barcode_info=None, msgs=None, currentuser=self.current_user) return barcode_projects, parent_project = db.getBarcodeProjType( barcode) project_names = db.getProjectNames() # barcode exists get general info if barcode_details['status'] is None: barcode_details['status'] = 'Received' if barcode_details['biomass_remaining'] is None: barcode_details['biomass_remaining'] = 'Unknown' if barcode_details['sequencing_status'] is None: barcode_details['sequencing_status'] if barcode_details['obsolete'] is None: barcode_details['obsolete'] = 'N' div_id = message = "" if (barcode_details['obsolete'] == "Y"): # the barcode is obsolete div_id = "obsolete" message = "Barcode is Obsolete" # get project info for div ag_details = [] if parent_project == 'American Gut': div_id, message, ag_details = self.get_ag_details(barcode) else: div_id = "verified" message = "Barcode Info is correct" div_and_msg = (div_id, message, barcode) self.render("barcode_util.html", div_and_msg=div_and_msg, barcode_projects=barcode_projects, parent_project=parent_project, project_names=project_names, barcode=barcode, email_type=None, barcode_info=barcode_details, proj_barcode_info=ag_details, msgs=None, currentuser=self.current_user)
def test_post_update_ag_project_change(self): db.alter_access_levels('test', [3]) self.data['project'] = 'UNKNOWN' 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('Project successfully changed', response.body) barcode_projects, parent_project = db.getBarcodeProjType(self.ag_good) self.assertEqual(barcode_projects, 'UNKNOWN') self.assertEqual(parent_project, 'American Gut') # reset back db.setBarcodeProjects(self.ag_good, rem_projects=['UNKNOWN']) barcode_projects, parent_project = db.getBarcodeProjType(self.ag_good) self.assertEqual(barcode_projects, '') self.assertEqual(parent_project, 'American Gut')
def test_get_non_ag_barcode(self): self.mock_login() db.alter_access_levels('test', [3]) response = self.get('/barcode_util/', {'barcode': self.not_ag}) self.assertEqual(response.code, 200) self.assertIn( '<input id="barcode" name="barcode" type="text" ' 'onclick="this.select()" />', response.body) self.assertNotIn( '<input class="checkbox" type="checkbox" name="sample' '_issue" id="overloaded" value="overloaded" }/>', response.body) exp_prj_name = list(set(db.getBarcodeProjType(self.not_ag)))[0] self.assertIn('Project type: %s' % exp_prj_name.encode('utf-8'), response.body) self.assertIn('Barcode Info is correct', response.body)
def test_get_non_ag_barcode(self): self.mock_login() db.alter_access_levels('test', [3]) response = self.get('/barcode_util/', {'barcode': self.not_ag}) self.assertEqual(response.code, 200) self.assertIn( '<input id="barcode" name="barcode" type="text" ' 'onclick="this.select()" />', response.body) self.assertNotIn('<input class="checkbox" type="checkbox" name="sample' '_issue" id="overloaded" value="overloaded" }/>', response.body) exp_prj_name = list(set(db.getBarcodeProjType(self.not_ag)))[0] self.assertIn('Project type: %s' % exp_prj_name.encode('utf-8'), response.body) self.assertIn('Barcode Info is correct', response.body)
def post(self): barcode = self.get_argument('barcode') postmark_date = self.get_argument('postmark_date', None) scan_date = self.get_argument('scan_date', None) biomass_remaining_value = self.get_argument('biomass_remaining_value', None) sequencing_status = self.get_argument('sequencing_status', None) obsolete_status = self.get_argument('obsolete_status', None) projects = set(self.get_arguments('project')) sent_date = self.get_argument('sent_date', None) login_user = self.get_argument('login_user', 'American Gut participant') send_mail = self.get_argument('send_mail', None) login_email = self.get_argument('login_email', None) other_text = self.get_argument('other_text', None) email_type = self.get_argument('email_type', None) sample_time = self.get_argument('sample_time', None) sample_date = self.get_argument('sample_date', None) # now we collect data and update based on forms # first update general barcode info # Set to non to make sure no conflicts with new date typing in DB if not postmark_date: postmark_date = None if not scan_date: scan_date = None try: db.updateBarcodeStatus('Received', postmark_date, scan_date, barcode, biomass_remaining_value, sequencing_status, obsolete_status) gen_update_msg = "Barcode %s general details updated" % barcode except: # noqa gen_update_msg = "Barcode %s general details failed" % barcode email_msg = ag_update_msg = project_msg = None exisiting_proj, parent_project = db.getBarcodeProjType(barcode) # This WILL NOT let you remove a sample from being in AG if it is # part of AG to begin with exisiting_proj = set(exisiting_proj.split(', ')) if exisiting_proj != projects: try: add_projects = projects.difference(exisiting_proj) rem_projects = exisiting_proj.difference(projects) db.setBarcodeProjects(barcode, add_projects, rem_projects) project_msg = "Project successfully changed" except: # noqa project_msg = "Error changing project" new_proj, parent_project = db.getBarcodeProjType(barcode) if parent_project == 'American Gut': db.push_barcode_to_qiita_buffer(barcode) email_msg, ag_update_msg = self.update_ag_barcode( barcode, login_user, login_email, email_type, sent_date, send_mail, sample_date, sample_time, other_text) self.render("barcode_util.html", div_and_msg=None, barcode_projects=[], parent_project=None, project_names=[], barcode=None, email_type=None, barcode_info=None, proj_barcode_info=None, msgs=(gen_update_msg, email_msg, ag_update_msg, project_msg), currentuser=self.current_user)
def get(self): barcode = self.get_argument('barcode', None) if barcode is None: self.render("barcode_util.html", div_and_msg=None, barcode_projects=[], parent_project=None, project_names=[], barcode=None, email_type=None, barcode_info=None, proj_barcode_info=None, msgs=None, currentuser=self.current_user) return # gather info to display barcode_details = db.get_barcode_details(barcode) if len(barcode_details) == 0: div_id = "invalid_barcode" message = ("Barcode %s does not exist in the database" % barcode) self.render("barcode_util.html", div_and_msg=(div_id, message, barcode), barcode_projects=[], parent_project=None, project_names=[], barcode=barcode, email_type=None, barcode_info=None, proj_barcode_info=None, msgs=None, currentuser=self.current_user) return barcode_projects, parent_project = db.getBarcodeProjType(barcode) project_names = db.getProjectNames() # barcode exists get general info # TODO (Stefan Janssen): check spelling of "received", i.e. tests in # the template check for 'Recieved'. I think the logic is broken due # to that. if barcode_details['status'] is None: barcode_details['status'] = 'Received' if barcode_details['biomass_remaining'] is None: barcode_details['biomass_remaining'] = 'Unknown' if barcode_details['sequencing_status'] is None: barcode_details['sequencing_status'] if barcode_details['obsolete'] is None: barcode_details['obsolete'] = 'N' div_id = message = "" if (barcode_details['obsolete'] == "Y"): # the barcode is obsolete div_id = "obsolete" # TODO: Stefan: why is that set here, as far as I see, this # message will in all cases be overwritten! message = "Barcode is Obsolete" # get project info for div ag_details = [] if parent_project == 'American Gut': div_id, message, ag_details = self.get_ag_details(barcode) else: div_id = "verified" message = "Barcode Info is correct" div_and_msg = (div_id, message, barcode) self.render("barcode_util.html", div_and_msg=div_and_msg, barcode_projects=barcode_projects, parent_project=parent_project, project_names=project_names, barcode=barcode, email_type=None, barcode_info=barcode_details, proj_barcode_info=ag_details, msgs=None, currentuser=self.current_user)
def get(self): barcode = self.get_argument('barcode', None) if barcode is None: self.render("barcode_util.html", div_and_msg=None, barcode_projects=[], parent_project=None, project_names=[], barcode=None, email_type=None, barcode_info=None, proj_barcode_info=None, msgs=None, currentuser=self.current_user) return # gather info to display barcode_details = db.get_barcode_details(barcode) if len(barcode_details) == 0: div_id = "invalid_barcode" message = ("Barcode %s does not exist in the database" % barcode) self.render("barcode_util.html", div_and_msg=(div_id, message, barcode), barcode_projects=[], parent_project=None, project_names=[], barcode=barcode, email_type=None, barcode_info=None, proj_barcode_info=None, msgs=None, currentuser=self.current_user) return barcode_projects, parent_project = db.getBarcodeProjType(barcode) project_names = db.getProjectNames() # barcode exists get general info if barcode_details['status'] is None: barcode_details['status'] = 'Received' if barcode_details['biomass_remaining'] is None: barcode_details['biomass_remaining'] = 'Unknown' if barcode_details['sequencing_status'] is None: barcode_details['sequencing_status'] if barcode_details['obsolete'] is None: barcode_details['obsolete'] = 'N' div_id = message = "" if (barcode_details['obsolete'] == "Y"): # the barcode is obsolete div_id = "obsolete" message = "Barcode is Obsolete" # get project info for div ag_details = [] if parent_project == 'American Gut': div_id, message, ag_details = self.get_ag_details(barcode) else: div_id = "verified" message = "Barcode Info is correct" div_and_msg = (div_id, message, barcode) self.render("barcode_util.html", div_and_msg=div_and_msg, barcode_projects=barcode_projects, parent_project=parent_project, project_names=project_names, barcode=barcode, email_type=None, barcode_info=barcode_details, proj_barcode_info=ag_details, msgs=None, currentuser=self.current_user)
def post(self): barcode = self.get_argument('barcode') postmark_date = self.get_argument('postmark_date', None) scan_date = self.get_argument('scan_date', None) biomass_remaining_value = self.get_argument('biomass_remaining_value', None) sequencing_status = self.get_argument('sequencing_status', None) obsolete_status = self.get_argument('obsolete_status', None) projects = set(self.get_arguments('project')) sent_date = self.get_argument('sent_date', None) login_user = self.get_argument('login_user', 'American Gut participant') send_mail = self.get_argument('send_mail', None) login_email = self.get_argument('login_email', None) other_text = self.get_argument('other_text', None) email_type = self.get_argument('email_type', None) sample_time = self.get_argument('sample_time', None) sample_date = self.get_argument('sample_date', None) # now we collect data and update based on forms # first update general barcode info # Set to non to make sure no conflicts with new date typing in DB if not postmark_date: postmark_date = None if not scan_date: scan_date = None try: db.updateBarcodeStatus('Received', postmark_date, scan_date, barcode, biomass_remaining_value, sequencing_status, obsolete_status) gen_update_msg = "Barcode %s general details updated" % barcode except: gen_update_msg = "Barcode %s general details failed" % barcode email_msg = ag_update_msg = project_msg = None exisiting_proj, parent_project = db.getBarcodeProjType( barcode) # This WILL NOT let you remove a sample from being in AG if it is # part of AG to begin with exisiting_proj = set(exisiting_proj.split(', ')) if exisiting_proj != projects: try: add_projects = projects.difference(exisiting_proj) rem_projects = exisiting_proj.difference(projects) db.setBarcodeProjects(barcode, add_projects, rem_projects) project_msg = "Project successfully changed" except: project_msg = "Error changing project" new_proj, parent_project = db.getBarcodeProjType(barcode) if parent_project == 'American Gut': email_msg, ag_update_msg = self.update_ag_barcode( barcode, login_user, login_email, email_type, sent_date, send_mail, sample_date, sample_time, other_text) self.render("barcode_util.html", div_and_msg=None, barcode_projects=[], parent_project=None, project_names=[], barcode=None, email_type=None, barcode_info=None, proj_barcode_info=None, msgs=(gen_update_msg, email_msg, ag_update_msg, project_msg), currentuser=self.current_user)
def get(self): barcode = self.get_argument('barcode', None) if barcode is None: self.render("barcode_util.html", div_and_msg=None, barcode_projects=[], parent_project=None, project_names=[], barcode=None, email_type=None, barcode_info=None, proj_barcode_info=None, msgs=None, currentuser=self.current_user) return # gather info to display barcode_details = db.get_barcode_details(barcode) if len(barcode_details) == 0: div_id = "invalid_barcode" message = ("Barcode %s does not exist in the database" % barcode) self.render("barcode_util.html", div_and_msg=(div_id, message, barcode), barcode_projects=[], parent_project=None, project_names=[], barcode=barcode, email_type=None, barcode_info=None, proj_barcode_info=None, msgs=None, currentuser=self.current_user) return barcode_projects, parent_project = db.getBarcodeProjType( barcode) project_names = db.getProjectNames() # barcode exists get general info # TODO (Stefan Janssen): check spelling of "received", i.e. tests in # the template check for 'Recieved'. I think the logic is broken due # to that. if barcode_details['status'] is None: barcode_details['status'] = 'Received' if barcode_details['biomass_remaining'] is None: barcode_details['biomass_remaining'] = 'Unknown' if barcode_details['sequencing_status'] is None: barcode_details['sequencing_status'] if barcode_details['obsolete'] is None: barcode_details['obsolete'] = 'N' div_id = message = "" if (barcode_details['obsolete'] == "Y"): # the barcode is obsolete div_id = "obsolete" # TODO: Stefan: why is that set here, as far as I see, this # message will in all cases be overwritten! message = "Barcode is Obsolete" # get project info for div ag_details = [] if parent_project == 'American Gut': div_id, message, ag_details = self.get_ag_details(barcode) else: div_id = "verified" message = "Barcode Info is correct" div_and_msg = (div_id, message, barcode) self.render("barcode_util.html", div_and_msg=div_and_msg, barcode_projects=barcode_projects, parent_project=parent_project, project_names=project_names, barcode=barcode, email_type=None, barcode_info=barcode_details, proj_barcode_info=ag_details, msgs=None, currentuser=self.current_user)
def post(self): barcode = self.get_argument('barcode', None) bstatus = self.get_argument('bstatus', None) postmark_date = self.get_argument('postmark_date', None) scan_date = self.get_argument('scan_date', None) biomass_remaining_value = self.get_argument('biomass_remaining_value', None) sequencing_status = self.get_argument('sequencing_status', None) obsolete_status = self.get_argument('obsolete_status', None) projects = set(self.get_arguments('project')) barcode_projects = 'Unknown' ag_details = {} if bstatus is None: # gather info to display barcode_details = db.get_barcode_details(barcode) if len(barcode_details) == 0: div_id = "invalid_barcode" message = ("Barcode %s does not exist in the database" % barcode) self.render("barcode_util.html", div_and_msg=(div_id, message, barcode), barcode_projects=[], parent_project=None, project_names=[], barcode=barcode, email_type=None, barcode_info=None, proj_barcode_info=None, msgs=None, currentuser=self.current_user) return else: barcode_projects, parent_project = db.getBarcodeProjType( barcode) project_names = db.getProjectNames() # barcode exists get general info if barcode_details['status'] is None: barcode_details['status'] = 'Received' if barcode_details['biomass_remaining'] is None: barcode_details['biomass_remaining'] = 'Unknown' if barcode_details['sequencing_status'] is None: barcode_details['sequencing_status'] if barcode_details['obsolete'] is None: barcode_details['obsolete'] = 'N' div_id = message = email_type = "" ag_details = [] if (barcode_details['obsolete'] == "Y"): #the barcode is obsolete div_id = "obsolete" message = "Barcode is Obsolete" #get project info for div if parent_project == 'American Gut': div_id, message, ag_details = self.get_ag_details(barcode) else: div_id = "verified" message = "Barcode Info is correct" div_and_msg = (div_id, message, barcode) self.render("barcode_util.html", div_and_msg=div_and_msg, barcode_projects=barcode_projects, parent_project=parent_project, project_names=project_names, barcode=barcode, email_type=None, barcode_info=barcode_details, proj_barcode_info=ag_details, msgs=None, currentuser=self.current_user) else: #now we collect data and update based on forms #first update general barcode info #Set to non to make sure no conflicts with new date typing in DB if not postmark_date: postmark_date = None if not scan_date: scan_date = None try: db.updateBarcodeStatus('Received', postmark_date, scan_date, barcode, biomass_remaining_value, sequencing_status, obsolete_status) msg1 = "Barcode %s general details updated" % barcode except: msg1 = "Barcode %s general details failed" % barcode msg2 = msg3 = msg4 = None exisiting_proj, parent_project = db.getBarcodeProjType(barcode) exisiting_proj = set(exisiting_proj.split(',')) if exisiting_proj != projects: try: add_projects = projects.difference(exisiting_proj) rem_projects = exisiting_proj.difference(projects) print exisiting_proj print projects print add_projects print rem_projects db.setBarcodeProjects(barcode, add_projects, rem_projects) msg4 = "Project successfully changed" except: msg4 = "Error changing project" new_proj, parent_project = db.getBarcodeProjType(barcode) if parent_project == 'American Gut': msg2, msg3 = self.update_ag_barcode(barcode) self.render("barcode_util.html", div_and_msg=None, barcode_projects=[], parent_project=None, project_names=[], barcode=None, email_type=None, barcode_info=None, proj_barcode_info=None, msgs=(msg1, msg2, msg3, msg4), currentuser=self.current_user)
def post(self): barcode = self.get_argument('barcode', None) bstatus = self.get_argument('bstatus', None) postmark_date = self.get_argument('postmark_date', None) scan_date = self.get_argument('scan_date', None) biomass_remaining_value = self.get_argument('biomass_remaining_value', None) sequencing_status = self.get_argument('sequencing_status', None) obsolete_status = self.get_argument('obsolete_status', None) projects = set(self.get_arguments('project')) barcode_projects = 'Unknown' ag_details = {} if bstatus is None: # gather info to display barcode_details = db.get_barcode_details(barcode) if len(barcode_details) == 0: div_id = "invalid_barcode" message = ("Barcode %s does not exist in the database" % barcode) self.render("barcode_util.html", div_and_msg=(div_id, message, barcode), barcode_projects=[], parent_project=None, project_names=[], barcode=barcode, email_type=None, barcode_info=None, proj_barcode_info=None, msgs=None, currentuser=self.current_user) return else: barcode_projects, parent_project = db.getBarcodeProjType( barcode) project_names = db.getProjectNames() # barcode exists get general info if barcode_details['status'] is None: barcode_details['status'] = 'Received' if barcode_details['biomass_remaining'] is None: barcode_details['biomass_remaining'] = 'Unknown' if barcode_details['sequencing_status'] is None: barcode_details['sequencing_status'] if barcode_details['obsolete'] is None: barcode_details['obsolete'] = 'N' div_id = message = email_type = "" ag_details = [] if (barcode_details['obsolete'] == "Y"): #the barcode is obsolete div_id = "obsolete" message = "Barcode is Obsolete" #get project info for div if parent_project == 'American Gut': div_id, message, ag_details = self.get_ag_details(barcode) else: div_id = "verified" message = "Barcode Info is correct" div_and_msg = (div_id, message, barcode) self.render("barcode_util.html", div_and_msg=div_and_msg, barcode_projects=barcode_projects, parent_project=parent_project, project_names=project_names, barcode=barcode, email_type=None, barcode_info=barcode_details, proj_barcode_info=ag_details, msgs=None, currentuser=self.current_user) else: #now we collect data and update based on forms #first update general barcode info #Set to non to make sure no conflicts with new date typing in DB if not postmark_date: postmark_date = None if not scan_date: scan_date = None try: db.updateBarcodeStatus('Received', postmark_date, scan_date, barcode, biomass_remaining_value, sequencing_status, obsolete_status) msg1 = "Barcode %s general details updated" % barcode except: msg1 = "Barcode %s general details failed" % barcode msg2 = msg3 = msg4 = None exisiting_proj, parent_project = db.getBarcodeProjType( barcode) exisiting_proj = set(exisiting_proj.split(',')) if exisiting_proj != projects: try: add_projects = projects.difference(exisiting_proj) rem_projects = exisiting_proj.difference(projects) print exisiting_proj print projects print add_projects print rem_projects db.setBarcodeProjects(barcode, add_projects, rem_projects) msg4 = "Project successfully changed" except: msg4 = "Error changing project" new_proj, parent_project = db.getBarcodeProjType(barcode) if parent_project == 'American Gut': msg2, msg3 = self.update_ag_barcode(barcode) self.render("barcode_util.html", div_and_msg=None, barcode_projects=[], parent_project=None, project_names=[], barcode=None, email_type=None, barcode_info=None, proj_barcode_info=None, msgs=(msg1, msg2, msg3, msg4), currentuser=self.current_user)