def test_queue_view_tasks(self): url, _ = yield from self.create_server() t1 = Task("test_task", [1, 2, 3], "pool", [1], {}) t2 = Task("test_task", [1, 2, 3], "pool", [1], {}) r = yield from client.post("{}/task".format(url), data=json.dumps(t1.for_json()), loop=self.loop) data = yield from r.json() assert r.status == 200 assert data["result"] == "success" r = yield from client.post("{}/task".format(url), data=json.dumps(t2.for_json()), loop=self.loop) data = yield from r.json() assert r.status == 200 assert data["result"] == "success" r = yield from client.get("{}/task".format(url), loop=self.loop) assert r.status == 200 data = yield from r.json() assert len(data) == 2 r = yield from client.get("{}/task".format(url), params={"limit": 1}, loop=self.loop) assert r.status == 200 data = yield from r.json() assert len(data) == 1 assert data[0]["id"] == str(t1.id) r = yield from client.get("{}/task".format(url), params={"offset": 1}, loop=self.loop) assert r.status == 200 data = yield from r.json() assert len(data) == 1 assert data[0]["id"] == str(t2.id)
def test_queue_add_unique_not_equal(self): url, _ = yield from self.create_server() t = Task("test_task", [1, 2, 3], "pool", [1], {}) t2 = Task("test_task", [1, 2, 3, 4], "pool", [1], {}) r = yield from client.post("{}/task".format(url), data=json.dumps(t.for_json()), loop=self.loop) data = yield from r.json() assert r.status == 200 assert data["result"] == "success" r = yield from client.post( "{}/task".format(url), data=json.dumps(t2.for_json()), loop=self.loop, params={"unique": "true"} ) data = yield from r.json() assert r.status == 200 assert data["result"] == "success" r = yield from client.options("{}/".format(url), data=json.dumps(t.for_json()), loop=self.loop) data = yield from r.json() assert r.status == 200 assert data["tasks"]["pending"] == 2 r = yield from client.get("{}/".format(url), data=json.dumps(t.for_json()), loop=self.loop) data = yield from r.json() assert r.status == 200 assert len(data["tasks"]["pending"]) == 2
def test_tcp_connector(test_client, loop): @asyncio.coroutine def handler(request): return web.HTTPOk() app = web.Application(loop=loop) app.router.add_get('/', handler) client = yield from test_client(app) r = yield from client.get('/') assert r.status == 200
def test_handle_request(self): url, _ = yield from self.create_server() r = yield from client.options("{}/".format(url), loop=self.loop) data = yield from r.json() assert data["tasks"]["pending"] == 0 assert data["tasks"]["active"] == 0 assert data["locks"] == 0 r = yield from client.get("{}/".format(url), loop=self.loop) data = yield from r.json() assert len(data["tasks"]["pending"]) == 0 assert len(data["tasks"]["active"]) == 0 assert len(data["locks"]) == 0