def test_get(self): self.mock_login() db.alter_access_levels('test', [4]) response = self.get('/ag_third_party/add/') self.assertEqual(response.code, 200) self.assertIn('<label for="description">Description</label>', response.body)
def test_get(self): self.mock_login() db.alter_access_levels('test', [4]) response = self.get('/ag_third_party/data/') self.assertEqual(response.code, 200) self.assertIn('File seperator', response.body) self.assertIn('Vioscreen', response.body)
def test_post_not_logged_in(self): db.alter_access_levels('test', [4]) data = {'survey': 'Vioscreen', 'seperator': 'comma', 'survey_id': 'SubjectId', 'trim': '-160'} files = {'file_in': self.ext_survey_fp} response = self.post('/ag_third_party/data/', data, files) self.assertEqual(response.code, 403)
def test_get(self): self.mock_login() db.alter_access_levels("test", [3]) response = self.get("/barcode_util/") self.assertEqual(response.code, 200) self.assertIn('<input id="barcode" name="barcode" type="text" ' 'onclick="this.select()" />', response.body) self.assertNotIn('<option value="American Gut Project">' "American Gut Project</option>", response.body)
def test_get_not_logged_in(self): db.alter_access_levels('test', [3]) response = self.get('/ag_search/') self.assertEqual(response.code, 200) port = self.get_http_port() self.assertEqual(response.effective_url, 'http://localhost:%d/login/?next=%s' % (port, url_escape('/ag_search/')))
def test_post_data(self): self.mock_login() db.alter_access_levels('test', [4]) name = ''.join([choice(ascii_letters) for x in range(15)]) response = self.post('/ag_third_party/add/', data={'name': name, 'description': 'TEST', 'url': 'test.fake'}) self.assertEqual(response.code, 200) self.assertIn("Added '%s' successfully" % name, response.body)
def test_post_existing_survey(self): self.mock_login() db.alter_access_levels('test', [4]) data = {'name': 'Vioscreen', 'description': 'TEST', 'url': 'test.fake'} response = self.post('/ag_third_party/add/', data) self.assertEqual(response.code, 200) self.assertIn("Survey 'Vioscreen' already exists", response.body) db._clear_table('external_survey_answers', 'ag')
def test_post_missing_data(self): self.mock_login_admin() db.alter_access_levels('test', [4]) data = {'name': ''.join([choice(ascii_letters) for x in range(15)]), 'description': 'TEST', 'url': ''} response = self.post('/ag_third_party/add/', data) self.assertEqual(response.code, 200) self.assertIn('Survey URL</label>\n\n<ul class="errors"><li>' 'Required field', response.body)
def test_get_access_levels_user(self): obs = db.get_access_levels_user('test') self.assertEqual(obs, []) db.alter_access_levels('test', [1, 6]) obs = db.get_access_levels_user('test') self.assertEqual(obs, [[1, 'Barcodes'], [6, 'Search']]) db.alter_access_levels('test', []) obs = db.get_access_levels_user('test') self.assertEqual(obs, [])
def test_post_not_logged_barcode(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_not_logged) self.assertEqual(response.code, 200) # I believe this is correct: the sample is marked as received, as well # as status such as moldy/etc but there is no consent or tie sample # site. This _should_ trigger an email self.assertIn("Barcode %s general details updated" % self.not_logged, response.body)
def test_post_missing_data(self): self.mock_login() db.alter_access_levels('test', [4]) data = {'seperator': 'comma', 'survey_id': 'SubjectId', 'trim': ''} files = {'file_in': self.ext_survey_fp} response = self.multipart_post('/ag_third_party/data/', data, files) self.assertEqual(response.code, 200) self.assertIn('Third Party survey</label>\n\n<ul class="errors">' '<li>Not a valid choice', response.body) db._clear_table('external_survey_answers', 'ag')
def test_get_access_levels_user(self): obs = db.get_access_levels_user("test") self.assertEqual(obs, []) db.alter_access_levels("test", [1, 6]) obs = db.get_access_levels_user("test") self.assertEqual(obs, [[1, "Barcodes"], [6, "Search"]]) db.alter_access_levels("test", []) obs = db.get_access_levels_user("test") self.assertEqual(obs, [])
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 post(self): msg = "Access levels updated" access_levels = [int(x) for x in self.get_arguments("levels")] user = self.get_argument("user") try: db.alter_access_levels(user, access_levels) except Exception as e: msg = "ERROR: %s" % str(e) all_levels = db.get_access_levels() user_levels = db.get_access_levels_user(user) users = db.get_users() self.render("edit_user.html", all_levels=all_levels, user_levels=user_levels, users=users, user=user, msg=msg)
def test_post_data(self): self.mock_login_admin() db.alter_access_levels('test', [4]) data = {'name': ''.join([choice(ascii_letters) for x in range(15)]), 'description': 'TEST', 'url': 'test.fake'} response = self.post('/ag_third_party/add/', data) self.assertEqual(response.code, 200) self.assertIn("Added '%s' successfully" % data['name'], response.body) # roll back change to the DB self._clean_up_funcs.append(partial( db.ut_remove_external_survey, **data))
def test_get_enviro_barcode(self): self.mock_login() db.alter_access_levels("test", [3]) response = self.get("/barcode_util/", {"barcode": self.ag_enviro}) self.assertEqual(response.code, 200) self.assertIn('<input id="barcode" name="barcode" type="text" ' 'onclick="this.select()" />', response.body) self.assertIn( '<input class="checkbox" type="checkbox" name=' '"sample_issue" id="overloaded" value="overloaded" }/>', response.body, ) self.assertIn("Project type: American Gut", response.body) self.assertIn("All good", 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, ) self.assertIn("Project type: UNKNOWN", response.body) self.assertIn("Barcode Info is correct", response.body)
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 test_post_existing_survey(self): self.mock_login_admin() db.alter_access_levels('test', [4]) data = {'name': 'Vioscreen', 'description': 'TEST', 'url': 'test.fake'} # adding survey in for the first time response = self.post('/ag_third_party/add/', data) # trying the second time response = self.post('/ag_third_party/add/', data) self.assertEqual(response.code, 200) self.assertIn("Survey 'Vioscreen' already exists", response.body) # roll back change to the DB self._clean_up_funcs.append( partial(db.ut_remove_external_survey, **data))
def test_get_handout_barcode(self): self.mock_login() db.alter_access_levels("test", [3]) response = self.get("/barcode_util/", {"barcode": self.ag_handout}) 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, ) self.assertIn("Project type: American Gut", response.body) self.assertIn("Cannot retrieve metadata: Unassigned handout kit " "barcode", response.body)
def post(self): msg = 'Access levels updated' access_levels = [int(x) for x in self.get_arguments('levels')] user = self.get_argument('user') try: db.alter_access_levels(user, access_levels) except Exception as e: msg = 'ERROR: %s' % str(e) all_levels = db.get_access_levels() user_levels = db.get_access_levels_user(user) users = db.get_users() self.render('edit_user.html', all_levels=all_levels, user_levels=user_levels, users=users, user=user, msg=msg)
def test_post_data(self): self.mock_login_admin() db.alter_access_levels('test', [4]) data = { 'name': ''.join([choice(ascii_letters) for x in range(15)]), 'description': 'TEST', 'url': 'test.fake' } response = self.post('/ag_third_party/add/', data) self.assertEqual(response.code, 200) self.assertIn("Added '%s' successfully" % data['name'], response.body) # roll back change to the DB self._clean_up_funcs.append( partial(db.ut_remove_external_survey, **data))
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) self.assertIn('Project type: UNKNOWN', response.body) self.assertIn('Barcode Info is correct', response.body)
def test_post_existing_survey(self): self.mock_login_admin() db.alter_access_levels('test', [4]) data = {'name': 'Vioscreen', 'description': 'TEST', 'url': 'test.fake'} # adding survey in for the first time response = self.post('/ag_third_party/add/', data) # trying the second time response = self.post('/ag_third_party/add/', data) self.assertEqual(response.code, 200) self.assertIn("Survey 'Vioscreen' already exists", response.body) # roll back change to the DB self._clean_up_funcs.append(partial( db.ut_remove_external_survey, **data))
def test_get_enviro_barcode(self): self.mock_login() db.alter_access_levels('test', [3]) response = self.get('/barcode_util/', {'barcode': self.ag_enviro}) self.assertEqual(response.code, 200) self.assertIn( '<input id="barcode" name="barcode" type="text" ' 'onclick="this.select()" />', response.body) self.assertIn( '<input class="checkbox" type="checkbox" name=' '"sample_issue" id="overloaded" value="overloaded" }/>', response.body) self.assertIn('Project type: American Gut', response.body) self.assertIn('All good', response.body)
def test_get_ag_barcode(self): self.mock_login() db.alter_access_levels('test', [3]) response = self.get('/barcode_util/', {'barcode': self.ag_good}) self.assertEqual(response.code, 200) self.assertIn( '<input id="barcode" name="barcode" type="text" ' 'onclick="this.select()" />', response.body) self.assertIn('<input class="checkbox" type="checkbox" name=' '"sample_issue" id="overloaded" value="overloaded" }/>', response.body) self.assertIn('Project type: American Gut', response.body) self.assertIn('All good', response.body)
def test_get_unlogged_barcode(self): self.mock_login() db.alter_access_levels('test', [3]) response = self.get('/barcode_util/', {'barcode': self.ag_unlogged}) 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) self.assertIn('Project type: American Gut', response.body) self.assertIn('Cannot retrieve metadata: Unassigned handout kit ' 'barcode', response.body)
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_post_data(self): self.mock_login() db.alter_access_levels('test', [4]) data = {'survey': 'Vioscreen', 'seperator': 'comma', 'survey_id': 'SubjectId', 'trim': '-160'} files = {'file_in': self.ext_survey_fp} response = self.multipart_post('/ag_third_party/data/', data, files) self.assertEqual(response.code, 200) self.assertIn("3 surveys added to 'Vioscreen' successfully", response.body) # Grab one of the inserted surveys for testing obs = db.get_external_survey('Vioscreen', ['14f508185c954721']) self.assertTrue(len(obs['14f508185c954721']) == 274) self.assertIn('HEI2010_Greens_Beans', obs['14f508185c954721'].keys()) db._clear_table('external_survey_answers', 'ag')
def test_get_handout_barcode(self): self.mock_login() db.alter_access_levels('test', [3]) response = self.get('/barcode_util/', {'barcode': self.ag_handout}) 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) self.assertIn('Project type: American Gut', response.body) self.assertIn( 'Cannot retrieve metadata: Unassigned handout kit ' 'barcode', response.body)
def test_post_missing_data(self): self.mock_login() db.alter_access_levels('test', [4]) data = {'seperator': 'comma', 'survey_id': 'SubjectId', 'trim': ''} files = {'file_in': self.ext_survey_fp} response = self.post('/ag_third_party/add/', self.data_vioscreen) response = self.multipart_post('/ag_third_party/data/', data, files) self.assertEqual(response.code, 200) self.assertIn('Third Party survey</label>\n\n<ul class="errors">' '<li>Not a valid choice', response.body) # roll back change to the DB self._clean_up_funcs.append(partial( db._clear_table, 'external_survey_answers', 'ag')) self._clean_up_funcs.append(partial( db.ut_remove_external_survey, **self.data_vioscreen))
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_post(self): self.mock_login_admin() response = self.post('/admin/edit/', {'user': '******', 'levels': [6, 7]}) self.assertEqual(response.code, 200) self.assertIn('Update groups', response.body) obs = db.get_access_levels_user('test') self.assertEqual(sorted(obs), [[6, 'Search'], [7, 'Admin']]) # test raising exception user = '******' db.alter_access_levels('test', [4]) response = self.post('/admin/edit/', {'user': user, 'levels': [7]}) self.assertEqual(response.code, 403) self.assertRaises(HTTPError) self.assertIn(('HTTPError: HTTP 403: Forbidden (User %s does not have ' 'access level Admin)') % 'test', response.body)
def test_post_missing_data(self): self.mock_login() db.alter_access_levels('test', [4]) data = {'seperator': 'comma', 'survey_id': 'SubjectId', 'trim': ''} files = {'file_in': self.ext_survey_fp} response = self.post('/ag_third_party/add/', self.data_vioscreen) response = self.multipart_post('/ag_third_party/data/', data, files) self.assertEqual(response.code, 200) self.assertIn( 'Third Party survey</label>\n\n<ul class="errors">' '<li>Not a valid choice', response.body) # roll back change to the DB self._clean_up_funcs.append( partial(db._clear_table, 'external_survey_answers', 'ag')) self._clean_up_funcs.append( partial(db.ut_remove_external_survey, **self.data_vioscreen))
def test_post(self): self.mock_login_admin() response = self.post('/admin/edit/', { 'user': '******', 'levels': [6, 7] }) self.assertEqual(response.code, 200) self.assertIn('Update groups', response.body) obs = db.get_access_levels_user('test') self.assertEqual(sorted(obs), [[6, 'Search'], [7, 'Admin']]) # test raising exception user = '******' db.alter_access_levels('test', [4]) response = self.post('/admin/edit/', {'user': user, 'levels': [7]}) self.assertEqual(response.code, 403) self.assertRaises(HTTPError) self.assertIn(('HTTPError: HTTP 403: Forbidden (User %s does not have ' 'access level Admin)') % 'test', response.body)
def test_get_access_levels_user(self): # insert a fresh new user into DB. email = '*****@*****.**' password = ('$2a$10$2.6Y9HmBqUFmSvKCjWmBte70' 'WF.zd3h4VqbhLMQK1xP67Aj3rei86') sql = """INSERT INTO ag.labadmin_users (email, password) VALUES (%s, %s)""" db._con.execute(sql, [email, password]) obs = db.get_access_levels_user(email) self.assertItemsEqual(obs, []) db.alter_access_levels(email, [1, 6]) obs = db.get_access_levels_user(email) self.assertItemsEqual(obs, [[1, 'Barcodes'], [6, 'Search']]) db.alter_access_levels(email, []) obs = db.get_access_levels_user(email) self.assertItemsEqual(obs, []) # Remove test user from DB. sql = """DELETE FROM ag.labadmin_users WHERE email=%s""" db._con.execute(sql, [email])
def tearDown(self): BaseHandler.get_current_user = self.orig_func # Remove all access privileges user may hve been given by a test db.alter_access_levels('test', []) super(TestHandlerBase, self).tearDown()
def mock_login_admin(self): db.alter_access_levels('test', [7]) self.mock_login()
def test_get_not_logged_in(self): db.alter_access_levels('test', [4]) response = self.get('/ag_third_party/data/') self.assertEqual(response.code, 200) self.assertTrue(response.effective_url.endswith( '?next=%2Fag_third_party%2Fdata%2F'))
def test_build_email(self): db.alter_access_levels('test', [3]) self.mock_login() subject, body = BarcodeUtilHelper()._build_email( u'persøn', '000001018', '0', '2016-12-14', '6:52 pm') self.assertEqual( subject, 'ACTION REQUIRED - Assign your samples in American Gut') self.assertEqual( body, u""" Dear persøn, We have recently received your sample barcode: 000001018, but we cannot process your sample until the following steps have been completed online. Please ensure that you have completed both steps outlined below: 1. Submit your consent form and survey Consent and survey depend on sample type. For human samples, the consent form is mandatory. Even if you elect not to answer the questions on the survey, please click through and submit the survey in order to ensure we receive your completed consent form. For pet samples, we ask that you fill out a short survey. No consent form is necessary. For environmental samples, the consent form and survey are not necessary. To begin the consent/survey process: * Click on the "Add Source Survey" tab on the main page. * Select the appropriate category (human, animal, or environmental) for your sample. 2. Associate your sample(s) with your survey(s) This step is important as it connects your consent form to your sample. We cannot legally work with your sample until this step has been completed. For human and pet samples, the survey must be completed before doing this step. To associate your sample with your survey: * Log into your account and click the "Associate/Log Sample" button at the bottom of the left-hand navigation menu. This will bring you to a screen with the heading "Choose your sample source". * Click on the name of the participant that the sample belongs to. * Fill out the required fields and submit. The American Gut participant website is located at https://microbio.me/americangut The British Gut participant website is located at https://microbio.me/britishgut If you have any questions, please contact us at [email protected]. Thank you, American Gut Team """) subject, body = BarcodeUtilHelper()._build_email( u'persøn', '000001018', '1', '2016-12-14', '6:52 pm') self.assertEqual( subject, 'American Gut Sample with Barcode 000001018 is Received.') self.assertEqual( body, u""" Dear persøn, We have recently received your sample with barcode 000001018 dated 2016-12-14 6:52 pm and we have begun processing it. Please see our FAQ section for when you can expect results. (https://microbio.me/AmericanGut/faq/#faq4) Thank you for your participation! --American Gut Team-- """) with self.assertRaises(RuntimeError): BarcodeUtilHelper()._build_email(u'persøn', '000001018', 'UNKNOWN', '2016-12-14', '6:52 pm')
def test_build_email(self): db.alter_access_levels('test', [3]) self.mock_login() subject, body = BarcodeUtilHelper()._build_email( u'persøn', '000001018', '0', '2016-12-14', '6:52 pm') self.assertEqual( subject, 'ACTION REQUIRED - Assign your samples in American Gut') self.assertEqual( body, u""" <html> <body> <p>Dear persøn,</p> <p>We have recently received your sample barcode: 000001018, but we cannot process your sample until the following steps have been completed online. Please ensure that you have completed <b>both</b> steps outlined below:</p> <ol> <li><b>Submit your consent form and survey-<i>if you have already done these please proceed to step 2 below.</i></b><br/>For human samples, the consent form is mandatory. Even if you elect not to answer the questions on the survey, please click through and submit the survey in order to ensure we receive your completed consent form.</li> <li><b>Assign your sample(s) to your survey(s)</b><br/>This step is critical as it connects your consent form to your sample. We cannot legally work with your sample until this step has been completed.</li> </ol> <p>To assign your sample to your survey:</p> <ul> <li>Log into your account and click the "Assign" button at the bottom of the left-hand navigation menu. This will bring you to a screen with the heading "Choose your sample source".</li> <li>Click on the name of the participant that the sample belongs to.</li> <li>Fill out the required fields and submit.</li> </ul> <p> The American Gut participant website is located at<br/> <a href='https://microbio.me/americangut'>https://microbio.me/americangut</a> <br/>The British Gut participant website is located at<br/> <a href='https://microbio.me/britishgut'>https://microbio.me/britishgut</a> <br/>If you have any questions, please contact us at <a href='mailto:[email protected]'>[email protected]</a>.</p> <p>Thank you,<br/> American Gut Team</p> </body> </html>""") subject, body = BarcodeUtilHelper()._build_email( u'persøn', '000001018', '1', '2016-12-14', '6:52 pm') self.assertEqual( subject, 'American Gut Sample with Barcode 000001018 is Received.') self.assertEqual( body, u"""<html><body><p> Dear persøn,</p> <p>We have recently received your sample with barcode 000001018 dated 2016-12-14 6:52 pm and we have begun processing it. Please see our FAQ section for when you can expect results.<br/> (<a href='https://microbio.me/AmericanGut/faq/#faq4' >https://microbio.me/AmericanGut/faq/#faq4</a>)</p> <p>Thank you for your participation!</p> <p>--American Gut Team--</p></body></html> """) with self.assertRaises(RuntimeError): BarcodeUtilHelper()._build_email(u'persøn', '000001018', 'UNKNOWN', '2016-12-14', '6:52 pm')
def test_build_email(self): db.alter_access_levels("test", [3]) self.mock_login() subject, body = BarcodeUtilHelper()._build_email(u"persøn", "000001018", "0", "2016-12-14", "6:52 pm") self.assertEqual(subject, "ACTION REQUIRED - Assign your samples in American Gut") self.assertEqual( body, u""" <html> <body> <p>Dear persøn,</p> <p>We have recently received your sample barcode: 000001018, but we cannot process your sample until the following steps have been completed online. Please ensure that you have completed <b>both</b> steps outlined below:</p> <ol> <li><b>Submit your consent form and survey-<i>if you have already done these please proceed to step 2 below.</i></b><br/>For human samples, the consent form is mandatory. Even if you elect not to answer the questions on the survey, please click through and submit the survey in order to ensure we receive your completed consent form.</li> <li><b>Assign your sample(s) to your survey(s)</b><br/>This step is critical as it connects your consent form to your sample. We cannot legally work with your sample until this step has been completed.</li> </ol> <p>To assign your sample to your survey:</p> <ul> <li>Log into your account and click the "Assign" button at the bottom of the left-hand navigation menu. This will bring you to a screen with the heading "Choose your sample source".</li> <li>Click on the name of the participant that the sample belongs to.</li> <li>Fill out the required fields and submit.</li> </ul> <p> The American Gut participant website is located at<br/> <a href='https://microbio.me/americangut'>https://microbio.me/americangut</a> <br/>The British Gut participant website is located at<br/> <a href='https://microbio.me/britishgut'>https://microbio.me/britishgut</a> <br/>If you have any questions, please contact us at <a href='mailto:[email protected]'>[email protected]</a>.</p> <p>Thank you,<br/> American Gut Team</p> </body> </html>""", ) subject, body = BarcodeUtilHelper()._build_email(u"persøn", "000001018", "1", "2016-12-14", "6:52 pm") self.assertEqual(subject, "American Gut Sample with Barcode 000001018 is Received.") self.assertEqual( body, u"""<html><body><p> Dear persøn,</p> <p>We have recently received your sample with barcode 000001018 dated 2016-12-14 6:52 pm and we have begun processing it. Please see our FAQ section for when you can expect results.<br/> (<a href='https://microbio.me/AmericanGut/faq/#faq4' >https://microbio.me/AmericanGut/faq/#faq4</a>)</p> <p>Thank you for your participation!</p> <p>--American Gut Team--</p></body></html> """, ) with self.assertRaises(RuntimeError): BarcodeUtilHelper()._build_email(u"persøn", "000001018", "UNKNOWN", "2016-12-14", "6:52 pm")
def test_post_not_logged_in(self): db.alter_access_levels('test', [3]) response = self.post('/barcode_util/', self.data) self.assertEqual(response.code, 403)
def test_get_not_logged_in(self): db.alter_access_levels("test", [3]) response = self.get("/barcode_util/") self.assertEqual(response.code, 200) self.assertTrue(response.effective_url.endswith("?next=%2Fbarcode_util%2F"))
def test_get_not_logged_in(self): db.alter_access_levels('test', [3]) response = self.get('/barcode_util/') self.assertEqual(response.code, 200) self.assertTrue( response.effective_url.endswith('?next=%2Fbarcode_util%2F'))