Esempio n. 1
0
def response(uuid):
    status = htq.status(uuid)

    if not status:
        abort(404)

    # Block until ready
    while True:
        # Poll status until it is complete
        if status not in {htq.QUEUED, htq.PENDING}:
            break

        time.sleep(0.1)
        status = htq.status(uuid)

    rp = htq.response(uuid) or {}

    resp = make_response(json.dumps(rp), 200)
    resp.headers['Content-Type'] = 'application/json'
    resp.headers['Link'] = build_link_header({
        url_for('response', uuid=uuid, _external=True): {
            'rel': 'self',
        },
        url_for('request', uuid=uuid, _external=True): {
            'rel': 'request',
        },
    })

    return resp
Esempio n. 2
0
def response(uuid):
    status = htq.status(uuid)

    if not status:
        abort(404)

    # Block until ready
    while True:
        # Poll status until it is complete
        if status not in {htq.QUEUED, htq.PENDING}:
            break

        time.sleep(0.1)
        status = htq.status(uuid)

    rp = htq.response(uuid) or {}

    resp = make_response(json.dumps(rp), 200)
    resp.headers['Content-Type'] = 'application/json'
    resp.headers['Link'] = build_link_header({
        url_for('response', uuid=uuid, _external=True): {
            'rel': 'self',
        },
        url_for('request', uuid=uuid, _external=True): {
            'rel': 'request',
        },
    })

    return resp
Esempio n. 3
0
    def test_purge(self):
        htq.send(url)
        uuid = htq.pop()

        htq.receive(uuid)
        htq.purge(uuid)

        resp = htq.response(uuid)
        self.assertIsNone(resp)
Esempio n. 4
0
    def test_purge(self):
        htq.send(url)
        uuid = htq.pop()

        htq.receive(uuid)
        htq.purge(uuid)

        resp = htq.response(uuid)
        self.assertIsNone(resp)
Esempio n. 5
0
    def test_cancel_complete(self):
        htq.send(url)
        uuid = htq.pop()

        htq.receive(uuid)

        # Cancel will change the state and delete the response
        htq.cancel(uuid)

        req = htq.request(uuid)
        resp = htq.response(uuid)
        self.assertEqual(req['status'], htq.CANCELED)
        self.assertIsNone(resp)
Esempio n. 6
0
    def test_cancel_complete(self):
        htq.send(url)
        uuid = htq.pop()

        htq.receive(uuid)

        # Cancel will change the state and delete the response
        htq.cancel(uuid)

        req = htq.request(uuid)
        resp = htq.response(uuid)
        self.assertEqual(req['status'], htq.CANCELED)
        self.assertIsNone(resp)
Esempio n. 7
0
    def test_cancel_queued(self):
        htq.send(url)
        uuid = htq.pop()

        # Cancel while queued
        htq.cancel(uuid)

        # Receive has not effect
        htq.receive(uuid)

        req = htq.request(uuid)
        resp = htq.response(uuid)
        self.assertEqual(req['status'], htq.CANCELED)
        self.assertIsNone(resp)
Esempio n. 8
0
    def test_cancel_queued(self):
        htq.send(url)
        uuid = htq.pop()

        # Cancel while queued
        htq.cancel(uuid)

        # Receive has not effect
        htq.receive(uuid)

        req = htq.request(uuid)
        resp = htq.response(uuid)
        self.assertEqual(req['status'], htq.CANCELED)
        self.assertIsNone(resp)
Esempio n. 9
0
    def test_send_receive(self):
        # Send (queue) a request
        htq.send(url)
        self.assertEqual(htq.size(), 1)

        # Pop off UUID for receiving
        uuid = htq.pop()
        self.assertEqual(htq.size(), 0)

        # Actually send request/get response
        htq.receive(uuid)

        # Check states
        req = htq.request(uuid)
        resp = htq.response(uuid)

        self.assertEqual(req['status'], htq.SUCCESS)
        self.assertEqual(resp['code'], 200)
        self.assertEqual(resp['data'], '{"ok": 1}')
        self.assertEqual(resp['headers'], {
            'Content-Type': 'application/json',
        })
Esempio n. 10
0
    def test_send_receive(self):
        # Send (queue) a request
        htq.send(url)
        self.assertEqual(htq.size(), 1)

        # Pop off UUID for receiving
        uuid = htq.pop()
        self.assertEqual(htq.size(), 0)

        # Actually send request/get response
        htq.receive(uuid)

        # Check states
        req = htq.request(uuid)
        resp = htq.response(uuid)

        self.assertEqual(req['status'], htq.SUCCESS)
        self.assertEqual(resp['code'], 200)
        self.assertEqual(resp['data'], '{"ok": 1}')
        self.assertEqual(resp['headers'], {
            'Content-Type': 'application/json',
        })