Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c812fec
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Feb 19, 2016
1b9c5ec
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Feb 19, 2016
03d4571
Merge branch 'workflow-object' into artifact-study-pages-tests
josenavas Feb 19, 2016
bf13e4d
Fixing qiita_db/test/test_artifact.py
josenavas Feb 19, 2016
7797c72
Fixing study tests
josenavas Feb 19, 2016
4716480
Requiring minimum pandas version 0.17
josenavas Feb 19, 2016
2639998
Fixing qiita_pet/handlers/api_proxy/tests/test_artifact.py tests
josenavas Feb 19, 2016
e3ebea0
fixing qiita_pet/handlers/api_proxy/tests/test_prep_template.py
josenavas Feb 19, 2016
f191a16
Fixing test_study_handlers.py
josenavas Feb 19, 2016
6645258
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Feb 25, 2016
f817558
Adding -v to travis
josenavas Feb 25, 2016
0c5850f
Fixing test post job not running
josenavas Feb 25, 2016
6824b86
Fixing test_types
josenavas Feb 25, 2016
cb60f2d
Fixing processing job tests
josenavas Feb 25, 2016
4f1c9b1
Fixing tests in the api proxy due to the usage of tests
josenavas Feb 25, 2016
4f05365
Fixing set up in test_sample_template.py
josenavas Feb 25, 2016
e730156
Fixing failing test
josenavas Feb 25, 2016
69d4a5e
Fix failure on file retrieval
josenavas Feb 25, 2016
03f87e6
pep8ing
josenavas Feb 25, 2016
fbd5b09
Fixing indentation
josenavas Feb 25, 2016
5ac0372
Removing unused code
josenavas Feb 25, 2016
0919093
Fixing imports
josenavas Feb 25, 2016
fec048b
Splitting tests by file and noting missing tests
josenavas Feb 25, 2016
60b9250
Removing warnings
josenavas Feb 25, 2016
d4d685d
addressing @antgonza
josenavas Feb 26, 2016
7791ba0
Speeding up qiita pet tests by 1 minute
josenavas Feb 26, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ script:
- qiita-env make --no-load-ontologies
- if [ ${TEST_ADD_STUDIES} == "True" ]; then test_data_studies/commands.sh ; fi
- if [ ${TEST_ADD_STUDIES} == "False" ]; then qiita-test-install ; fi
- if [ ${TEST_ADD_STUDIES} == "False" ]; then nosetests --with-doctest --with-coverage; fi
- if [ ${TEST_ADD_STUDIES} == "False" ]; then nosetests --with-doctest --with-coverage -v; fi
- flake8 qiita_* setup.py scripts/qiita scripts/qiita-env scripts/qiita-test-install
- ls -R /home/travis/miniconda3/envs/env_name/lib/python2.7/site-packages/qiita_pet/support_files/doc/
- qiita pet webserver
Expand Down
11 changes: 6 additions & 5 deletions qiita_db/artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,17 +376,18 @@ def delete(cls, artifact_id):
raise qdb.exceptions.QiitaDBArtifactDeletionError(
artifact_id, "it has been submitted to VAMPS")

# Check if there is a job queued or running that will use/is using
# the artifact
# Check if there is a job queued, running, waiting or
# in_construction that will use/is using the artifact
sql = """SELECT EXISTS(
SELECT *
FROM qiita.artifact_processing_job
JOIN qiita.processing_job USING (processing_job_id)
JOIN qiita.processing_job_status
USING (processing_job_status_id)
WHERE artifact_id = %s
AND processing_job_status IN ('queued', 'running'))
"""
AND processing_job_status IN (
'queued', 'running', 'waiting',
'in_construction'))"""
qdb.sql_connection.TRN.add(sql, [artifact_id])
if qdb.sql_connection.TRN.execute_fetchlast():
raise qdb.exceptions.QiitaDBArtifactDeletionError(
Expand Down Expand Up @@ -772,7 +773,7 @@ def filepaths(self):
with the artifact
"""
return qdb.util.retrieve_filepaths(
"artifact_filepath", "artifact_id", self.id)
"artifact_filepath", "artifact_id", self.id, sort='ascending')

@property
def parents(self):
Expand Down
2 changes: 1 addition & 1 deletion qiita_db/handlers/tests/test_processing_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def test_post_job_does_not_exists(self):
self.assertEqual(loads(obs.body), exp)

def test_post_job_not_running(self):
payload = dumps({'success': False, 'error': 'Job failure'})
payload = dumps({'success': True, 'artifacts': []})
obs = self.post(
'/qiita_db/jobs/063e553b-327c-4818-ab4a-adfe58e49860/complete/',
payload, headers=self.header)
Expand Down
4 changes: 2 additions & 2 deletions qiita_db/test/test_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def test_types(self):
['Demultiplexed', 'Demultiplexed and QC sequeneces'],
['FASTA', None], ['FASTA_Sanger', None], ['FASTQ', None],
['SFF', None], ['per_sample_FASTQ', None]]
self.assertEqual(obs, exp)
self.assertItemsEqual(obs, exp)

def test_copy(self):
src = qdb.artifact.Artifact(1)
Expand Down Expand Up @@ -336,7 +336,7 @@ def test_delete_error_vamps(self):
with self.assertRaises(qdb.exceptions.QiitaDBArtifactDeletionError):
qdb.artifact.Artifact.delete(obs.id)

def test_delete_error_queued_job(self):
def test_delete_error_in_construction_job(self):
test = qdb.artifact.Artifact.create(
self.filepaths_root, 'FASTQ', prep_template=self.prep_template)
self._clean_up_files.extend([fp for _, fp, _ in test.filepaths])
Expand Down
2 changes: 1 addition & 1 deletion qiita_db/test/test_processing_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ def test_graph_only_root(self):

def test_raise_if_not_in_construction(self):
# We just need to test that the execution continues (i.e. no raise)
tester = qdb.processing_job.ProcessingWorkflow(1)
tester = qdb.processing_job.ProcessingWorkflow(2)
tester._raise_if_not_in_construction()

def test_raise_if_not_in_construction_error(self):
Expand Down
32 changes: 14 additions & 18 deletions qiita_db/test/test_study.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from unittest import TestCase, main
from datetime import datetime

from future.utils import viewitems

from qiita_core.exceptions import IncompetentQiitaDeveloperError
from qiita_core.qiita_settings import qiita_config
from qiita_core.util import qiita_test_checker
Expand Down Expand Up @@ -138,20 +136,20 @@ def setUp(self):
"study_abstract": "Exploring how a high fat diet changes the "
"gut microbiome",
"emp_person_id": 2,
"principal_investigator_id": 3,
"lab_person_id": 1
"principal_investigator": qdb.study.StudyPerson(3),
"lab_person": qdb.study.StudyPerson(1)
}

self.existingexp = {
'mixs_compliant': True,
'metadata_complete': True,
'reprocess': False,
'number_samples_promised': 27,
'emp_person_id': qdb.study.StudyPerson(2),
'emp_person_id': 2,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not part of tests, but this should be renamed to emp_person since it's no longer the ID.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's incorrect - note how it is actually the id, the ones that are no longer the id are the principal_investigator and the lab_person

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Went is this still the id but the rest are not? We should be consistent.
On Feb 27, 2016 14:17, "Jose Navas" notifications@github.com wrote:

In qiita_db/test/test_study.py
#1647 (comment):

@@ -147,11 +145,11 @@ def setUp(self):
'metadata_complete': True,
'reprocess': False,
'number_samples_promised': 27,

  •        'emp_person_id': qdb.study.StudyPerson(2),
    
  •        'emp_person_id': 2,
    

That's incorrect - note how it is actually the id, the ones that are no
longer the id are the principal_investigator and the lab_person


Reply to this email directly or view it on GitHub
https://github.com/biocore/qiita/pull/1647/files#r54337870.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@antgonza @ElDeveloper @mortonjt emp_person is not used anywhere in the code and I think we should drop it as that is something that we will be keeping track in Jira, not Qiita. Should we spend time fixing that or just agree that we are going to drop it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an issue to discuss that: #1668

'funding': None,
'vamps_id': None,
'first_contact': datetime(2014, 5, 19, 16, 10),
'principal_investigator_id': qdb.study.StudyPerson(3),
'principal_investigator': qdb.study.StudyPerson(3),
'timeseries_type_id': 1,
'study_abstract':
"This is a preliminary study to examine the "
Expand All @@ -169,7 +167,7 @@ def setUp(self):
'study_alias': 'Cannabis Soils',
'most_recent_contact': '2014-05-19 16:11',
'most_recent_contact': datetime(2014, 5, 19, 16, 11),
'lab_person_id': qdb.study.StudyPerson(1),
'lab_person': qdb.study.StudyPerson(1),
'number_samples_collected': 27}

def tearDown(self):
Expand Down Expand Up @@ -361,15 +359,16 @@ def test_create_study_min_data(self):
'reprocess': False,
'number_samples_promised': 28, 'emp_person_id': 2,
'funding': None, 'vamps_id': None,
'principal_investigator_id': 3,
'principal_investigator': qdb.study.StudyPerson(3),
'timeseries_type_id': 1,
'study_abstract': 'Exploring how a high fat diet changes the '
'gut microbiome',
'spatial_series': None,
'study_description': 'Microbiome of people who eat nothing but'
' fried chicken',
'study_alias': 'FCM',
'most_recent_contact': None, 'lab_person_id': 1,
'most_recent_contact': None,
'lab_person': qdb.study.StudyPerson(1),
'number_samples_collected': 25}
self.assertEqual(obs_info, exp)
# Check the timestamp separately, since it is set by the database
Expand Down Expand Up @@ -431,14 +430,16 @@ def test_create_study_all_data(self):
'number_samples_promised': 28, 'emp_person_id': 2,
'funding': 'FundAgency', 'vamps_id': 'MBE_1111111',
'first_contact': datetime(2014, 10, 24, 12, 47),
'principal_investigator_id': 3, 'timeseries_type_id': 1,
'principal_investigator': qdb.study.StudyPerson(3),
'timeseries_type_id': 1,
'study_abstract': 'Exploring how a high fat diet changes the '
'gut microbiome',
'spatial_series': True,
'study_description': 'Microbiome of people who eat nothing '
'but fried chicken',
'study_alias': 'FCM',
'most_recent_contact': None, 'lab_person_id': 1,
'most_recent_contact': None,
'lab_person': qdb.study.StudyPerson(1),
'number_samples_collected': 25}
self.assertEqual(obs.info, exp)
self.assertEqual(obs.efo, [1])
Expand Down Expand Up @@ -584,12 +585,6 @@ def test_ebi_submission_status_setter(self):
with self.assertRaises(ValueError):
new.ebi_submission_status = "unknown"

def test_retrieve_info(self):
for key, val in viewitems(self.existingexp):
if isinstance(val, qdb.base.QiitaObject):
self.existingexp[key] = val.id
self.assertEqual(self.study.info, self.existingexp)

def test_set_info(self):
"""Set info in a study"""
newinfo = {
Expand All @@ -611,8 +606,9 @@ def test_set_info(self):
self.infoexp["spatial_series"] = None
self.infoexp["most_recent_contact"] = None
self.infoexp["reprocess"] = False
self.infoexp["lab_person_id"] = 2
self.infoexp["first_contact"] = datetime(2014, 6, 11)
self.infoexp["lab_person"] = qdb.study.StudyPerson(2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this two step process instead of just changing the key to lab_person on line 594?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that line 594 and this are not the same variable.

del self.infoexp["lab_person_id"]

self.assertEqual(new.info, self.infoexp)

Expand Down
27 changes: 18 additions & 9 deletions qiita_pet/handlers/api_proxy/tests/test_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,24 @@
from datetime import datetime

import pandas as pd
import numpy.testing as npt

from qiita_core.qiita_settings import qiita_config
from qiita_core.util import qiita_test_checker
from qiita_db.artifact import Artifact
from qiita_db.metadata_template.prep_template import PrepTemplate
from qiita_db.study import Study
from qiita_db.util import get_count, get_mountpoint
from qiita_db.exceptions import QiitaDBUnknownIDError
from qiita_db.exceptions import QiitaDBUnknownIDError, QiitaDBWarning
from qiita_pet.handlers.api_proxy.artifact import (
artifact_get_req, artifact_status_put_req, artifact_graph_get_req,
artifact_delete_req, artifact_types_get_req, artifact_post_req)


@qiita_test_checker()
class TestArtifactAPI(TestCase):
database = True

def setUp(self):
uploads_path = get_mountpoint('uploads')[0][1]
# Create prep test file to point at
Expand Down Expand Up @@ -97,8 +100,9 @@ def test_artifact_get_req(self):
def test_artifact_post_req(self):
# Create new prep template to attach artifact to
new_prep_id = get_count('qiita.prep_template') + 1
PrepTemplate.create(pd.DataFrame(
{'new_col': {'1.SKD6.640190': 1}}), Study(1), '16S')
npt.assert_warns(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also test the warning mesage is correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not correct, we are not interested in the warning message thrown here. the only reason why this is wrapped in the npt.assert_warns is because we don't want the warning message to show up on the test suite.

QiitaDBWarning, PrepTemplate.create,
pd.DataFrame({'new_col': {'1.SKD6.640190': 1}}), Study(1), '16S')

new_artifact_id = get_count('qiita.artifact') + 1
obs = artifact_post_req(
Expand All @@ -115,8 +119,9 @@ def test_artifact_post_req(self):
def test_artifact_post_req_bad_file(self):
# Create new prep template to attach artifact to
new_prep_id = get_count('qiita.prep_template') + 1
PrepTemplate.create(pd.DataFrame(
{'new_col': {'1.SKD6.640190': 1}}), Study(1), '16S')
npt.assert_warns(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

QiitaDBWarning, PrepTemplate.create,
pd.DataFrame({'new_col': {'1.SKD6.640190': 1}}), Study(1), '16S')

obs = artifact_post_req(
'test@foo.bar', {'raw_forward_seqs': ['NOEXIST']},
Expand Down Expand Up @@ -170,9 +175,10 @@ def test_artifact_graph_get_req_descendants(self):
'node_labels': [(1, 'Raw data 1 - FASTQ'),
(3, 'Demultiplexed 2 - Demultiplexed'),
(2, 'Demultiplexed 1 - Demultiplexed'),
(4, 'BIOM - BIOM')],
'edge_list': [(1, 3), (1, 2), (2, 4)]}
self.assertEqual(obs, exp)
(4, 'BIOM - BIOM'),
(5, 'BIOM - BIOM')],
'edge_list': [(1, 3), (1, 2), (2, 5), (2, 4)]}
self.assertItemsEqual(obs, exp)

def test_artifact_graph_get_req_no_access(self):
obs = artifact_graph_get_req(1, 'ancestors', 'demo@microbio.me')
Expand All @@ -191,7 +197,10 @@ def test_artifact_types_get_req(self):
['FASTQ', None],
['SFF', None],
['per_sample_FASTQ', None]]}
self.assertEqual(obs, exp)

self.assertEqual(obs['message'], exp['message'])
self.assertEqual(obs['status'], exp['status'])
self.assertItemsEqual(obs['types'], exp['types'])

def test_artifact_graph_get_req_bad_direction(self):
obs = artifact_graph_get_req(1, 'WRONG', 'test@foo.bar')
Expand Down
30 changes: 19 additions & 11 deletions qiita_pet/handlers/api_proxy/tests/test_prep_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
from random import choice

import pandas as pd
import numpy.testing as npt

from qiita_core.qiita_settings import qiita_config
from qiita_core.util import qiita_test_checker
from qiita_db.metadata_template.prep_template import PrepTemplate
from qiita_db.ontology import Ontology
from qiita_db.study import Study
from qiita_db.util import get_count
from qiita_db.exceptions import QiitaDBWarning
from qiita_pet.handlers.api_proxy.prep_template import (
prep_template_summary_get_req, prep_template_post_req,
prep_template_put_req, prep_template_delete_req, prep_template_get_req,
Expand All @@ -36,8 +38,8 @@ def setUp(self):
with open(self.update_fp, 'w') as f:
f.write("""sample_name\tnew_col\n1.SKD6.640190\tnew_value\n""")

def tear_down(self):
remove(self.update_fp)
def tear_down(self):
remove(self.update_fp)

fp = join(qiita_config.base_data_dir, 'uploads', '1',
'uploaded_file.txt')
Expand Down Expand Up @@ -187,7 +189,11 @@ def test_prep_template_post_req(self):
'LinkerPrimerSequence, BarcodeSequence',
'file': 'update.txt',
'id': new_id}
self.assertEqual(obs, exp)
self.assertEqual(obs['status'], exp['status'])
self.assertItemsEqual(obs['message'].split('\n'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the split?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you pay attention to the code that generates this string, it is a result of joining the strings stored in a set. Since it is in a set, it is unordered, so we cannot ensure the order of the strings here. By doing the split and assertItemsEqual I can compare that the contents are the same.

exp['message'].split('\n'))
self.assertEqual(obs['file'], exp['file'])
self.assertEqual(obs['id'], exp['id'])

# Make sure new prep template added
prep = PrepTemplate(new_id)
Expand Down Expand Up @@ -232,7 +238,10 @@ def test_prep_template_put_req_warning(self):
'differences between the data stored in the DB and '
'the new data provided',
'file': 'update.txt'}
self.assertEqual(obs, exp)
self.assertEqual(obs['status'], exp['status'])
self.assertItemsEqual(obs['message'].split('\n'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same answer

exp['message'].split('\n'))
self.assertEqual(obs['file'], exp['file'])

def test_prep_put_req_inv_type(self):
randstr = ''.join([choice(ascii_letters) for x in range(30)])
Expand Down Expand Up @@ -270,7 +279,8 @@ def test_prep_template_put_req_no_exists(self):
def test_prep_template_delete_req(self):
template = pd.read_csv(self.update_fp, sep='\t', index_col=0)
new_id = get_count('qiita.prep_template') + 1
PrepTemplate.create(template, Study(1), '16S')
npt.assert_warns(QiitaDBWarning, PrepTemplate.create,
template, Study(1), '16S')
obs = prep_template_delete_req(new_id, 'test@foo.bar')
exp = {'status': 'success',
'message': ''}
Expand Down Expand Up @@ -315,17 +325,15 @@ def test_prep_template_filepaths_get_req_no_access(self):

def test_prep_template_graph_get_req(self):
obs = prep_template_graph_get_req(1, 'test@foo.bar')
exp = {'edge_list': [(1, 3), (1, 2), (2, 4)],
exp = {'edge_list': [(1, 3), (1, 2), (2, 4), (2, 5)],
'node_labels': [(1, 'Raw data 1 - FASTQ'),
(2, 'Demultiplexed 1 - Demultiplexed'),
(3, 'Demultiplexed 2 - Demultiplexed'),
(4, 'BIOM - BIOM')],
(4, 'BIOM - BIOM'),
(5, 'BIOM - BIOM')],
'status': 'success',
'message': ''}

self.assertItemsEqual(obs.keys(), exp.keys())
self.assertItemsEqual(obs['edge_list'], exp['edge_list'])
self.assertItemsEqual(obs['node_labels'], exp['node_labels'])
self.assertItemsEqual(obs, exp)

def test_prep_template_graph_get_req_no_access(self):
obs = prep_template_graph_get_req(1, 'demo@microbio.me')
Expand Down
12 changes: 7 additions & 5 deletions qiita_pet/handlers/api_proxy/tests/test_sample_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# The full license is in the file LICENSE, distributed with this software.
# -----------------------------------------------------------------------------
from unittest import TestCase, main
from os import remove
from os import remove, mkdir
from os.path import join, exists

from qiita_core.util import qiita_test_checker
Expand Down Expand Up @@ -40,9 +40,11 @@ def setUp(self):
qdb.user.User('test@foo.bar'), "Some New Study", [1],
info)

base_dir = qdb.util.get_mountpoint('uploads')[0][1]
self.new_study_fp = join(base_dir, str(self.new_study.id),
'uploaded_file.txt')
base_dir = join(qdb.util.get_mountpoint('uploads')[0][1],
str(self.new_study.id))
if not exists(base_dir):
mkdir(base_dir)
self.new_study_fp = join(base_dir, 'uploaded_file.txt')
if not exists(self.new_study_fp):
with open(self.new_study_fp, 'w') as f:
f.write('')
Expand Down Expand Up @@ -356,7 +358,7 @@ def test_sample_template_filepaths_get_req(self):
obs = sample_template_filepaths_get_req(1, 'test@foo.bar')
exp = {'status': 'success',
'message': '',
'filepaths': [(14, join(templates_dir,
'filepaths': [(17, join(templates_dir,
'1_19700101-000000.txt'))]}
self.assertEqual(obs, exp)

Expand Down
Loading