From 7918c02bbfe17b3464e56fd67334727cbce6ca51 Mon Sep 17 00:00:00 2001 From: Antonio Gonzalez Date: Fri, 22 Feb 2019 11:13:27 -0700 Subject: [PATCH 1/4] initial changes --- .../test/test_prep_template.py | 2 +- qiita_db/portal.py | 2 +- .../tests/test_base_handlers.py | 2 +- qiita_pet/handlers/api_proxy/prep_template.py | 2 +- .../handlers/api_proxy/tests/test_artifact.py | 18 +++---- .../api_proxy/tests/test_prep_template.py | 35 +++++++------ .../api_proxy/tests/test_processing.py | 2 +- .../tests/test_base_handlers.py | 3 +- qiita_pet/handlers/rest/study_preparation.py | 4 +- .../handlers/study_handlers/edit_handlers.py | 50 +++++++++---------- .../study_handlers/listing_handlers.py | 3 +- .../study_handlers/tests/test_base.py | 7 +-- .../tests/test_edit_handlers.py | 6 +-- .../tests/test_listing_handlers.py | 10 ++-- .../tests/test_sample_template.py | 4 +- qiita_pet/handlers/upload.py | 2 +- .../study_ajax/sample_prep_summary.html | 2 +- qiita_pet/test/test_auth_handlers.py | 4 +- qiita_pet/test/test_base_handlers.py | 4 +- qiita_pet/test/test_download.py | 30 ++++++----- qiita_pet/test/test_portal.py | 2 +- qiita_pet/test/test_prep_template.py | 2 +- qiita_pet/test/test_upload.py | 10 ++-- 23 files changed, 107 insertions(+), 99 deletions(-) diff --git a/qiita_db/metadata_template/test/test_prep_template.py b/qiita_db/metadata_template/test/test_prep_template.py index 5edb67ade..9b6c46aeb 100644 --- a/qiita_db/metadata_template/test/test_prep_template.py +++ b/qiita_db/metadata_template/test/test_prep_template.py @@ -1204,7 +1204,7 @@ def test_qiime_map_fp(self): pt = qdb.metadata_template.prep_template.PrepTemplate(1) exp = join(qdb.util.get_mountpoint('templates')[0][1], '1_prep_1_qiime_[0-9]*-[0-9]*.txt') - self.assertRegexpMatches(pt.qiime_map_fp, exp) + self.assertRegex(pt.qiime_map_fp, exp) def test_check_restrictions(self): obs = self.tester.check_restrictions( diff --git a/qiita_db/portal.py b/qiita_db/portal.py index 8ddebad65..d9cb5ae55 100644 --- a/qiita_db/portal.py +++ b/qiita_db/portal.py @@ -213,7 +213,7 @@ def _check_studies(self, studies): sql = "SELECT study_id FROM qiita.study WHERE study_id IN %s" qdb.sql_connection.TRN.add(sql, [tuple(studies)]) existing = qdb.sql_connection.TRN.execute_fetchflatten() - if len(existing) != len(studies): + if len(existing) != len(list(studies)): bad = map(str, set(studies).difference(existing)) raise qdb.exceptions.QiitaDBError( "The following studies do not exist: %s" % ", ".join(bad)) diff --git a/qiita_pet/handlers/analysis_handlers/tests/test_base_handlers.py b/qiita_pet/handlers/analysis_handlers/tests/test_base_handlers.py index 0139852d9..3b7d6496d 100644 --- a/qiita_pet/handlers/analysis_handlers/tests/test_base_handlers.py +++ b/qiita_pet/handlers/analysis_handlers/tests/test_base_handlers.py @@ -111,7 +111,7 @@ def test_post_create_analysis_handler(self): args = {'name': 'New Test Analysis', 'description': 'Test Analysis Description'} response = self.post('/analysis/create/', args) - self.assertRegexpMatches( + self.assertRegex( response.effective_url, r"http://localhost:\d+/analysis/description/\d+/") self.assertEqual(response.code, 200) diff --git a/qiita_pet/handlers/api_proxy/prep_template.py b/qiita_pet/handlers/api_proxy/prep_template.py index 99adf4195..4a903ad84 100644 --- a/qiita_pet/handlers/api_proxy/prep_template.py +++ b/qiita_pet/handlers/api_proxy/prep_template.py @@ -372,7 +372,7 @@ def prep_template_post_req(study_id, user_id, prep_template, data_type, # join all the warning messages into one. Note that this info # will be ignored if an exception is raised if warns: - msg = '\n'.join(set(str(w) for w in warns)) + msg = '\n'.join(set(str(w.message) for w in warns)) status = 'warning' except Exception as e: # Some error occurred while processing the prep template diff --git a/qiita_pet/handlers/api_proxy/tests/test_artifact.py b/qiita_pet/handlers/api_proxy/tests/test_artifact.py index 2e1ace0cc..096365691 100644 --- a/qiita_pet/handlers/api_proxy/tests/test_artifact.py +++ b/qiita_pet/handlers/api_proxy/tests/test_artifact.py @@ -207,15 +207,15 @@ def test_artifact_patch_request_errors(self): def test_artifact_get_prep_req(self): obs = artifact_get_prep_req('test@foo.bar', [4]) exp = {'status': 'success', 'msg': '', 'data': { - 4: ['1.SKB2.640194', '1.SKM4.640180', '1.SKB3.640195', - '1.SKB6.640176', '1.SKD6.640190', '1.SKM6.640187', - '1.SKD9.640182', '1.SKM8.640201', '1.SKM2.640199', - '1.SKD2.640178', '1.SKB7.640196', '1.SKD4.640185', - '1.SKB8.640193', '1.SKM3.640197', '1.SKD5.640186', - '1.SKB1.640202', '1.SKM1.640183', '1.SKD1.640179', - '1.SKD3.640198', '1.SKB5.640181', '1.SKB4.640189', - '1.SKB9.640200', '1.SKM9.640192', '1.SKD8.640184', - '1.SKM5.640177', '1.SKM7.640188', '1.SKD7.640191']}} + 4: ['1.SKB1.640202', '1.SKB2.640194', '1.SKB3.640195', + '1.SKB4.640189', '1.SKB5.640181', '1.SKB6.640176', + '1.SKB7.640196', '1.SKB8.640193', '1.SKB9.640200', + '1.SKD1.640179', '1.SKD2.640178', '1.SKD3.640198', + '1.SKD4.640185', '1.SKD5.640186', '1.SKD6.640190', + '1.SKD7.640191', '1.SKD8.640184', '1.SKD9.640182', + '1.SKM1.640183', '1.SKM2.640199', '1.SKM3.640197', + '1.SKM4.640180', '1.SKM5.640177', '1.SKM6.640187', + '1.SKM7.640188', '1.SKM8.640201', '1.SKM9.640192']}} self.assertEqual(obs, exp) obs = artifact_get_prep_req('demo@microbio.me', [4]) diff --git a/qiita_pet/handlers/api_proxy/tests/test_prep_template.py b/qiita_pet/handlers/api_proxy/tests/test_prep_template.py index aa75fec0b..5a6d46749 100644 --- a/qiita_pet/handlers/api_proxy/tests/test_prep_template.py +++ b/qiita_pet/handlers/api_proxy/tests/test_prep_template.py @@ -119,7 +119,7 @@ def test_prep_template_get_req(self): list(obs.keys()), ['status', 'message', 'template']) self.assertEqual(obs['status'], 'success') self.assertEqual(obs['message'], '') - self.assertEqual(obs['template'].keys(), [ + self.assertCountEqual(obs['template'].keys(), [ '1.SKB2.640194', '1.SKM4.640180', '1.SKB3.640195', '1.SKB6.640176', '1.SKD6.640190', '1.SKM6.640187', '1.SKD9.640182', '1.SKM8.640201', '1.SKM2.640199', '1.SKD2.640178', '1.SKB7.640196', '1.SKD4.640185', @@ -404,8 +404,8 @@ def test_prep_template_jobs_get_req(self): self._wait_for_parallel_job('prep_template_%s' % pt.id) obs = prep_template_jobs_get_req(pt.id, 'test@foo.bar') self.assertEqual(len(obs), 1) - self.assertEqual(obs.values(), - [{'error': '', 'status': 'success', 'step': None}]) + self.assertCountEqual( + obs.values(), [{'error': '', 'status': 'success', 'step': None}]) obs = prep_template_jobs_get_req(pt.id, 'demo@microbio.me') exp = {'status': 'error', @@ -435,21 +435,20 @@ def test_prep_template_post_req(self): '16S', name=" ") exp = {'status': 'warning', 'message': [ - ('Some columns required to generate a QIIME-compliant ' - 'mapping file are not present in the template. A ' - 'placeholder value (XXQIITAXX) has been used to populate ' - 'these columns. Missing columns: BarcodeSequence, ' - 'LinkerPrimerSequence'), - ('Some functionality will be disabled due to missing ' - 'columns:'), - ('\tDemultiplexing with multiple input files disabled.: ' - 'barcode, primer, run_prefix;'), - '\tDemultiplexing disabled.: barcode;', - ('\tEBI submission disabled: center_name, ' - 'experiment_design_description, instrument_model, ' - 'library_construction_protocol, platform.'), - ('See the Templates tutorial for a description of these ' - 'fields.')], + 'Both a converter and dtype were specified for column ' + 'sample_name - only the converter will be used', 'Some ' + 'functionality will be disabled due to missing columns:', + '\tEBI submission disabled: center_name, ' + 'experiment_design_description, instrument_model, ' + 'library_construction_protocol, platform;', + '\tDemultiplexing disabled.: barcode;', '\tDemultiplexing ' + 'with multiple input files disabled.: barcode, primer, ' + 'run_prefix.', 'See the Templates tutorial for a ' + 'description of these fields.', 'Some columns required to ' + 'generate a QIIME-compliant mapping file are not present ' + 'in the template. A placeholder value (XXQIITAXX) ' + 'has been used to populate these columns. Missing columns: ' + 'BarcodeSequence, LinkerPrimerSequence'], 'file': 'update.txt', 'id': 'ignored in test'} diff --git a/qiita_pet/handlers/api_proxy/tests/test_processing.py b/qiita_pet/handlers/api_proxy/tests/test_processing.py index ad1e70d72..93e98602b 100644 --- a/qiita_pet/handlers/api_proxy/tests/test_processing.py +++ b/qiita_pet/handlers/api_proxy/tests/test_processing.py @@ -114,7 +114,7 @@ def test_workflow_handler_post_req(self): '"rev_comp_mapping_barcodes": false, ' '"min_per_read_length_fraction": 0.75, "sequence_max_n": 0}') obs = workflow_handler_post_req("test@foo.bar", 1, params) - self.assertRegexpMatches( + self.assertRegex( obs.pop('message'), 'Cannot create job because the parameters are ' 'the same as jobs that are queued, running or already have ' 'succeeded:\n') diff --git a/qiita_pet/handlers/artifact_handlers/tests/test_base_handlers.py b/qiita_pet/handlers/artifact_handlers/tests/test_base_handlers.py index 06df9fcdc..da4a27ad1 100644 --- a/qiita_pet/handlers/artifact_handlers/tests/test_base_handlers.py +++ b/qiita_pet/handlers/artifact_handlers/tests/test_base_handlers.py @@ -393,7 +393,8 @@ def test_get_artifact_summary_handler(self): summary = relpath(a.html_summary_fp[1], qiita_config.base_data_dir) response = self.get('/artifact/html_summary/%s' % summary) self.assertEqual(response.code, 200) - self.assertEqual(response.body, 'HTML TEST - not important\n') + self.assertEqual(response.body.decode('ascii'), + 'HTML TEST - not important\n') if __name__ == '__main__': diff --git a/qiita_pet/handlers/rest/study_preparation.py b/qiita_pet/handlers/rest/study_preparation.py index 02d9c5f1b..0afc1702a 100644 --- a/qiita_pet/handlers/rest/study_preparation.py +++ b/qiita_pet/handlers/rest/study_preparation.py @@ -41,7 +41,7 @@ def post(self, study_id, *args, **kwargs): p = PrepTemplate.create(data, study_id, data_type, investigation_type) except QiitaError as e: - self.fail(e.message, 406) + self.fail(str(e), 406) return self.write({'id': p.id}) @@ -80,7 +80,7 @@ def post(self, study_id, prep_id): artifact_deets['artifact_name'], p) except QiitaError as e: - self.fail(e.message, 406) + self.fail(str(e), 406) return self.write({'id': art.id}) diff --git a/qiita_pet/handlers/study_handlers/edit_handlers.py b/qiita_pet/handlers/study_handlers/edit_handlers.py index babf137ad..dfafbd113 100644 --- a/qiita_pet/handlers/study_handlers/edit_handlers.py +++ b/qiita_pet/handlers/study_handlers/edit_handlers.py @@ -70,9 +70,7 @@ def __init__(self, study=None, **kwargs): # Get people from the study_person table to populate the PI and # lab_person fields - choices = [(sp.id, u"%s, %s" - % (sp.name.decode('utf-8'), - sp.affiliation.decode('utf-8'))) + choices = [(sp.id, u"%s, %s" % (sp.name, sp.affiliation)) for sp in StudyPerson.iter()] choices.insert(0, ('', '')) @@ -83,8 +81,8 @@ def __init__(self, study=None, **kwargs): if study: study_info = study.info - self.study_title.data = study.title.decode('utf-8') - self.study_alias.data = study_info['study_alias'].decode('utf-8') + self.study_title.data = study.title + self.study_alias.data = study_info['study_alias'] dois = [] pids = [] for p, is_doi in study.publications: @@ -92,12 +90,10 @@ def __init__(self, study=None, **kwargs): dois.append(p) else: pids.append(p) - self.publication_doi.data = ",".join(dois).decode('utf-8') - self.publication_pid.data = ",".join(pids).decode('utf-8') - self.study_abstract.data = study_info[ - 'study_abstract'].decode('utf-8') - self.study_description.data = study_info[ - 'study_description'].decode('utf-8') + self.publication_doi.data = ",".join(dois) + self.publication_pid.data = ",".join(pids) + self.study_abstract.data = study_info['study_abstract'] + self.study_description.data = study_info['study_description'] self.principal_investigator.data = study_info[ 'principal_investigator'].id self.lab_person.data = (study_info['lab_person'].id @@ -254,19 +250,20 @@ def post(self, study=None): lab_person = None # TODO: MIXS compliant? Always true, right? + fd = form_data.data info = { 'lab_person_id': lab_person, 'principal_investigator_id': PI, 'metadata_complete': False, 'mixs_compliant': True, - 'study_description': form_data.data['study_description'][0], - 'study_alias': form_data.data['study_alias'][0], - 'study_abstract': form_data.data['study_abstract'][0]} + 'study_description': fd['study_description'][0].decode('utf-8'), + 'study_alias': fd['study_alias'][0].decode('utf-8'), + 'study_abstract': fd['study_abstract'][0].decode('utf-8')} - if 'timeseries' in form_data.data and form_data.data['timeseries']: - info['timeseries_type_id'] = form_data.data['timeseries'][0] + if 'timeseries' in fd and fd['timeseries']: + info['timeseries_type_id'] = fd['timeseries'][0].decode('utf-8') - study_title = form_data.data['study_title'][0] + study_title = fd['study_title'][0].decode('utf-8') if the_study: # We are under editing, so just update the values @@ -275,8 +272,7 @@ def post(self, study=None): msg = ('Study %s ' 'successfully updated' % - (qiita_config.portal_dir, the_study.id, - form_data.data['study_title'][0])) + (qiita_config.portal_dir, the_study.id, study_title)) else: # create the study # TODO: Fix this EFO once ontology stuff from emily is added @@ -284,26 +280,26 @@ def post(self, study=None): msg = ('Study %s ' 'successfully created' % - (qiita_config.portal_dir, the_study.id, - form_data.data['study_title'][0])) + (qiita_config.portal_dir, the_study.id, study_title)) # Add the environmental packages, this attribute can only be edited # if the study is not public, otherwise this cannot be changed if isinstance(form_data, StudyEditorExtendedForm): - the_study.environmental_packages = form_data.data[ - 'environmental_packages'] + vals = [ + eval(v).decode('utf-8') for v in fd['environmental_packages']] + the_study.environmental_packages = vals pubs = [] - dois = form_data.data['publication_doi'] + dois = fd['publication_doi'] if dois and dois[0]: # The user can provide a comma-seprated list - dois = dois[0].split(',') + dois = dois[0].decode('utf-8').split(',') # Make sure that we strip the spaces from the pubmed ids pubs.extend([(doi.strip(), True) for doi in dois]) - pids = form_data.data['publication_pid'] + pids = fd['publication_pid'] if pids and pids[0]: # The user can provide a comma-seprated list - pids = pids[0].split(',') + pids = pids[0].decode('utf-8').split(',') # Make sure that we strip the spaces from the pubmed ids pubs.extend([(pid.strip(), False) for pid in pids]) the_study.publications = pubs diff --git a/qiita_pet/handlers/study_handlers/listing_handlers.py b/qiita_pet/handlers/study_handlers/listing_handlers.py index da554018c..e1c0d3543 100644 --- a/qiita_pet/handlers/study_handlers/listing_handlers.py +++ b/qiita_pet/handlers/study_handlers/listing_handlers.py @@ -62,7 +62,8 @@ def get(self): text = self.get_argument('text') vals = r_client.execute_command('zrangebylex', 'qiita-usernames', u'[%s' % text, u'[%s\xff' % text) - self.write({'results': [{'id': s, 'text': s} for s in vals]}) + self.write({'results': [{'id': s.decode('utf-8'), + 'text': s.decode('utf-8')} for s in vals]}) class ShareStudyAJAX(BaseHandler): diff --git a/qiita_pet/handlers/study_handlers/tests/test_base.py b/qiita_pet/handlers/study_handlers/tests/test_base.py index c1a9f8a98..66d84b246 100644 --- a/qiita_pet/handlers/study_handlers/tests/test_base.py +++ b/qiita_pet/handlers/study_handlers/tests/test_base.py @@ -55,7 +55,7 @@ def test_get(self): exp = ('{"status": "success", "message": "", "tags": ' '{"admin": [], "user": []}}') self.assertEqual(response.code, 200) - self.assertEqual(response.body, exp) + self.assertEqual(response.body.decode('ascii'), exp) class TestStudyTags(OauthTestingBase): @@ -63,7 +63,7 @@ def test_get(self): response = self.get('/study/tags/1') exp = ('{"status": "success", "message": "", "tags": []}') self.assertEqual(response.code, 200) - self.assertEqual(response.body, exp) + self.assertEqual(response.body.decode('ascii'), exp) # test error response = self.get('/study/tags/bla') @@ -78,7 +78,8 @@ def test_patch_tags(self): data=arguments, asjson=True) self.assertEqual(obs.code, 200) - self.assertEqual(obs.body, '{"status": "success", "message": ""}') + self.assertEqual(obs.body.decode('ascii'), + '{"status": "success", "message": ""}') # checking the tags were added response = self.get('/study/tags/1') diff --git a/qiita_pet/handlers/study_handlers/tests/test_edit_handlers.py b/qiita_pet/handlers/study_handlers/tests/test_edit_handlers.py index 7a65942fd..fbd137122 100644 --- a/qiita_pet/handlers/study_handlers/tests/test_edit_handlers.py +++ b/qiita_pet/handlers/study_handlers/tests/test_edit_handlers.py @@ -156,12 +156,12 @@ def test_get(self): response = self.get('/check_study/', {'study_title': 'notreal'}) self.assertEqual(response.code, 200) # make sure responds properly - self.assertEqual(response.body, 'True') + self.assertEqual(response.body.decode('ascii'), 'True') response = self.get('/check_study/') self.assertEqual(response.code, 200) # make sure responds properly - self.assertEqual(response.body, 'False') + self.assertEqual(response.body.decode('ascii'), 'False') response = self.get( '/check_study/', @@ -169,7 +169,7 @@ def test_get(self): 'Identification of the Microbiomes for Cannabis Soils'}) self.assertEqual(response.code, 200) # make sure responds properly - self.assertEqual(response.body, 'False') + self.assertEqual(response.body.decode('ascii'), 'False') if __name__ == "__main__": diff --git a/qiita_pet/handlers/study_handlers/tests/test_listing_handlers.py b/qiita_pet/handlers/study_handlers/tests/test_listing_handlers.py index 812b7b6fb..a49ddf89f 100644 --- a/qiita_pet/handlers/study_handlers/tests/test_listing_handlers.py +++ b/qiita_pet/handlers/study_handlers/tests/test_listing_handlers.py @@ -34,25 +34,27 @@ def test_get(self): Artifact(4).visibility = "awaiting_approval" response = self.get('/admin/approval/') self.assertEqual(response.code, 200) - self.assertIn("test@foo.bar", response.body) + self.assertIn("test@foo.bar", response.body.decode('ascii')) class TestAutocompleteHandler(TestHandlerBase): def test_get(self): + base_url = '/study/sharing/autocomplete/?text=%s' + r_client.zadd('qiita-usernames', {e: 0 for e, n in User.iter()}) - response = self.get(self.base_url % 't') + response = self.get(base_url % 't') self.assertEqual(response.code, 200) self.assertEqual(loads(response.body), {'results': [{"id": "test@foo.bar", "text": "test@foo.bar"}]}) - response = self.get(self.base_url % 'admi') + response = self.get(base_url % 'admi') self.assertEqual(response.code, 200) self.assertEqual(loads(response.body), {'results': [{"id": "admin@foo.bar", "text": "admin@foo.bar"}]}) - response = self.get(self.base_url % 'tesq') + response = self.get(base_url % 'tesq') self.assertEqual(response.code, 200) self.assertEqual(loads(response.body), {'results': []}) diff --git a/qiita_pet/handlers/study_handlers/tests/test_sample_template.py b/qiita_pet/handlers/study_handlers/tests/test_sample_template.py index df3740654..015e3f2d0 100644 --- a/qiita_pet/handlers/study_handlers/tests/test_sample_template.py +++ b/qiita_pet/handlers/study_handlers/tests/test_sample_template.py @@ -352,7 +352,7 @@ def test_sample_template_columns_get_req(self): 'winter', 'winter', 'winter', 'winter', 'winter', 'winter', 'winter', 'winter', 'winter', 'winter', 'winter', 'winter', 'winter', 'winter', 'winter'] - self.assertEqual(obs, exp) + self.assertCountEqual(obs, exp) def test_build_sample_summary(self): cols, rows = _build_sample_summary(1, 'test@foo.bar') @@ -530,7 +530,7 @@ def test_get(self): self.assertEqual(res.code, 200) # Make sure metadata read properly line = '' - self.assertIn(line, res.body) + self.assertIn(line, res.body.decode('ascii')) class TestSampleAJAX(TestHandlerBase): diff --git a/qiita_pet/handlers/upload.py b/qiita_pet/handlers/upload.py index e6cd9f4fc..d9542ee4b 100644 --- a/qiita_pet/handlers/upload.py +++ b/qiita_pet/handlers/upload.py @@ -140,7 +140,7 @@ def post(self, study_id): create_nested_path(upload_folder) - with open(ssh_key_fp, 'w') as f: + with open(ssh_key_fp, 'wb') as f: f.write(ssh_key) qiita_plugin = Software.from_name_and_version('Qiita', 'alpha') diff --git a/qiita_pet/templates/study_ajax/sample_prep_summary.html b/qiita_pet/templates/study_ajax/sample_prep_summary.html index efa73517b..3d94bbb04 100644 --- a/qiita_pet/templates/study_ajax/sample_prep_summary.html +++ b/qiita_pet/templates/study_ajax/sample_prep_summary.html @@ -32,7 +32,7 @@ { 'name': '', 'field': 'sample-delete', 'id': 'sample-delete', width: 69, sortable: false, formatter: linkFormatter }, { 'name': 'sample_name', 'field': 'sample', 'id': 'sample_name', width: 200, sortable: true }, - {% for k, v in columns.viewitems() %} + {% for k, v in columns.items() %} { 'name': '{% raw v %}', 'field': '{% raw k %}', 'id': '{% raw k %}', 'width': {{ len(v) }}*column_width_factor, 'sortable': true }, {% end %} ]; diff --git a/qiita_pet/test/test_auth_handlers.py b/qiita_pet/test/test_auth_handlers.py index 273ff9a81..1188c79bd 100644 --- a/qiita_pet/test/test_auth_handlers.py +++ b/qiita_pet/test/test_auth_handlers.py @@ -44,7 +44,7 @@ def test_get(self): self.assertEqual(response.code, 200) # make sure redirect happened properly port = self.get_http_port() - self.assertEqual(response.effective_url, 'http://localhost:%d/' % port) + self.assertEqual(response.effective_url, 'http://127.0.0.1:%d/' % port) def test_post_correct_pass(self): post_args = { @@ -75,7 +75,7 @@ def test_get(self): self.assertEqual(response.code, 200) # make sure redirect happened properly port = self.get_http_port() - self.assertEqual(response.effective_url, 'http://localhost:%d/' % port) + self.assertEqual(response.effective_url, 'http://127.0.0.1:%d/' % port) if __name__ == "__main__": diff --git a/qiita_pet/test/test_base_handlers.py b/qiita_pet/test/test_base_handlers.py index eea63d656..a8df18f07 100644 --- a/qiita_pet/test/test_base_handlers.py +++ b/qiita_pet/test/test_base_handlers.py @@ -26,12 +26,12 @@ class TestIFrame(TestHandlerBase): def test_get(self): response = self.get('/iframe/') self.assertEqual(response.code, 200) - self.assertIn("No content", response.body) + self.assertIn("No content", response.body.decode('ascii')) response = self.get('/iframe/?iframe=qiita-terms') self.assertEqual(response.code, 200) self.assertIn('src="/static/qiita_data_terms_of_use.html"', - response.body) + response.body.decode('ascii')) if __name__ == "__main__": diff --git a/qiita_pet/test/test_download.py b/qiita_pet/test/test_download.py index 3baadaf5a..5984a94d3 100644 --- a/qiita_pet/test/test_download.py +++ b/qiita_pet/test/test_download.py @@ -43,7 +43,7 @@ def test_download(self): # check success response = self.get('/download/1') self.assertEqual(response.code, 200) - self.assertEqual(response.body, ( + self.assertEqual(response.body.decode('ascii'), ( "This installation of Qiita was not equipped with nginx, so it " "is incapable of serving files. The file you attempted to " "download is located at raw_data/1_s_G1_L001_sequences.fastq.gz")) @@ -74,9 +74,9 @@ def test_download(self): fp_name = basename(fp2) dirname = basename(dirpath) - self.assertEqual( - response.body, "- 1 /protected/FASTQ/1/%s/%s FASTQ/1/%s/%s\n" - % (dirname, fp_name, dirname, fp_name)) + self.assertEqual(response.body.decode('ascii'), + "- 1 /protected/FASTQ/1/%s/%s FASTQ/1/%s/%s\n" % ( + dirname, fp_name, dirname, fp_name)) class TestDownloadStudyBIOMSHandler(TestHandlerBase): @@ -114,7 +114,7 @@ def test_download_study(self): files_biom = [(biom_fp, 'biom'), (smr_dir, 'directory'), (tgz, 'tgz')] params = Parameters.from_default_params( - Command(3).default_parameter_sets.next(), {'input_data': 1}) + next(Command(3).default_parameter_sets), {'input_data': 1}) a = Artifact.create(files_biom, "BIOM", parents=[Artifact(2)], processing_parameters=params) for _, fp, _ in a.filepaths: @@ -146,7 +146,7 @@ def test_download_study(self): 'BIOM/{0}/sortmerna_picked_otus/seqs_otus.log\n' '- 36615 /protected/templates/1_prep_1_qiime_[0-9]*-[0-9]*.' 'txt mapping_files/{0}_mapping_file.txt\n'.format(a.id)) - self.assertRegexpMatches(response.body, exp) + self.assertRegex(response.body.decode('ascii'), exp) response = self.get('/download_study_bioms/200') self.assertEqual(response.code, 405) @@ -167,7 +167,7 @@ def test_download_study(self): 'BIOM/{0}/sortmerna_picked_otus/seqs_otus.log\n' '- 36615 /protected/templates/1_prep_1_qiime_[0-9]*-[0-9]*.' 'txt mapping_files/{0}_mapping_file.txt\n'.format(a.id)) - self.assertRegexpMatches(response.body, exp) + self.assertRegex(response.body.decode('ascii'), exp) class TestDownloadRelease(TestHandlerBase): @@ -185,7 +185,7 @@ def test_download(self): self.assertIn( "This installation of Qiita was not equipped with nginx, so it is " "incapable of serving files. The file you attempted to download " - "is located at", response.body) + "is located at", response.body.decode('ascii')) class TestDownloadRawData(TestHandlerBase): @@ -225,7 +225,7 @@ def test_download_raw_data(self): 'mapping_files/1_mapping_file.txt\n' '- 36615 /protected/templates/1_prep_2_qiime_[0-9]*-[0-9]*.txt ' 'mapping_files/7_mapping_file.txt\n') - self.assertRegexpMatches(response.body, exp) + self.assertRegex(response.body.decode('ascii'), exp) response = self.get('/download_study_bioms/200') self.assertEqual(response.code, 405) @@ -253,7 +253,7 @@ def test_download_raw_data(self): exp = ( '- 36615 /protected/templates/1_prep_2_qiime_[0-9]*-[0-9]*.txt ' 'mapping_files/7_mapping_file.txt\n') - self.assertRegexpMatches(response.body, exp) + self.assertRegex(response.body.decode('ascii'), exp) class TestDownloadEBISampleAccessions(TestHandlerBase): @@ -282,7 +282,10 @@ def test_download(self): "1.SKD8.640184\tERS000001\n1.SKM5.640177\tERS000005\n" "1.SKM7.640188\tERS000010\n1.SKD7.640191\tERS000021") self.assertEqual(response.code, 200) - self.assertRegexpMatches(response.body, exp) + # testing as lists so we ignore order + obs = response.body.decode('ascii').split('\n') + exp = exp.split('\n') + self.assertCountEqual(obs, exp) # changing user so we can test the failures BaseHandler.get_current_user = Mock( @@ -317,7 +320,10 @@ def test_download(self): "1.SKD8.640184\tERX0000001\n1.SKM5.640177\tERX0000005\n" "1.SKM7.640188\tERX0000010\n1.SKD7.640191\tERX0000021") self.assertEqual(response.code, 200) - self.assertRegexpMatches(response.body, exp) + # testing as lists so we ignore order + obs = response.body.decode('ascii').split('\n') + exp = exp.split('\n') + self.assertCountEqual(obs, exp) # changing user so we can test the failures BaseHandler.get_current_user = Mock( diff --git a/qiita_pet/test/test_portal.py b/qiita_pet/test/test_portal.py index 8abadedf4..3bed950d0 100644 --- a/qiita_pet/test/test_portal.py +++ b/qiita_pet/test/test_portal.py @@ -69,7 +69,7 @@ def test_get_AJAX(self): self.assertEqual(response.code, 200) exp = "Identification of the Microbiomes for Cannabis Soils" - self.assertIn(exp, response.body) + self.assertIn(exp, response.body.decode('ascii')) def test_get_AJAX_not_valid_user(self): page = '/admin/portals/studiesAJAX/' diff --git a/qiita_pet/test/test_prep_template.py b/qiita_pet/test/test_prep_template.py index 1a30c9a0c..85557680c 100644 --- a/qiita_pet/test/test_prep_template.py +++ b/qiita_pet/test/test_prep_template.py @@ -52,7 +52,7 @@ def test_post_broken_header(self): 'prep-file': 'broke_template.txt'} response = self.post('/prep_template/', arguments) self.assertEqual(response.code, 200) - self.assertIn('broke |col', response.body) + self.assertIn('broke |col', response.body.decode('ascii')) def test_patch(self): arguments = {'op': 'replace', diff --git a/qiita_pet/test/test_upload.py b/qiita_pet/test/test_upload.py index 7ef402e58..d4ee24a36 100644 --- a/qiita_pet/test/test_upload.py +++ b/qiita_pet/test/test_upload.py @@ -55,7 +55,8 @@ def test_post(self): response = self.post( '/study/upload/remote/1', data=body, headers=headers) self.assertEqual(response.code, 200) - self.assertEqual(response.body, '{"status": "success", "message": ""}') + self.assertEqual(response.body.decode('ascii'), + '{"status": "success", "message": ""}') # create a successful list job data = {'remote-request-type': 'transfer', 'inputURL': 'scp-url'} @@ -63,7 +64,8 @@ def test_post(self): response = self.post( '/study/upload/remote/1', data=body, headers=headers) self.assertEqual(response.code, 200) - self.assertEqual(response.body, '{"status": "success", "message": ""}') + self.assertEqual(response.body.decode('ascii'), + '{"status": "success", "message": ""}') # sleep to wait for jobs to finish, no need to check for it's status sleep(5) @@ -73,8 +75,8 @@ def test_post(self): response = self.post( '/study/upload/remote/1', data=body, headers=headers) self.assertEqual(response.code, 200) - self.assertEqual(response.body, '{"status": "error", "message": ' - '"Not a valid method"}') + self.assertEqual(response.body.decode('ascii'), '{"status": "error", ' + '"message": "Not a valid method"}') if __name__ == "__main__": From 0b0e8859d1ea3aa32ee46989e8ecee2406b15457 Mon Sep 17 00:00:00 2001 From: Antonio Gonzalez Date: Fri, 22 Feb 2019 11:15:37 -0700 Subject: [PATCH 2/4] self.assertRaisesRegexp -> self.assertRaisesRegex --- .../test/test_sample_template.py | 2 +- qiita_db/test/test_processing_job.py | 2 +- .../tests/test_sample_template.py | 52 +++++++++---------- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/qiita_db/metadata_template/test/test_sample_template.py b/qiita_db/metadata_template/test/test_sample_template.py index 8226faf28..9d4e980b3 100644 --- a/qiita_db/metadata_template/test/test_sample_template.py +++ b/qiita_db/metadata_template/test/test_sample_template.py @@ -2232,7 +2232,7 @@ def test_delete_column_specimen_id(self): self.metadata, self.new_study) self.new_study.specimen_id_column = 'latitude' - with self.assertRaisesRegexp( + with self.assertRaisesRegex( qdb.exceptions.QiitaDBOperationNotPermittedError, '"latitude" cannot be deleted, this column is currently ' r'selected as the tube identifier \(specimen_id_column\)'): diff --git a/qiita_db/test/test_processing_job.py b/qiita_db/test/test_processing_job.py index 4b49aab1d..c950ea059 100644 --- a/qiita_db/test/test_processing_job.py +++ b/qiita_db/test/test_processing_job.py @@ -1007,7 +1007,7 @@ class ProcessingJobDuplicated(TestCase): def test_create_duplicated(self): job = _create_job() job._set_status('success') - with self.assertRaisesRegexp(ValueError, 'Cannot create job because ' + with self.assertRaisesRegex(ValueError, 'Cannot create job because ' 'the parameters are the same as jobs ' 'that are queued, running or already ' 'have succeeded:') as context: diff --git a/qiita_pet/handlers/study_handlers/tests/test_sample_template.py b/qiita_pet/handlers/study_handlers/tests/test_sample_template.py index 015e3f2d0..9eca83a27 100644 --- a/qiita_pet/handlers/study_handlers/tests/test_sample_template.py +++ b/qiita_pet/handlers/study_handlers/tests/test_sample_template.py @@ -80,35 +80,35 @@ def test_sample_template_checks(self): sample_template_checks(1, user, check_exists=True) # Test study doesn't exist - with self.assertRaisesRegexp(HTTPError, 'Study does not exist'): + with self.assertRaisesRegex(HTTPError, 'Study does not exist'): sample_template_checks(1000000, user) # Test user doesn't have access to the study - with self.assertRaisesRegexp(HTTPError, + with self.assertRaisesRegex(HTTPError, 'User does not have access to study'): sample_template_checks(1, User('demo@microbio.me')) # Test sample template doesn't exist new_study = self._create_study('Test Sample Template Checks') - with self.assertRaisesRegexp(HTTPError, + with self.assertRaisesRegex(HTTPError, "Study %s doesn't have sample information" % new_study.id): sample_template_checks(new_study.id, user, check_exists=True) def test_sample_template_handler_post_request(self): # Test user doesn't have access - with self.assertRaisesRegexp(HTTPError, + with self.assertRaisesRegex(HTTPError, 'User does not have access to study'): sample_template_handler_post_request( 1, User('demo@microbio.me'), 'ignored') # Test study doesn't exist user = User('test@foo.bar') - with self.assertRaisesRegexp(HTTPError, 'Study does not exist'): + with self.assertRaisesRegex(HTTPError, 'Study does not exist'): sample_template_handler_post_request(1000000, user, 'ignored') # Test file doesn't exist - with self.assertRaisesRegexp(HTTPError, 'Filepath not found'): + with self.assertRaisesRegex(HTTPError, 'Filepath not found'): sample_template_handler_post_request(1, user, 'DoesNotExist.txt') # Test looks like mapping file and no data_type provided @@ -120,7 +120,7 @@ def test_sample_template_handler_post_request(self): with open(fp, 'w') as f: f.write('#SampleID\tCol1\nSample1\tVal1') - with self.assertRaisesRegexp( + with self.assertRaisesRegex( HTTPError, 'Please, choose a data type if uploading a QIIME ' 'mapping file'): sample_template_handler_post_request(1, user, fp) @@ -139,20 +139,20 @@ def test_sample_template_handler_patch_request(self): user = User('test@foo.bar') # Test user doesn't have access - with self.assertRaisesRegexp(HTTPError, + with self.assertRaisesRegex(HTTPError, 'User does not have access to study'): sample_template_handler_patch_request( User('demo@microbio.me'), "remove", "/1/columns/season_environment/") # Test study doesn't exist - with self.assertRaisesRegexp(HTTPError, 'Study does not exist'): + with self.assertRaisesRegex(HTTPError, 'Study does not exist'): sample_template_handler_patch_request( user, "remove", "/10000/columns/season_environment/") # Test sample template doesn't exist new_study = self._create_study('Patching test') - with self.assertRaisesRegexp(HTTPError, + with self.assertRaisesRegex(HTTPError, "Study %s doesn't have sample information" % new_study.id): sample_template_handler_patch_request( @@ -160,19 +160,19 @@ def test_sample_template_handler_patch_request(self): % new_study.id) # Test wrong operation value - with self.assertRaisesRegexp( + with self.assertRaisesRegex( HTTPError, 'Operation add not supported. Current supported ' 'operations: remove.'): sample_template_handler_patch_request( user, 'add', '/1/columns/season_environment') # Test wrong path parameter < 2 - with self.assertRaisesRegexp(HTTPError, 'Incorrect path parameter'): + with self.assertRaisesRegex(HTTPError, 'Incorrect path parameter'): sample_template_handler_patch_request(user, 'ignored', '1') # TESTS FOR OPERATION: remove # Test wrong path parameter - with self.assertRaisesRegexp(HTTPError, 'Incorrect path parameter'): + with self.assertRaisesRegex(HTTPError, 'Incorrect path parameter'): sample_template_handler_patch_request( user, 'remove', '/1/season_environment/') @@ -197,21 +197,21 @@ def test_sample_template_handler_patch_request(self): # TESTS FOR OPERATION: replace # Test incorrect path parameter with replace - with self.assertRaisesRegexp(HTTPError, 'Incorrect path parameter'): + with self.assertRaisesRegex(HTTPError, 'Incorrect path parameter'): sample_template_handler_patch_request(user, "replace", "/1/") # Test attribute not found - with self.assertRaisesRegexp(HTTPError, 'Attribute name not found'): + with self.assertRaisesRegex(HTTPError, 'Attribute name not found'): sample_template_handler_patch_request(user, "replace", "/1/name") # Test missing value - with self.assertRaisesRegexp(HTTPError, + with self.assertRaisesRegex(HTTPError, 'Value is required when updating sample ' 'information'): sample_template_handler_patch_request(user, "replace", "/1/data") # Test file doesn't exist - with self.assertRaisesRegexp(HTTPError, 'Filepath not found'): + with self.assertRaisesRegex(HTTPError, 'Filepath not found'): sample_template_handler_patch_request(user, "replace", "/1/data", req_value='DoesNotExist') @@ -227,19 +227,19 @@ def test_sample_template_handler_patch_request(self): def test_sample_template_handler_delete_request(self): # Test user doesn't have access - with self.assertRaisesRegexp(HTTPError, + with self.assertRaisesRegex(HTTPError, 'User does not have access to study'): sample_template_handler_delete_request( 1, User('demo@microbio.me')) # Test study doesn't exist user = User('test@foo.bar') - with self.assertRaisesRegexp(HTTPError, 'Study does not exist'): + with self.assertRaisesRegex(HTTPError, 'Study does not exist'): sample_template_handler_delete_request(1000000, user) # Test sample information doesn't exist new_study = self._create_study('Study for deleting test') - with self.assertRaisesRegexp(HTTPError, "Study %s doesn't have sample " + with self.assertRaisesRegex(HTTPError, "Study %s doesn't have sample " "information" % new_study.id): sample_template_handler_delete_request(new_study.id, user) @@ -255,14 +255,14 @@ def test_sample_template_handler_delete_request(self): def test_sample_template_overview_handler_get_request(self): # Test user doesn't have access - with self.assertRaisesRegexp(HTTPError, + with self.assertRaisesRegex(HTTPError, 'User does not have access to study'): sample_template_overview_handler_get_request( 1, User('demo@microbio.me')) # Test study doesn't exist user = User('test@foo.bar') - with self.assertRaisesRegexp(HTTPError, 'Study does not exist'): + with self.assertRaisesRegex(HTTPError, 'Study does not exist'): sample_template_overview_handler_get_request(1000000, user) # Test sample template exist @@ -312,23 +312,23 @@ def test_sample_template_overview_handler_get_request(self): def test_sample_template_columns_get_req(self): # Test user doesn't have access - with self.assertRaisesRegexp(HTTPError, + with self.assertRaisesRegex(HTTPError, 'User does not have access to study'): sample_template_columns_get_req(1, None, User('demo@microbio.me')) # Test study doesn't exist user = User('test@foo.bar') - with self.assertRaisesRegexp(HTTPError, 'Study does not exist'): + with self.assertRaisesRegex(HTTPError, 'Study does not exist'): sample_template_columns_get_req(1000000, None, user) # Test sample template doesn't exist new_study = self._create_study('New Study - Summary') - with self.assertRaisesRegexp(HTTPError, "Study %s doesn't have sample " + with self.assertRaisesRegex(HTTPError, "Study %s doesn't have sample " "information" % new_study.id): sample_template_columns_get_req(new_study.id, None, user) # Test that if the column doesn't exist it raises an error - with self.assertRaisesRegexp(QiitaDBColumnError, 'should-fail'): + with self.assertRaisesRegex(QiitaDBColumnError, 'should-fail'): sample_template_columns_get_req(1, 'should-fail', user) # Test success From eb172a1437a676d91fd5088251bdefb67327482f Mon Sep 17 00:00:00 2001 From: Antonio Gonzalez Date: Fri, 22 Feb 2019 12:12:46 -0700 Subject: [PATCH 3/4] flake8 --- .../test/test_sample_template.py | 4 ++- qiita_db/study.py | 3 +- qiita_db/test/test_processing_job.py | 6 ++-- .../tests/test_base_handlers.py | 2 +- .../handlers/api_proxy/tests/test_studies.py | 5 +++- .../tests/test_sample_template.py | 28 +++++++++---------- qiita_pet/test/test_qiita_redbiom.py | 4 ++- 7 files changed, 30 insertions(+), 22 deletions(-) diff --git a/qiita_db/metadata_template/test/test_sample_template.py b/qiita_db/metadata_template/test/test_sample_template.py index 9d4e980b3..5d49c7a47 100644 --- a/qiita_db/metadata_template/test/test_sample_template.py +++ b/qiita_db/metadata_template/test/test_sample_template.py @@ -1349,7 +1349,9 @@ def test_update_numpy(self): ['%s.Sample1' % self.new_study.id, { 'bool_col': 'false', 'date_col': '2015-09-01 00:00:00'}], ['qiita_sample_column_names', { - 'columns': ['bool_col', 'date_col']}]] + 'columns': sorted(['bool_col', 'date_col'])}]] + # making sure they are always in the same order + obs[2][1]['columns'] = sorted(obs[2][1]['columns']) self.assertEqual(sorted(obs), sorted(exp)) def test_generate_files(self): diff --git a/qiita_db/study.py b/qiita_db/study.py index 372d41b16..dead7cce4 100644 --- a/qiita_db/study.py +++ b/qiita_db/study.py @@ -1018,7 +1018,8 @@ def tags(self): sql = """SELECT study_tag FROM qiita.study_tags LEFT JOIN qiita.per_study_tags USING (study_tag) - WHERE study_id = {0}""".format(self._id) + WHERE study_id = {0} + ORDER BY study_tag""".format(self._id) qdb.sql_connection.TRN.add(sql) return [t[0] for t in qdb.sql_connection.TRN.execute_fetchindex()] diff --git a/qiita_db/test/test_processing_job.py b/qiita_db/test/test_processing_job.py index c950ea059..d05b97501 100644 --- a/qiita_db/test/test_processing_job.py +++ b/qiita_db/test/test_processing_job.py @@ -1008,9 +1008,9 @@ def test_create_duplicated(self): job = _create_job() job._set_status('success') with self.assertRaisesRegex(ValueError, 'Cannot create job because ' - 'the parameters are the same as jobs ' - 'that are queued, running or already ' - 'have succeeded:') as context: + 'the parameters are the same as jobs ' + 'that are queued, running or already ' + 'have succeeded:') as context: _create_job(False) # If it failed it's because we have jobs in non finished status so diff --git a/qiita_pet/handlers/analysis_handlers/tests/test_base_handlers.py b/qiita_pet/handlers/analysis_handlers/tests/test_base_handlers.py index 3b7d6496d..7a484de29 100644 --- a/qiita_pet/handlers/analysis_handlers/tests/test_base_handlers.py +++ b/qiita_pet/handlers/analysis_handlers/tests/test_base_handlers.py @@ -113,7 +113,7 @@ def test_post_create_analysis_handler(self): response = self.post('/analysis/create/', args) self.assertRegex( response.effective_url, - r"http://localhost:\d+/analysis/description/\d+/") + r"http://127.0.0.1:\d+/analysis/description/\d+/") self.assertEqual(response.code, 200) # The new analysis id is located at the -2 position (see regex above) diff --git a/qiita_pet/handlers/api_proxy/tests/test_studies.py b/qiita_pet/handlers/api_proxy/tests/test_studies.py index b88f5e5c1..6fc9faa32 100644 --- a/qiita_pet/handlers/api_proxy/tests/test_studies.py +++ b/qiita_pet/handlers/api_proxy/tests/test_studies.py @@ -347,8 +347,11 @@ def test_study_files_get_req_multiple(self): 'remaining': ['uploaded_file.txt'], 'message': '', 'file_types': [ ('raw_forward_seqs', True, - ['test_2.R1.fastq.gz', 'test_1.R1.fastq.gz']), + sorted(['test_2.R1.fastq.gz', 'test_1.R1.fastq.gz'])), ('raw_reverse_seqs', False, [])]} + # making sure they are always in the same order + oft = obs['file_types'][0] + obs['file_types'][0] = (oft[0], oft[1], sorted(oft[2])) self.assertEqual(obs, exp) # let's add reverse diff --git a/qiita_pet/handlers/study_handlers/tests/test_sample_template.py b/qiita_pet/handlers/study_handlers/tests/test_sample_template.py index 9eca83a27..7ec7d780f 100644 --- a/qiita_pet/handlers/study_handlers/tests/test_sample_template.py +++ b/qiita_pet/handlers/study_handlers/tests/test_sample_template.py @@ -85,20 +85,20 @@ def test_sample_template_checks(self): # Test user doesn't have access to the study with self.assertRaisesRegex(HTTPError, - 'User does not have access to study'): + 'User does not have access to study'): sample_template_checks(1, User('demo@microbio.me')) # Test sample template doesn't exist new_study = self._create_study('Test Sample Template Checks') with self.assertRaisesRegex(HTTPError, - "Study %s doesn't have sample information" - % new_study.id): + "Study %s doesn't have sample information" + % new_study.id): sample_template_checks(new_study.id, user, check_exists=True) def test_sample_template_handler_post_request(self): # Test user doesn't have access with self.assertRaisesRegex(HTTPError, - 'User does not have access to study'): + 'User does not have access to study'): sample_template_handler_post_request( 1, User('demo@microbio.me'), 'ignored') @@ -140,7 +140,7 @@ def test_sample_template_handler_patch_request(self): # Test user doesn't have access with self.assertRaisesRegex(HTTPError, - 'User does not have access to study'): + 'User does not have access to study'): sample_template_handler_patch_request( User('demo@microbio.me'), "remove", "/1/columns/season_environment/") @@ -153,8 +153,8 @@ def test_sample_template_handler_patch_request(self): # Test sample template doesn't exist new_study = self._create_study('Patching test') with self.assertRaisesRegex(HTTPError, - "Study %s doesn't have sample information" - % new_study.id): + "Study %s doesn't have sample information" + % new_study.id): sample_template_handler_patch_request( user, "remove", "/%s/columns/season_environment/" % new_study.id) @@ -206,8 +206,8 @@ def test_sample_template_handler_patch_request(self): # Test missing value with self.assertRaisesRegex(HTTPError, - 'Value is required when updating sample ' - 'information'): + 'Value is required when updating sample ' + 'information'): sample_template_handler_patch_request(user, "replace", "/1/data") # Test file doesn't exist @@ -228,7 +228,7 @@ def test_sample_template_handler_patch_request(self): def test_sample_template_handler_delete_request(self): # Test user doesn't have access with self.assertRaisesRegex(HTTPError, - 'User does not have access to study'): + 'User does not have access to study'): sample_template_handler_delete_request( 1, User('demo@microbio.me')) @@ -240,7 +240,7 @@ def test_sample_template_handler_delete_request(self): # Test sample information doesn't exist new_study = self._create_study('Study for deleting test') with self.assertRaisesRegex(HTTPError, "Study %s doesn't have sample " - "information" % new_study.id): + "information" % new_study.id): sample_template_handler_delete_request(new_study.id, user) # Test success @@ -256,7 +256,7 @@ def test_sample_template_handler_delete_request(self): def test_sample_template_overview_handler_get_request(self): # Test user doesn't have access with self.assertRaisesRegex(HTTPError, - 'User does not have access to study'): + 'User does not have access to study'): sample_template_overview_handler_get_request( 1, User('demo@microbio.me')) @@ -313,7 +313,7 @@ def test_sample_template_overview_handler_get_request(self): def test_sample_template_columns_get_req(self): # Test user doesn't have access with self.assertRaisesRegex(HTTPError, - 'User does not have access to study'): + 'User does not have access to study'): sample_template_columns_get_req(1, None, User('demo@microbio.me')) # Test study doesn't exist @@ -324,7 +324,7 @@ def test_sample_template_columns_get_req(self): # Test sample template doesn't exist new_study = self._create_study('New Study - Summary') with self.assertRaisesRegex(HTTPError, "Study %s doesn't have sample " - "information" % new_study.id): + "information" % new_study.id): sample_template_columns_get_req(new_study.id, None, user) # Test that if the column doesn't exist it raises an error diff --git a/qiita_pet/test/test_qiita_redbiom.py b/qiita_pet/test/test_qiita_redbiom.py index 51f3036b3..c79bd6b20 100644 --- a/qiita_pet/test/test_qiita_redbiom.py +++ b/qiita_pet/test/test_qiita_redbiom.py @@ -29,10 +29,12 @@ def test_post_metadata(self): exp_artifact_biom_ids = { '5': ['1.SKD2.640178'], - '4': ['1.SKD2.640178', '1.SKD8.640184']} + '4': sorted(['1.SKD2.640178', '1.SKD8.640184'])} response_body = loads(response.body) obs_artifact_biom_ids = response_body['data'][0].pop( 'artifact_biom_ids') + # making sure they are in the same order + obs_artifact_biom_ids['4'] = sorted(obs_artifact_biom_ids['4']) self.assertDictEqual(obs_artifact_biom_ids, exp_artifact_biom_ids) exp = {'status': 'success', 'message': '', 'data': DATA} self.assertEqual(response_body, exp) From 64f27d52802c9859331de5c87eb10b95736f4411 Mon Sep 17 00:00:00 2001 From: Antonio Gonzalez Date: Fri, 22 Feb 2019 12:39:50 -0700 Subject: [PATCH 4/4] fix errors --- .../handlers/api_proxy/tests/test_studies.py | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/qiita_pet/handlers/api_proxy/tests/test_studies.py b/qiita_pet/handlers/api_proxy/tests/test_studies.py index 6fc9faa32..efddbfcda 100644 --- a/qiita_pet/handlers/api_proxy/tests/test_studies.py +++ b/qiita_pet/handlers/api_proxy/tests/test_studies.py @@ -364,10 +364,15 @@ def test_study_files_get_req_multiple(self): 'shared@foo.bar', 1, pt.id, 'per_sample_FASTQ') exp = {'status': 'success', 'num_prefixes': 2, 'artifacts': [], 'remaining': ['uploaded_file.txt'], 'message': '', - 'file_types': [('raw_forward_seqs', True, - ['test_2.R1.fastq.gz', 'test_1.R1.fastq.gz']), - ('raw_reverse_seqs', False, - ['test_2.R2.fastq.gz', 'test_1.R2.fastq.gz'])]} + 'file_types': [ + ('raw_forward_seqs', True, sorted( + ['test_2.R1.fastq.gz', 'test_1.R1.fastq.gz'])), + ('raw_reverse_seqs', False, sorted( + ['test_2.R2.fastq.gz', 'test_1.R2.fastq.gz']))]} + # making sure they are always in the same order + oft = obs['file_types'] + obs['file_types'][0] = (oft[0][0], oft[0][1], sorted(oft[0][2])) + obs['file_types'][1] = (oft[1][0], oft[1][1], sorted(oft[1][2])) self.assertEqual(obs, exp) # let's an extra file that matches @@ -398,11 +403,15 @@ def test_study_files_get_req_multiple(self): 'artifacts': [(1, 'Identification of the Microbiomes for ' 'Cannabis Soils (1) - Raw data 1 (1)')], 'file_types': [ - ('raw_barcodes', True, - ['test_2.R1.fastq.gz', 'test_1.R1.fastq.gz']), - ('raw_forward_seqs', True, - ['test_2.R2.fastq.gz', 'test_1.R2.fastq.gz']), + ('raw_barcodes', True, sorted( + ['test_2.R1.fastq.gz', 'test_1.R1.fastq.gz'])), + ('raw_forward_seqs', True, sorted( + ['test_2.R2.fastq.gz', 'test_1.R2.fastq.gz'])), ('raw_reverse_seqs', False, ['test_1.R3.fastq.gz'])]} + # making sure they are always in the same order + oft = obs['file_types'] + obs['file_types'][0] = (oft[0][0], oft[0][1], sorted(oft[0][2])) + obs['file_types'][1] = (oft[1][0], oft[1][1], sorted(oft[1][2])) self.assertEqual(obs, exp) PREP.delete(pt.id)