def test_pull_task(self): task1 = Task() task1.uuid = 'de305d54-75b4-431b-adb2-eb6b9e546018' task1.test_id = 'de305d54-75b4-431b-adb2-eb6b9e546018' task1.claimed = datetime.utcnow() task1.data = json.dumps({'wait_time': 123}) db.session.add(task1) task2 = Task() task2.uuid = 'de305d54-75b4-431b-adb2-eb6b9e546019' task2.test_id = 'de305d54-75b4-431b-adb2-eb6b9e546019' task2.claimed = datetime.utcnow() task2.completed = datetime.utcnow() task2.result_data = json.dumps({'result': 'epic success'}) db.session.add(task2) task3 = Task() task3.uuid = 'de305d54-75b4-431b-adb2-eb6b9e546020' task3.test_id = 'de305d54-75b4-431b-adb2-eb6b9e546020' task3.claimed = datetime.utcnow() task3.failed = datetime.utcnow() task3.error = 'unknown error' db.session.add(task3) db.session.commit() self.test_app.get('/task/de305d54-75b4-431b-adb2-eb6b9e546018') self.test_app.get('/task/de305d54-75b4-431b-adb2-eb6b9e546019') self.test_app.get('/task/de305d54-75b4-431b-adb2-eb6b9e546020')
def test_push_response(self): task = Task() task.uuid = 'de305d54-75b4-431b-adb2-eb6b9e546013' task.test_id = 'de305d54-75b4-431b-adb2-eb6b9e546013' task.claimed = datetime.utcnow() db.session.add(task) db.session.commit() r = self.test_app.post_json('/tasks/response', { 'protocol': 1, 'task_id': 'de305d54-75b4-431b-adb2-eb6b9e546013', 'task_data': { 'key': 'value', 'another_key': 5 } }) print(r) task = db.session.query(Task).filter(Task.uuid == 'de305d54-75b4-431b-adb2-eb6b9e546013').one() self.assertIsNotNone(task.completed) self.assertIsNotNone(task.completed) self.assertIsNotNone(task.result_data) self.assertIsNone(task.failed) self.assertIsNone(task.error) task.completed = None task.result_data = None db.session.commit() self.test_app.post_json('/tasks/response', { 'protocol': 1, 'task_id': 'de305d54-75b4-431b-adb2-eb6b9e546013', 'task_error': 'Something went terribly wrong' }) task = db.session.query(Task).filter(Task.uuid == 'de305d54-75b4-431b-adb2-eb6b9e546013').one() assert task.completed is None assert task.result_data is None assert task.failed is not None assert task.error is not None