def test_display(self): """Test if displaying jobs works as expected""" rv = self.client.get('/display/invalid') self.assert404(rv) j = Job() redis_store = self._ctx.g._database redis_store.hmset(u"job:%s" % j.uid, j.get_dict()) rv = self.client.get('/display/%s' % j.uid) assert "Status of job" in rv.data
def status(task_id): redis_store = get_db() res = redis_store.hgetall(u'job:%s' % task_id) if res == {}: abort(404) job = Job(**res) if job.status == 'done': result_url = "%s/%s" % (app.config['RESULTS_URL'], job.uid) if job.jobtype == 'antismash': result_url += "/display.xhtml" else: result_url += "/index.html" res['result_url'] = result_url res['short_status'] = job.get_short_status() return jsonify(res)
def test_job_get_status(self): """Test that Job.get_status() is sane""" job = Job() assert job.get_status() == 'pending' assert job.status == job.get_status() job = Job(status='funky') assert job.get_status() == 'funky'
def display(task_id): redis_store = get_db() results_path = app.config['RESULTS_URL'] res = redis_store.hgetall(u'job:%s' % task_id) if res == {}: abort(404) else: job = Job(**res) return render_template('display.html', job=job, results_path=results_path)
def _get_oldest_job(queue): """Get the oldest job in a queue""" redis_store = get_db() try: res = redis_store.hgetall("job:%s" % redis_store.lrange(queue, -1, -1)[0]) except IndexError: return None return Job(**res)
def test_submit_job_download(self): """Test if submitting a job with a downloaded sequence works""" data = dict(ncbi='TESTING', cluster_1=u'on') rv = self.client.post('/', data=data, follow_redirects=True) assert "Status of job" in rv.data redis_store = self._ctx.g._database job_id = redis_store.keys('job:*')[0] res = redis_store.hgetall(job_id) assert res != {} j = Job(**res) assert j is not None self.assertEquals(j.download, 'TESTING')
def new(): redis_store = get_db() error = None results_path = app.config['RESULTS_URL'] old_email = '' try: if request.method == 'POST': kwargs = {} kwargs['ncbi'] = request.form.get('ncbi', '').strip() kwargs['email'] = request.form.get('email', '').strip() old_email = kwargs['email'] # This webapi is for plantiSMASH, so create plantiSMASH jobs kwargs['jobtype'] = 'plantismash' clusterblast = request.form.get('clusterblast', u'off') knownclusterblast = request.form.get('knownclusterblast', u'off') subclusterblast = request.form.get('subclusterblast', u'off') fullhmmer = request.form.get('fullhmmer', u'off') coexpress_mad = request.form.get('coexpress_mad', u'') kwargs['cdh_cutoff'] = request.form.get('cdh_cutoff', 0.5, type=float) kwargs['min_domain_number'] = request.form.get('min_domain_number', 2, type=int) # Use boolean values instead of "on/off" strings kwargs['clusterblast'] = (clusterblast == u'on') kwargs['knownclusterblast'] = (knownclusterblast == u'on') try: kwargs['min_mad'] = int(coexpress_mad) except ValueError: pass job = Job(**kwargs) dirname = path.join(app.config['RESULTS_PATH'], job.uid) os.mkdir(dirname) upload = None if kwargs['ncbi'] != '': job.download = kwargs['ncbi'] else: upload = request.files['seq'] if upload is not None: filename = secure_filename(upload.filename) upload.save(path.join(dirname, filename)) if not path.exists(path.join(dirname, filename)): raise Exception("Could not save file!") job.filename = filename else: raise Exception("Uploading input file failed!") if 'gff' in request.files: gff = request.files['gff'] if gff is not None and gff.filename != '': filename = secure_filename(gff.filename) gff.save(path.join(dirname, filename)) if not path.exists(path.join(dirname, filename)): raise Exception("Could not save file!") job.gff3 = filename if 'coexpress_file' in request.files: coexpress_file = request.files['coexpress_file'] if coexpress_file is not None and coexpress_file.filename != '': filename = secure_filename(coexpress_file.filename) coexpress_file.save(path.join(dirname, filename)) if not path.exists(path.join(dirname, filename)): raise Exception("Could not save file!") job.coexpress = True _, ext = path.splitext(filename) if ext.lower() == '.soft': job.soft_file = filename elif ext.lower() == '.csv': job.csv_file = filename else: job.coexpress = False _submit_job(redis_store, job) return redirect(url_for('.display', task_id=job.uid)) except Exception as e: error = unicode(e) return render_template('new.html', error=error, old_email=old_email, results_path=results_path)
def test_job_instantiate(self): """Test if job can be instantiated""" job = Job() assert job is not None
def test_job_jobtype_default(self): """Test that Job.jobtype is 'antismash' if not specified""" job = Job() assert job.jobtype == "antismash"
def test_job_email(self): """Test that Job.email returns the correct value""" job = Job(email="*****@*****.**") assert job.email == "*****@*****.**"
def test_job_get_short_status(self): """Test that Job.get_short_status() is sane""" job = Job(status='pending: Waiting for Godot') assert job.get_short_status() == 'pending'
def test_job_repr(self): """Test that the repr matches the job data""" job = Job() assert job.uid in str(job) assert job.status in str(job)
def test_job_unique_uid(self): """Test if two different job objects get different uids""" first = Job() second = Job() assert first.uid != second.uid