def test_pull_task():
        test_app = TestApp(app)

        session = create_session()
        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})
        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'})
        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'
        session.add(task3)

        session.commit()

        test_app.get('/task/de305d54-75b4-431b-adb2-eb6b9e546018')
        test_app.get('/task/de305d54-75b4-431b-adb2-eb6b9e546019')
        test_app.get('/task/de305d54-75b4-431b-adb2-eb6b9e546020')
    def test_push_response():
        test_app = TestApp(app)
        session = create_session()
        task = Task()
        task.uuid = 'de305d54-75b4-431b-adb2-eb6b9e546013'
        task.test_id = 'de305d54-75b4-431b-adb2-eb6b9e546013'
        task.claimed = datetime.utcnow()
        session.add(task)
        session.commit()
        test_app.post_json(
            '/tasks/response', {
                'protocol': 1,
                'task_id': 'de305d54-75b4-431b-adb2-eb6b9e546013',
                'task_data': {
                    'key': 'value',
                    'another_key': 5
                }
            })

        session = create_session()
        task = session.query(Task).filter(
            Task.uuid == 'de305d54-75b4-431b-adb2-eb6b9e546013').one()

        assert task.completed is not None
        assert task.result_data is not None
        assert task.failed is None
        assert task.error is None

        task.completed = None
        task.result_data = None
        session.commit()
        test_app.post_json(
            '/tasks/response', {
                'protocol': 1,
                'task_id': 'de305d54-75b4-431b-adb2-eb6b9e546013',
                'task_error': 'Something went terribly wrong'
            })

        session = create_session()
        task = 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

        session.close()
    def test_push_response():
        test_app = TestApp(app)
        session = create_session()
        task = Task()
        task.uuid = 'de305d54-75b4-431b-adb2-eb6b9e546013'
        task.test_id = 'de305d54-75b4-431b-adb2-eb6b9e546013'
        task.claimed = datetime.utcnow()
        session.add(task)
        session.commit()
        test_app.post_json('/tasks/response', {
            'protocol': 1,
            'task_id': 'de305d54-75b4-431b-adb2-eb6b9e546013',
            'task_data': {
                'key': 'value',
                'another_key': 5
            }
        })

        session = create_session()
        task = session.query(Task).filter(Task.uuid == 'de305d54-75b4-431b-adb2-eb6b9e546013').one()

        assert task.completed is not None
        assert task.result_data is not None
        assert task.failed is None
        assert task.error is None

        task.completed = None
        task.result_data = None
        session.commit()
        test_app.post_json('/tasks/response', {
            'protocol': 1,
            'task_id': 'de305d54-75b4-431b-adb2-eb6b9e546013',
            'task_error': 'Something went terribly wrong'
        })

        session = create_session()
        task = 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

        session.close()