Exemplo n.º 1
0
async def test_ping():
    async with httpx.AsyncClient(app=app, base_url="http://test") as client:
        url = app.url_path_for("ping")
        response = await client.get(url)
        assert response.status_code == 200
        data = response.json()
        assert data["message"] == "Ping"
Exemplo n.º 2
0
def test_search_basic_sync(load_books):
    client = TestClient(app)
    url = app.url_path_for("search")
    params = urlencode({"q": "Susan Collins"})
    response = client.get(f"{url}?{params}")
    assert response.status_code == 200
    data = response.json()
    assert data["results"]
    assert data["count"] == 3
    assert [row["book_id"] for row in data["results"]] == [1, 17, 20]
    for row in data["results"]:
        assert row["title"]
        assert row["isbn13"]
Exemplo n.º 3
0
async def test_search_tags(load_books):
    async with httpx.AsyncClient(app=app, base_url="http://test") as client:
        url = app.url_path_for("search")
        params = urlencode({"tags": ["between-film", "address-year"]})
        response = await client.get(f"{url}?{params}")
        assert response.status_code == 200
        data = response.json()
        assert data["results"]
        assert data["count"] == 4
        assert [row["book_id"] for row in data["results"]] == [1, 2, 67, 90]
        for row in data["results"]:
            assert row["title"]
            assert row["isbn13"]
Exemplo n.º 4
0
async def test_search_year(load_books):
    async with httpx.AsyncClient(app=app, base_url="http://test") as client:
        url = app.url_path_for("search")
        params = urlencode({"year": 2008})
        response = await client.get(f"{url}?{params}")
        assert response.status_code == 200
        data = response.json()
        assert data["results"]
        assert data["count"] == 4
        assert [row["book_id"] for row in data["results"]] == [1, 56, 73, 88]
        for row in data["results"]:
            assert row["title"]
            assert row["isbn13"]