Skip to content

Commit

Permalink
Merge pull request #2001 from antgonza/fix-fix-1971
Browse files Browse the repository at this point in the history
fix-fix-1971
  • Loading branch information
josenavas committed Nov 29, 2016
2 parents d9d7f83 + 09d23db commit 547319a
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 14 deletions.
4 changes: 3 additions & 1 deletion qiita_pet/handlers/api_proxy/studies.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ def study_prep_get_req(study_id, user_id):
info['start_artifact_id'] = start_artifact.id
info['youngest_artifact'] = '%s - %s' % (
youngest_artifact.name, youngest_artifact.artifact_type)
info['ebi_experiment'] = bool(prep.ebi_experiment_accessions)
info['ebi_experiment'] = bool(
[v for _, v in viewitems(prep.ebi_experiment_accessions)
if v is not None])
else:
info['start_artifact'] = None
info['start_artifact_id'] = None
Expand Down
107 changes: 104 additions & 3 deletions qiita_pet/handlers/api_proxy/tests/test_studies.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
# -----------------------------------------------------------------------------
from unittest import TestCase, main
from datetime import datetime
from os.path import exists, join, basename
from os.path import exists, join, basename, isdir
from os import remove, close
from tempfile import mkstemp
from shutil import rmtree
from tempfile import mkstemp, mkdtemp

import pandas as pd
import numpy.testing as npt
Expand All @@ -29,7 +30,10 @@ def setUp(self):
def tearDown(self):
for fp in self._clean_up_files:
if exists(fp):
remove(fp)
if isdir(fp):
rmtree(fp)
else:
remove(fp)

def test_data_types_get_req(self):
obs = data_types_get_req()
Expand Down Expand Up @@ -232,6 +236,103 @@ def test_study_prep_get_req(self):
for i in range(4, 0, -1):
qdb.artifact.Artifact(i).visibility = "private"

def test_study_prep_get_req_failed_EBI(self):
temp_dir = mkdtemp()
self._clean_up_files.append(temp_dir)
user_email = 'test@foo.bar'

# creating a (A) new study, (B) sample info, (C) prep without EBI
# values

# (A)
info = {
"timeseries_type_id": 1,
"metadata_complete": True,
"mixs_compliant": True,
"number_samples_collected": 3,
"number_samples_promised": 3,
"study_alias": "Test EBI",
"study_description": "Study for testing EBI",
"study_abstract": "Study for testing EBI",
"emp_person_id": qdb.study.StudyPerson(2),
"principal_investigator_id": qdb.study.StudyPerson(3),
"lab_person_id": qdb.study.StudyPerson(1)
}
study = qdb.study.Study.create(
qdb.user.User(user_email), "Test EBI study", [1], info)

# (B)
metadata_dict = {
'Sample1': {'collection_timestamp': datetime(2015, 6, 1, 7, 0, 0),
'physical_specimen_location': 'location1',
'taxon_id': 9606,
'scientific_name': 'homo sapiens',
'Description': 'Test Sample 1'},
'Sample2': {'collection_timestamp': datetime(2015, 6, 2, 7, 0, 0),
'physical_specimen_location': 'location1',
'taxon_id': 9606,
'scientific_name': 'homo sapiens',
'Description': 'Test Sample 2'},
'Sample3': {'collection_timestamp': datetime(2015, 6, 3, 7, 0, 0),
'physical_specimen_location': 'location1',
'taxon_id': 9606,
'scientific_name': 'homo sapiens',
'Description': 'Test Sample 3'}
}
metadata = pd.DataFrame.from_dict(metadata_dict, orient='index',
dtype=str)
qdb.metadata_template.sample_template.SampleTemplate.create(
metadata, study)

# (C)
metadata_dict = {
'Sample1': {'primer': 'GTGCCAGCMGCCGCGGTAA',
'barcode': 'CGTAGAGCTCTC',
'center_name': 'KnightLab',
'platform': 'ILLUMINA',
'instrument_model': 'Illumina MiSeq',
'library_construction_protocol': 'Protocol ABC',
'experiment_design_description': "Random value 1"},
'Sample2': {'primer': 'GTGCCAGCMGCCGCGGTAA',
'barcode': 'CGTAGAGCTCTA',
'center_name': 'KnightLab',
'platform': 'ILLUMINA',
'instrument_model': 'Illumina MiSeq',
'library_construction_protocol': 'Protocol ABC',
'experiment_design_description': "Random value 2"},
'Sample3': {'primer': 'GTGCCAGCMGCCGCGGTAA',
'barcode': 'CGTAGAGCTCTT',
'center_name': 'KnightLab',
'platform': 'ILLUMINA',
'instrument_model': 'Illumina MiSeq',
'library_construction_protocol': 'Protocol ABC',
'experiment_design_description': "Random value 3"},
}
metadata = pd.DataFrame.from_dict(metadata_dict, orient='index',
dtype=str)
pt = qdb.metadata_template.prep_template.PrepTemplate.create(
metadata, study, "16S", 'Metagenomics')

# making sure that the EBI values are empty
exp = {('%d.Sample3' % study.id): None,
('%d.Sample2' % study.id): None,
('%d.Sample1' % study.id): None}
self.assertEqual(pt.ebi_experiment_accessions, exp)

# actual test
obs = study_prep_get_req(study.id, user_email)
exp = {
'info': {
'16S': [
{'status': 'sandbox', 'name': 'PREP %d NAME' % pt.id,
'start_artifact': None, 'youngest_artifact': None,
'ebi_experiment': False, 'id': pt.id,
'start_artifact_id': None}]
},
'message': '',
'status': 'success'}
self.assertEqual(obs, exp)

def test_study_prep_get_req_no_access(self):
obs = study_prep_get_req(1, 'demo@microbio.me')
exp = {'status': 'error',
Expand Down
3 changes: 0 additions & 3 deletions qiita_ware/test/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
# -----------------------------------------------------------------------------
from unittest import TestCase, main
from os.path import join
from warnings import simplefilter
from tempfile import mkdtemp
import pandas as pd
from datetime import datetime
Expand Down Expand Up @@ -62,8 +61,6 @@ def write_demux_files(self, prep_template, generate_hdf5=True):

def generate_new_study_with_preprocessed_data(self):
"""Creates a new study up to the processed data for testing"""
# ignoring warnings generated when adding templates
simplefilter("ignore")
info = {
"timeseries_type_id": 1,
"metadata_complete": True,
Expand Down
4 changes: 2 additions & 2 deletions qiita_ware/test/test_dispatchable.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ def test_update_sample_template(self):
"existing template: new_col\nThere are no "
"differences between the data stored in the DB and "
"the new data provided")}
self.assertEqual(obs['status'], exp['status'])
self.assertItemsEqual(obs['message'].split('\n'),
exp['message'].split('\n'))
self.assertEqual(obs['status'], exp['status'])

def test_delete_sample_template(self):
obs = delete_sample_template(1)
Expand All @@ -115,9 +115,9 @@ def test_update_prep_template(self):
'existing template: new_col\nThere are no '
'differences between the data stored in the DB and '
'the new data provided'}
self.assertEqual(obs['status'], exp['status'])
self.assertItemsEqual(obs['message'].split('\n'),
exp['message'].split('\n'))
self.assertEqual(obs['status'], exp['status'])

def test_delete_sample_or_column(self):
st = SampleTemplate(1)
Expand Down
5 changes: 0 additions & 5 deletions qiita_ware/test/test_ebi.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
# The full license is in the file LICENSE, distributed with this software.
# -----------------------------------------------------------------------------

from warnings import simplefilter
from os import remove
from os.path import join, isdir, exists
from shutil import rmtree
Expand Down Expand Up @@ -299,8 +298,6 @@ def generate_new_prep_template_and_write_demux_files(self,
valid_metadata=False):
"""Creates new prep-template/demux-file to avoid duplication of code"""

# ignoring warnings generated when adding templates
simplefilter("ignore")
# creating prep template without required EBI submission columns
if not valid_metadata:
metadata_dict = {
Expand Down Expand Up @@ -364,8 +361,6 @@ def generate_new_prep_template_and_write_demux_files(self,

def generate_new_study_with_preprocessed_data(self):
"""Creates a new study up to the processed data for testing"""
# ignoring warnings generated when adding templates
simplefilter("ignore")
info = {
"timeseries_type_id": 1,
"metadata_complete": True,
Expand Down

0 comments on commit 547319a

Please sign in to comment.