Skip to content

Commit

Permalink
Merge pull request #113 from squirrelo/jobcreate
Browse files Browse the repository at this point in the history
Fix job create
  • Loading branch information
ElDeveloper committed Jun 19, 2014
2 parents 856b4b5 + 209e5aa commit 432f2cc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
13 changes: 7 additions & 6 deletions qiita_db/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,11 @@ def create(cls, datatype, command, options, analysis):
Job object
The newly created job
"""
if cls.exists(datatype, command, options):
raise QiitaDBDuplicateError(
"Job", "datatype: %s, command: %s, options: %s"
% (datatype, command, options))
# IGNORING EXISTS FOR DEMO
# if cls.exists(datatype, command, options):
# raise QiitaDBDuplicateError(
# "Job", "datatype: %s, command: %s, options: %s"
# % (datatype, command, options))

# Get the datatype and command ids from the strings
conn_handler = SQLConnectionHandler()
Expand All @@ -114,8 +115,8 @@ def create(cls, datatype, command, options, analysis):
sql = ("INSERT INTO qiita.{0} (data_type_id, job_status_id, "
"command_id, options) VALUES "
"(%s, %s, %s, %s) RETURNING job_id").format(cls._table)
job_id = conn_handler.execute_fetchone(sql, (datatype_id, command_id,
1, opts_json))[0]
job_id = conn_handler.execute_fetchone(sql, (datatype_id, 1,
command_id, opts_json))[0]

# add job to analysis
sql = ("INSERT INTO qiita.analysis_job (analysis_id, job_id) VALUES "
Expand Down
34 changes: 26 additions & 8 deletions qiita_db/test/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,14 @@ def test_exists_not_there(self):

def test_create(self):
"""Makes sure creation works as expected"""
new = Job.create("18S", "Beta Diversity",
# make first job
new = Job.create("18S", "Alpha Diversity",
self.options, Analysis(1))
self.assertEqual(new.id, 3)
# make sure job inserted correctly
obs = self.conn_handler.execute_fetchall("SELECT * FROM qiita.job "
"WHERE job_id = 3")
exp = [[3, 2, 2, 1, '{"option1":false,"option2":25,"option3":"NEW"}',
exp = [[3, 2, 1, 3, '{"option1":false,"option2":25,"option3":"NEW"}',
None]]
self.assertEqual(obs, exp)
# make sure job added to analysis correctly
Expand All @@ -68,12 +69,29 @@ def test_create(self):
exp = [[1, 3]]
self.assertEqual(obs, exp)

def test_create_exists(self):
"""Makes sure creation doesn't duplicate a job"""
with self.assertRaises(QiitaDBDuplicateError):
Job.create("16S", "Summarize Taxa",
{'option1': True, 'option2': 12, 'option3': 'FCM'},
Analysis(1))
# make second job with diff datatype and command to test column insert
new = Job.create("16S", "Beta Diversity",
self.options, Analysis(1))
self.assertEqual(new.id, 4)
# make sure job inserted correctly
obs = self.conn_handler.execute_fetchall("SELECT * FROM qiita.job "
"WHERE job_id = 4")
exp = [[4, 1, 1, 2, '{"option1":false,"option2":25,"option3":"NEW"}',
None]]
self.assertEqual(obs, exp)
# make sure job added to analysis correctly
obs = self.conn_handler.execute_fetchall("SELECT * FROM "
"qiita.analysis_job WHERE "
"job_id = 4")
exp = [[1, 4]]
self.assertEqual(obs, exp)

# def test_create_exists(self):
# """Makes sure creation doesn't duplicate a job"""
# with self.assertRaises(QiitaDBDuplicateError):
# Job.create("16S", "Summarize Taxa",
# {'option1': True, 'option2': 12, 'option3': 'FCM'},
# Analysis(1))

def test_retrieve_datatype(self):
"""Makes sure datatype retriveal is correct"""
Expand Down

0 comments on commit 432f2cc

Please sign in to comment.