def db_seed(): currenttime = datetime.now() endtime = currenttime + timedelta(seconds=600) tsk1 = Task(name='Cook Eggs', description='Cooking eggs for the family', priority=1, status='ACTIVE', starttime=currenttime, currenttime=currenttime, createdtime=currenttime, endtime=endtime) tsk2 = Task(name='Boil Water', description='Heating up water on the stove', priority=3, status='PENDING', starttime=currenttime, currenttime=currenttime, createdtime=currenttime, endtime=endtime) rds.session.add(tsk1) rds.session.add(tsk2) rds.session.commit() print('Database seeded')
def _load_from_db(self): """Loads the state data from the database.""" result = Task.query.filter_by(task_id=self.task_id).first() if not result: if self.flag_server_debug: task = Task(task_id=self.task_id, state=json.dumps({ 'task_id': self.task_id, 'pipeline': PipelineHelper.encode(GetPipeline()) })) else: task = Task(task_id=self.task_id, state=json.dumps({ 'task_id': self.task_id, 'pipeline': PipelineHelper.encode(GetMturkPipeline()) })) db.session.add(task) db.session.commit() self._load_from_db() else: self.data = json.loads(result.state)
def test_task_endpoint(self): clear_tasks() self.assertTrue(len(Task.query.all()) == 0) # Add 2 dummy tasks test1 = Task(title="test1", description="abcdefg") test2 = Task(title="test2", description="hijklmnop") db.session.add(test1) db.session.add(test2) db.session.commit() response = self.tester.get('/task/{}'.format(test2.id), content_type='html/text') # Check for dummy task in response self.assertTrue('"description": "hijklmnop"' in response.data) self.assertTrue('"title": "test2"' in response.data)
def setUp(self): db.create_all() # sample data test_task = Task(task_name="buy milk") db.session.add(test_task) db.session.commit()
def test_delete_task_endpoint(self): clear_tasks() self.assertTrue(len(Task.query.all()) == 0) # Add 2 dummy tasks random_task = Task(title="Random task", description="abcdefg") task_to_delete = Task(title="Delete Me", description="hijklmnop") db.session.add(random_task) db.session.add(task_to_delete) db.session.commit() response = self.tester.delete('/task/{}'.format(task_to_delete.id)) updated_tasks = Task.query.all() self.assertTrue(len(updated_tasks) == 1) self.assertTrue(updated_tasks[0].title == "Random task") self.assertTrue(updated_tasks[0].description == "abcdefg")
def test_update_task_endpoint(self): clear_tasks() self.assertTrue(len(Task.query.all()) == 0) # Add 2 dummy tasks random_test = Task(title="test1", description="abcdefg") task_to_update = Task(title="test2", description="hijklmnop") db.session.add(random_test) db.session.add(task_to_update) db.session.commit() response = self.tester.put('/task/{}'.format(task_to_update.id), data=json.dumps({ 'title': "New title", 'description': "I changed this" }), content_type='application/json') test_task = Task.query.filter_by(title="New title").first() self.assertTrue(test_task.title == "New title") self.assertTrue(test_task.description == "I changed this")
def test_all_tasks_endpoint(self): clear_tasks() self.assertTrue(len(Task.query.all()) == 0) # Add a dummy task test = Task(title="test", description="does this work?") db.session.add(test) db.session.commit() response = self.tester.get('/tasks', content_type='html/text') # Check for dummy task in response self.assertTrue('"description": "does this work?"' in response.data) self.assertTrue('"title": "test"' in response.data)
def consignor(): """Consignor view.""" if not current_user.is_consignor(): return redirect('/') form = ConsignorTaskForm() if request.method == 'POST' and form.validate_on_submit(): comment = request.form.get('comment') price = request.form.get('price') task = Task(comment=comment, price=price) consignor_task = ConsignorTask(user=current_user, task=task) db.session.add(task) db.session.add(consignor_task) db.session.commit() consignor_tasks = ConsignorTask.query.filter_by(user_id=current_user.id) return render_template('consignor.html', form=form, consignor_tasks=consignor_tasks)
from app import db, Task, Revision newTask = Task()
def test_outputs_contain_resources(self): context = Context(self.DAG_ID) task = Task(context) outputs = task.execute(self.INPUTS) assert isinstance(outputs[0]["job_data"]["resources"], list)
def test_outputs_contain_params(self): context = Context(self.DAG_ID) task = Task(context) outputs = task.execute(self.INPUTS) assert outputs[0]["job_data"]["params"]
def test_outputs_contain_job_data(self): context = Context(self.DAG_ID) task = Task(context) outputs = task.execute(self.INPUTS) assert outputs[0]["job_data"] assert isinstance(outputs[0]["job_data"], dict)
def test_outputs_contain_job_id(self): context = Context(self.DAG_ID) task = Task(context) outputs = task.execute(self.INPUTS) assert outputs[0]["job_id"] == self.JOB_ID
def test_outputs_outputs_length_over_one(self): context = Context(self.DAG_ID) task = Task(context) outputs = task.execute(self.INPUTS) assert isinstance(outputs, list) assert len(outputs) >= 1
def test_if_execute_method_exist(self): context = Context(self.DAG_ID) task = Task(context) task.execute([])
from app import db, Task db.create_all() first_task = Task(title="Set up db", description="Get Postgres up and running!") db.session.add(first_task) db.session.commit()