def get(self): project_names = db.getProjectNames() remaining = len(db.get_unassigned_barcodes()) self.render("ag_new_kit.html", projects=project_names, currentuser=self.current_user, msg="", kitinfo=[], fields="", remaining=remaining)
def post(self): tag = self.get_argument("tag") if not tag: tag = None projects = self.get_arguments("projects") num_swabs = map(int, self.get_arguments("swabs")) num_kits = map(int, self.get_arguments("kits")) kits = [] fields = "" try: kits = db.create_ag_kits(zip(num_swabs, num_kits), tag, projects) fields = ','.join(kits[0]._fields) except Exception as e: msg = "ERROR: %s" % str(e) else: msg = "Kits created! Please wait for downloads." project_names = db.getProjectNames() remaining = len(db.get_unassigned_barcodes()) self.render("ag_new_kit.html", projects=project_names, currentuser=self.current_user, msg=msg, kitinfo=dumps(kits), remaining=remaining, fields=fields)
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_get(self): self.mock_login_admin() response = self.get('/ag_new_kit/') self.assertEqual(response.code, 200) for project in db.getProjectNames(): self.assertIn("<option value='%s'>%s</option>" % (project, project), response.body) self.assertIn("%i</span> unassigned barcodes" % len(db.get_unassigned_barcodes()), response.body)
def test_get(self): self.mock_login() response = self.get('/projects/summary/') self.assertEqual(response.code, 200) # check that correct information is printed on HTML page. for project_name in db.getProjectNames(): num_barcodes = len(db.get_barcodes_for_projects([project_name])) self.assertIn('<tr><td>%s</td>' % project_name, response.body) self.assertIn('<td>%s</td></tr>' % num_barcodes, response.body)
def test_get(self): self.mock_login_admin() response = self.get('/ag_new_kit/') self.assertEqual(response.code, 200) obs = response.body.decode('utf-8') for project in db.getProjectNames(): self.assertIn("<option value='%s'>%s</option>" % ((xhtml_escape(project),) * 2), obs) self.assertIn("%i</span> unassigned barcodes" % len(db.get_unassigned_barcodes()), obs)
def test_get(self): self.mock_login_admin() response = self.get('/ag_new_kit/') self.assertEqual(response.code, 200) obs = response.body.decode('utf-8') for project in db.getProjectNames(): self.assertIn( "<option value='%s'>%s</option>" % ((xhtml_escape(project), ) * 2), obs) self.assertIn( "%i</span> unassigned barcodes" % len(db.get_unassigned_barcodes()), obs)
def get(self): project_names = db.getProjectNames() remaining = len(db.get_unassigned_barcodes()) self.render("ag_new_barcode.html", currentuser=self.current_user, projects=project_names, barcodes=[], remaining=remaining, msg="", newbc=[], assignedbc=[], assign_projects="")
def test_get(self): self.mock_login() response = self.get('/projects/summary/') self.assertEqual(response.code, 200) obs = response.body.decode('utf-8') # check that correct information is printed on HTML page. for project_name in db.getProjectNames(): num_barcodes = len(db.get_barcodes_for_projects([project_name])) self.assertIn('<tr><td>%s</td>' % xhtml_escape(project_name), obs) self.assertIn('<td>%s</td></tr>' % num_barcodes, obs)
def post(self): # create barcodes msg = "" newbc = [] assignedbc = [] projects = [] action = self.get_argument("action") num_barcodes = int(self.get_argument('numbarcodes')) if action == "create": newbc = db.create_barcodes(num_barcodes) msg = ("%d Barcodes created! Please wait for barcode download" % num_barcodes) elif action == "assign": projects = [ url_unescape(p).encode('utf-8') for p in self.get_arguments('projects') ] new_project = self.get_argument('newproject').strip() try: if new_project: db.create_project(new_project) projects.append(new_project) assignedbc = db.assign_barcodes(num_barcodes, projects) except ValueError as e: msg = u"ERROR! %s" % e.message else: projects = [p.decode('utf-8') for p in projects] tmp = u"%d barcodes assigned to %s, please wait for download." msg = tmp % (num_barcodes, ", ".join(projects)) else: raise HTTPError(400, 'Unknown action: %s' % action) project_names = db.getProjectNames() remaining = len(db.get_unassigned_barcodes()) self.render("ag_new_barcode.html", currentuser=self.current_user, projects=project_names, remaining=remaining, msg=msg, newbc=newbc, assignedbc=assignedbc, assign_projects=", ".join(projects))
def post(self): # create barcodes msg = "" newbc = [] assignedbc = [] projects = [] action = self.get_argument("action") num_barcodes = int(self.get_argument('numbarcodes')) if action == "create": newbc = db.create_barcodes(num_barcodes) msg = ("%d Barcodes created! Please wait for barcode download" % num_barcodes) elif action == "assign": projects = [url_unescape(p).encode('utf-8') for p in self.get_arguments('projects')] new_project = self.get_argument('newproject').strip() try: if new_project: db.create_project(new_project) projects.append(new_project) assignedbc = db.assign_barcodes(num_barcodes, projects) except ValueError as e: msg = u"ERROR! %s" % e.message else: projects = [p.decode('utf-8') for p in projects] tmp = u"%d barcodes assigned to %s, please wait for download." msg = tmp % (num_barcodes, ", ".join(projects)) else: raise HTTPError(400, 'Unknown action: %s' % action) project_names = db.getProjectNames() remaining = len(db.get_unassigned_barcodes()) self.render("ag_new_barcode.html", currentuser=self.current_user, projects=project_names, remaining=remaining, msg=msg, newbc=newbc, assignedbc=assignedbc, assign_projects=", ".join(projects))
def test_post(self): self.mock_login_admin() kits = [1, 2] swabs = [2, 2] tag = 'abc' # check for correct results projects = db.getProjectNames() project1 = projects[0].encode('utf-8') project2 = projects[1].encode('utf-8') response = self.post('/ag_new_kit/', {'tag': tag, 'projects': [project1, project2], 'swabs': swabs, 'kits': kits, }) kitinfo = loads(response.body) self.assertEqual(len(kitinfo['kitinfo']), sum(kits)) for k in kitinfo['kitinfo']: self.assertIn(tag, k[0]) self.assertEqual(len(kitinfo['kitinfo'][0][-1]), swabs[0]) self.assertEqual(len(kitinfo['kitinfo'][1][-1]), swabs[1]) self.assertEqual(kitinfo['fields'], "kit_id,password,verification_code,barcodes") # missing argument response = self.post('/ag_new_kit/', {'projects': [project1, project2], 'swabs': swabs, 'kits': kits, }) self.assertEqual(response.code, 400) # too long tag response = self.post('/ag_new_kit/', {'tag': 'toolongtag', 'projects': [project1, project2], 'swabs': swabs, 'kits': kits, }) # TODO: we should find more speaking ways to report an error to the # user, see issue: #113 self.assertEqual(response.code, 500) self.assertIn("Tag must be 4 or less characters", response.body) # test that non existing projects are recognized. response = self.post('/ag_new_kit/', {'tag': 'abc', 'projects': ['doesNotExist', 'PROJECT5'], 'swabs': swabs, 'kits': kits, }) self.assertEqual(response.code, 500) self.assertIn("Project(s) given don\'t exist in database:", response.body) # check for empty swabs list response = self.post('/ag_new_kit/', {'tag': tag, 'projects': [project1, project2], 'swabs': [], 'kits': kits, }) self.assertEqual(response.code, 500) self.assertIn("SET assigned_on = NOW() WHERE barcode IN ()", response.body) # no kits given response = self.post('/ag_new_kit/', {'tag': tag, 'projects': [project1, project2], 'swabs': swabs, 'kits': [], }) self.assertEqual(response.code, 500) self.assertIn("SET assigned_on = NOW() WHERE barcode IN ()", response.body) # what if tag is None response = self.post('/ag_new_kit/', {'tag': '', 'projects': [project1, project2], 'swabs': swabs, 'kits': kits, }) self.assertEqual(response.code, 200) kitinfo = loads(response.body) self.assertNotIn('_', kitinfo['kitinfo'][0][0])
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(self): self.mock_login_admin() action = 'unknown' num_barcodes = 4 projects = [p.encode('utf-8') for p in db.getProjectNames()[:2]] newProject = 'newProject' + str(os.getpid()) # check that unkown action results in a response code 400 response = self.post('/ag_new_barcode/', { 'action': action, 'numbarcodes': num_barcodes }) self.assertRaises(HTTPError) self.assertEqual(response.code, 400) self.assertIn( "HTTPError: HTTP %i: Bad Request (Unknown action: %s)" % (400, action), response.body) # TODO: test if exception for 0 barcodes to create is raised issue #105 # check creation of new barcodes response = self.post('/ag_new_barcode/', { 'action': 'create', 'numbarcodes': num_barcodes }) self.assertIn( "%i Barcodes created! Please wait for barcode download" % num_barcodes, response.body) # check assignment of barcodes # check that error is raised if project(s) cannot be found in DB prj_nonexist = 'a non existing project name' response = self.post( '/ag_new_barcode/', { 'action': 'assign', 'numbarcodes': num_barcodes, 'projects': projects + [prj_nonexist], 'newproject': "" }) self.assertEqual(response.code, 200) exp = xhtml_escape('ERROR! Project(s) given don\'t exist in ' 'database: %s' % prj_nonexist) self.assertIn(exp, response.body) # check correct assignment report on HTML side response = self.post( '/ag_new_barcode/', { 'action': 'assign', 'numbarcodes': num_barcodes, 'projects': projects, 'newproject': "" }) self.assertEqual(response.code, 200) exp = xhtml_escape( "%i barcodes assigned to %s, please wait for download." % (num_barcodes, ", ".join(projects))) self.assertIn(exp, response.body) # check if SQL error is thrown if number of barcodes is 0. # See issue: #107 response = self.post( '/ag_new_barcode/', { 'action': 'assign', 'numbarcodes': 0, 'projects': projects, 'newproject': "" }) self.assertEqual(response.code, 200) self.assertIn("Error running SQL query: UPDATE barcodes.barcode", response.body) # check recognition of existing projects response = self.post( '/ag_new_barcode/', { 'action': 'assign', 'numbarcodes': num_barcodes, 'newproject': projects[0] }) self.assertEqual(response.code, 200) self.assertIn( "ERROR! Project %s already exists!" % xhtml_escape(projects[0]), response.body) # check recognition of unkown action response = self.post('/ag_new_barcode/', {'action': 'unkown'}) self.assertEqual(response.code, 400) self.assertRaises(HTTPError) # test that new project is appended to list of projects response = self.post( '/ag_new_barcode/', { 'action': 'assign', 'numbarcodes': num_barcodes, 'projects': projects, 'newproject': newProject }) self.assertEqual(response.code, 200) self.assertIn( "%i barcodes assigned to %s, please wait for download." % (num_barcodes, ", ".join(map( xhtml_escape, projects + [newProject]))), response.body)
def get(self): projects = db.getProjectNames() # escape unicode project names for xhtml rendering info = [(p, len(db.get_barcodes_for_projects([p]))) for p in projects] self.render('projects_summary.html', proj_counts=info)
def get(self): projects = db.getProjectNames() info = [(p, len(db.get_barcodes_for_projects([p]))) for p in projects] self.render('projects_summary.html', proj_counts=info)
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 # 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)
def test_post(self): data = { 'barcode': '000029153', 'parent_project': 'American+Gut', 'postmark_date': '2015-06-25', 'scan_date': '2015-07-01', 'bstatus': 'Recieved', 'biomass_remaining': 'Unknown', 'sequencing_status': 'WAITING', 'obsolete_status': 'N', 'sent_date': '2015-01-07', 'login_user': '******', 'login_email': 'REMOVED', 'email_type': '1', 'sample_date': '2015-06-24', 'sample_time': '22%3A50%3A00', 'sample_site': 'Stool', 'other_text': 'REMOVED', 'send_mail': 'send_mail', } self.mock_login_admin() # check normal behaviour response = self.post('/barcode_util/', data) self.assertEqual(response.code, 200) self.assertIn('Barcode %s general details updated' % data['barcode'], response.body) self.assertIn('Project successfully changed', response.body) dbInfo = db.get_barcode_details(data['barcode']) self.assertEqual(date(2015, 6, 25), dbInfo['sample_postmark_date']) self.assertEqual(date(2015, 7, 1), dbInfo['scan_date']) # check that postmark_date and scan_date is set to None # if missed as an argument del data['postmark_date'] del data['scan_date'] response = self.post('/barcode_util/', data) self.assertEqual(response.code, 200) dbInfo = db.get_barcode_details(data['barcode']) self.assertEqual(None, dbInfo['sample_postmark_date']) self.assertEqual(None, dbInfo['scan_date']) data['postmark_date'] = '2015-06-25' data['scan_date'] = '2015-07-01' # TODO: Stefan Janssen: looks like we can successfully update a non # existing barcode!! data['barcode'] = 'rdskjmxykgrlyh' response = self.post('/barcode_util/', data) self.assertEqual(response.code, 200) self.assertTrue( '<p> Barcode %s general details updated </p>' % data['barcode'], response.body) data['barcode'] = '000029153' # check that update failes for wrong data types data['postmark_date'] = 'invalid date' response = self.post('/barcode_util/', data) self.assertEqual(response.code, 200) self.assertIn("Barcode %s general details failed" % data['barcode'], response.body) # test changing the barcode's project to a non existing one # TODO: Stefan Janssen: I think this should not result in a positive # message like 'Project successfully changed', because this does not # trigger the creation of a new project! data['project'] = 'NotAProject' response = self.post('/barcode_util/', data) self.assertEqual(response.code, 200) self.assertTrue( '<p> Barcode %s general details updated </p>' % data['barcode'], response.body) self.assertIn('Project successfully changed', response.body) # check updating a AGP barcode del data['project'] response = self.post('/barcode_util/', data) self.assertEqual(response.code, 200) self.assertIn( "Barcode %s AG info was successfully updated" % data['barcode'], response.body) data = { 'barcode': db.ut_get_arbitrary_non_ag_barcode(), 'parent_project': db.getProjectNames()[1], 'scan_date': '2014-12-15', 'bstatus': 'Recieved', 'biomass_remaining': 'Unknown', 'sequencing_status': 'WAITING', 'obsolete_status': 'N', 'project': 'UNKNOWN', } response = self.post('/barcode_util/', data) self.assertEqual(response.code, 200) self.assertNotIn( "Barcode %s AG info was successfully updated" % data['barcode'], response.body) self.assertTrue( '<p> Barcode %s general details updated </p>' % data['barcode'], response.body)
def test_post(self): self.mock_login_admin() kits = [1, 2] swabs = [2, 2] tag = 'abc' # check for correct results projects = db.getProjectNames() project1 = projects[0].encode('utf-8') project2 = projects[1].encode('utf-8') response = self.post( '/ag_new_kit/', { 'tag': tag, 'projects': [project1, project2], 'swabs': swabs, 'kits': kits, }) kitinfo = loads(response.body) self.assertEqual(len(kitinfo['kitinfo']), sum(kits)) for k in kitinfo['kitinfo']: self.assertIn(tag, k[0]) self.assertEqual(len(kitinfo['kitinfo'][0][-1]), swabs[0]) self.assertEqual(len(kitinfo['kitinfo'][1][-1]), swabs[1]) self.assertEqual(kitinfo['fields'], "kit_id,password,verification_code,barcodes") # missing argument response = self.post('/ag_new_kit/', { 'projects': [project1, project2], 'swabs': swabs, 'kits': kits, }) self.assertEqual(response.code, 400) # too long tag response = self.post( '/ag_new_kit/', { 'tag': 'toolongtag', 'projects': [project1, project2], 'swabs': swabs, 'kits': kits, }) # TODO: we should find more speaking ways to report an error to the # user, see issue: #113 self.assertEqual(response.code, 500) self.assertIn("Tag must be 4 or less characters", response.body) # test that non existing projects are recognized. response = self.post( '/ag_new_kit/', { 'tag': 'abc', 'projects': ['doesNotExist', 'PROJECT5'], 'swabs': swabs, 'kits': kits, }) self.assertEqual(response.code, 500) self.assertIn("Project(s) given don\'t exist in database:", response.body) # check for empty swabs list response = self.post( '/ag_new_kit/', { 'tag': tag, 'projects': [project1, project2], 'swabs': [], 'kits': kits, }) self.assertEqual(response.code, 500) self.assertIn("SET assigned_on = NOW() WHERE barcode IN ()", response.body) # no kits given response = self.post( '/ag_new_kit/', { 'tag': tag, 'projects': [project1, project2], 'swabs': swabs, 'kits': [], }) self.assertEqual(response.code, 500) self.assertIn("SET assigned_on = NOW() WHERE barcode IN ()", response.body) # what if tag is None response = self.post( '/ag_new_kit/', { 'tag': '', 'projects': [project1, project2], 'swabs': swabs, 'kits': kits, }) self.assertEqual(response.code, 200) kitinfo = loads(response.body) self.assertNotIn('_', kitinfo['kitinfo'][0][0])
def test_post(self): self.mock_login_admin() action = 'unknown' num_barcodes = 4 projects = [p.encode('utf-8') for p in db.getProjectNames()[:2]] newProject = 'newProject' + str(os.getpid()) # check that unkown action results in a response code 400 response = self.post('/ag_new_barcode/', {'action': action, 'numbarcodes': num_barcodes}) self.assertRaises(HTTPError) self.assertEqual(response.code, 400) self.assertIn("HTTPError: HTTP %i: Bad Request (Unknown action: %s)" % (400, action), response.body) # TODO: test if exception for 0 barcodes to create is raised issue #105 # check creation of new barcodes response = self.post('/ag_new_barcode/', {'action': 'create', 'numbarcodes': num_barcodes}) self.assertIn("%i Barcodes created! Please wait for barcode download" % num_barcodes, response.body) # check assignment of barcodes # check that error is raised if project(s) cannot be found in DB prj_nonexist = 'a non existing project name' response = self.post('/ag_new_barcode/', {'action': 'assign', 'numbarcodes': num_barcodes, 'projects': projects + [prj_nonexist], 'newproject': ""}) self.assertEqual(response.code, 200) exp = xhtml_escape('ERROR! Project(s) given don\'t exist in ' 'database: %s' % prj_nonexist) self.assertIn(exp, response.body) # check correct assignment report on HTML side response = self.post('/ag_new_barcode/', {'action': 'assign', 'numbarcodes': num_barcodes, 'projects': projects, 'newproject': ""}) self.assertEqual(response.code, 200) exp = xhtml_escape( "%i barcodes assigned to %s, please wait for download." % (num_barcodes, ", ".join(projects))) self.assertIn(exp, response.body) # check if SQL error is thrown if number of barcodes is 0. # See issue: #107 response = self.post('/ag_new_barcode/', {'action': 'assign', 'numbarcodes': 0, 'projects': projects, 'newproject': ""}) self.assertEqual(response.code, 200) self.assertIn("Error running SQL query: UPDATE barcodes.barcode", response.body) # check recognition of existing projects response = self.post('/ag_new_barcode/', {'action': 'assign', 'numbarcodes': num_barcodes, 'newproject': projects[0]}) self.assertEqual(response.code, 200) self.assertIn("ERROR! Project %s already exists!" % xhtml_escape(projects[0]), response.body) # check recognition of unkown action response = self.post('/ag_new_barcode/', {'action': 'unkown'}) self.assertEqual(response.code, 400) self.assertRaises(HTTPError) # test that new project is appended to list of projects response = self.post('/ag_new_barcode/', {'action': 'assign', 'numbarcodes': num_barcodes, 'projects': projects, 'newproject': newProject}) self.assertEqual(response.code, 200) self.assertIn("%i barcodes assigned to %s, please wait for download." % (num_barcodes, ", ".join(map(xhtml_escape, projects + [newProject]))), response.body)
def test_post(self): data = { 'barcode': '000029153', 'parent_project': 'American+Gut', 'postmark_date': '2015-06-25', 'scan_date': '2015-07-01', 'bstatus': 'Recieved', 'biomass_remaining': 'Unknown', 'sequencing_status': 'WAITING', 'obsolete_status': 'N', 'sent_date': '2015-01-07', 'login_user': '******', 'login_email': 'REMOVED', 'email_type': '1', 'sample_date': '2015-06-24', 'sample_time': '22%3A50%3A00', 'sample_site': 'Stool', 'other_text': 'REMOVED', 'send_mail': 'send_mail', } self.mock_login_admin() # check normal behaviour response = self.post('/barcode_util/', data) self.assertEqual(response.code, 200) self.assertIn('Barcode %s general details updated' % data['barcode'], response.body) self.assertIn('Project successfully changed', response.body) dbInfo = db.get_barcode_details(data['barcode']) self.assertEqual(date(2015, 6, 25), dbInfo['sample_postmark_date']) self.assertEqual(date(2015, 7, 1), dbInfo['scan_date']) # check that postmark_date and scan_date is set to None # if missed as an argument del data['postmark_date'] del data['scan_date'] response = self.post('/barcode_util/', data) self.assertEqual(response.code, 200) dbInfo = db.get_barcode_details(data['barcode']) self.assertEqual(None, dbInfo['sample_postmark_date']) self.assertEqual(None, dbInfo['scan_date']) data['postmark_date'] = '2015-06-25' data['scan_date'] = '2015-07-01' # TODO: Stefan Janssen: looks like we can successfully update a non # existing barcode!! data['barcode'] = 'rdskjmxykgrlyh' response = self.post('/barcode_util/', data) self.assertEqual(response.code, 200) self.assertTrue('<p> Barcode %s general details updated </p>' % data['barcode'], response.body) data['barcode'] = '000029153' # check that update failes for wrong data types data['postmark_date'] = 'invalid date' response = self.post('/barcode_util/', data) self.assertEqual(response.code, 200) self.assertIn("Barcode %s general details failed" % data['barcode'], response.body) # test changing the barcode's project to a non existing one # TODO: Stefan Janssen: I think this should not result in a positive # message like 'Project successfully changed', because this does not # trigger the creation of a new project! data['project'] = 'NotAProject' response = self.post('/barcode_util/', data) self.assertEqual(response.code, 200) self.assertTrue('<p> Barcode %s general details updated </p>' % data['barcode'], response.body) self.assertIn('Project successfully changed', response.body) # check updating a AGP barcode del data['project'] response = self.post('/barcode_util/', data) self.assertEqual(response.code, 200) self.assertIn("Barcode %s AG info was successfully updated" % data['barcode'], response.body) data = { 'barcode': db.ut_get_arbitrary_non_ag_barcode(), 'parent_project': db.getProjectNames()[1], 'scan_date': '2014-12-15', 'bstatus': 'Recieved', 'biomass_remaining': 'Unknown', 'sequencing_status': 'WAITING', 'obsolete_status': 'N', 'project': 'UNKNOWN', } response = self.post('/barcode_util/', data) self.assertEqual(response.code, 200) self.assertNotIn("Barcode %s AG info was successfully updated" % data['barcode'], response.body) self.assertTrue('<p> Barcode %s general details updated </p>' % data['barcode'], response.body)