Skip to content

Commit

Permalink
improve testing
Browse files Browse the repository at this point in the history
  • Loading branch information
aniketmaurya committed Dec 16, 2023
1 parent f7d3a2a commit 8e4383d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/fastserve/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
"""A Python Project"""
from .base_fastserve import FastServe

__version__ = "0.0.1"
6 changes: 6 additions & 0 deletions src/fastserve/base_fastserve.py → src/fastserve/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,9 @@ def run_server(
import uvicorn

uvicorn.run(self._app)

@property
def test_client(self):
from fastapi.testclient import TestClient

return TestClient(self._app)
28 changes: 28 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import pytest
from fastserve import FastServe
from fastserve.core import BaseRequest


class FakeServe(FastServe):
def handle(self, batch):
return [1] * len(batch)


def test_handle():
serve = FastServe()
batch = [BaseRequest(request=1), BaseRequest(request=2)]
with pytest.raises(NotImplementedError):
serve.handle(batch)

serve = FakeServe()
assert serve.handle(batch) == [1, 1]


def test_run_server():
serve = FakeServe()
serve._serve()
test_client = serve.test_client
data = BaseRequest(request=1).model_dump_json()
response = test_client.post("/endpoint", data=data)
assert response.status_code == 200
assert response.json() == 1

0 comments on commit 8e4383d

Please sign in to comment.