Skip to content

Commit a652aaa

Browse files
committed
feat(wip): add fastapi test
Signed-off-by: Sami Jaghouar <sami.jaghouar@hotmail.fr>
1 parent e7bd215 commit a652aaa

3 files changed

Lines changed: 140 additions & 27 deletions

File tree

poetry.lock

Lines changed: 107 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ common = ["protobuf"]
1717
torch = ["torch"]
1818

1919
[tool.poetry.dev-dependencies]
20-
pytest = "^5.2"
20+
pytest = "^6.1"
2121
pre-commit = "^2.20.0"
2222
jupyterlab = "^3.5.0"
2323
mypy = "^0.990"
@@ -29,6 +29,8 @@ ruff = "^0.0.117"
2929
[tool.poetry.group.dev.dependencies]
3030
fastapi = "^0.87.0"
3131
uvicorn = "^0.19.0"
32+
httpx = "^0.23.0"
33+
pytest-asyncio = "^0.20.2"
3234

3335
[build-system]
3436
requires = ["poetry-core>=1.0.0"]
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import pytest
2+
from fastapi import FastAPI
3+
from httpx import AsyncClient
4+
5+
from docarray import Document, Image, Text
6+
7+
8+
class Mmdoc(Document):
9+
img: Image
10+
text: Text
11+
title: str
12+
13+
14+
@pytest.mark.asyncio
15+
async def test_fast_api():
16+
17+
app = FastAPI()
18+
19+
@app.post("/doc/")
20+
async def create_item(doc: Mmdoc):
21+
return doc
22+
23+
async with AsyncClient(app=app, base_url="http://test") as ac:
24+
# response = await ac.get("/doc")
25+
response2 = await ac.get("/docs")
26+
27+
# assert response.status_code == 200
28+
assert response2.status_code == 200
29+
30+
# assert response.json() == {"message": "Tomato"}

0 commit comments

Comments
 (0)