Example #1
0
    def test_response(self):
        resp = app.post('/',
                        data=json.dumps({
                            'url': url,
                        }),
                        headers={'content-type': 'application/json'})

        location = resp.location

        # Receive response..
        htq.receive(htq.pop())

        resp = app.get(location)

        self.assertIn('response', resp.headers['Link'])

        links = parse_header_links(resp.headers['Link'])
        response_url = links['response']

        resp = app.get(response_url)
        self.assertEqual(resp.status_code, 200)

        resp = app.delete(response_url)
        self.assertEqual(resp.status_code, 204)

        resp = app.delete(response_url)
        self.assertEqual(resp.status_code, 404)
Example #2
0
    def test_response(self):
        resp = app.post('/', data=json.dumps({
            'url': url,
        }), headers={'content-type': 'application/json'})

        location = resp.location

        # Receive response..
        htq.receive(htq.pop())

        resp = app.get(location)

        self.assertIn('response', resp.headers['Link'])

        links = parse_header_links(resp.headers['Link'])
        response_url = links['response']

        resp = app.get(response_url)
        self.assertEqual(resp.status_code, 200)

        resp = app.delete(response_url)
        self.assertEqual(resp.status_code, 204)

        resp = app.delete(response_url)
        self.assertEqual(resp.status_code, 404)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #9
0
    def test_post(self):
        htq.send(url, 'post', data='{"foo": 1}', headers={
            'Content-Type': 'application/json',
        })

        uuid = htq.pop()
        resp = htq.receive(uuid)

        self.assertEqual(resp['status'], htq.SUCCESS)
Example #10
0
    def test_error(self):
        htq.send('http://localhost:9999')

        uuid = htq.pop()

        resp = htq.receive(uuid)
        req = htq.request(uuid)

        self.assertEqual(resp['status'], htq.ERROR)
        self.assertEqual(req['status'], htq.ERROR)
Example #11
0
    def test_error(self):
        htq.send('http://localhost:9999')

        uuid = htq.pop()

        resp = htq.receive(uuid)
        req = htq.request(uuid)

        self.assertEqual(resp['status'], htq.ERROR)
        self.assertEqual(req['status'], htq.ERROR)
Example #12
0
def run(n):
    responses.add(responses.GET,
                  url=re.compile(r'http://localhost/\d+'),
                  body='{"ok": 1}',
                  status=200,
                  content_type='application/json')

    t0 = time.time()

    for i in range(n):
        htq.send('http://localhost/' + str(i))

    print('sent {} in {}'.format(n, time.time() - t0))

    t0 = time.time()

    for i in range(n):
        uuid = htq.pop()
        htq.receive(uuid)

    print('received {} in {}'.format(n, time.time() - t0))
Example #13
0
    def test_post(self):
        htq.send(url,
                 'post',
                 data='{"foo": 1}',
                 headers={
                     'Content-Type': 'application/json',
                 })

        uuid = htq.pop()
        resp = htq.receive(uuid)

        self.assertEqual(resp['status'], htq.SUCCESS)
Example #14
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',
        })
Example #15
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',
        })