Skip to content

Commit

Permalink
tests for fast api
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriihavrylko committed Jan 9, 2024
1 parent 45b87f0 commit ad697d9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ scikit-learn==1.3.2
accelerate==0.25.0
datasets==2.16.1
wandb==0.16.1
httpx==0.26.0
27 changes: 27 additions & 0 deletions app/tests/serving/test_fastapi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from fastapi.testclient import TestClient

from unittest.mock import Mock
from src.serving.model import BertPredictor

def mock_predict(text):
return ['positive' for _ in text]

BertPredictor.from_model_registry = Mock(return_value=Mock(predict=mock_predict))



def test_predict():
from src.serving.fastapi import app
client = TestClient(app)

payload = {
"text": ["This is a test sentence.", "Here's another one!"]
}

response = client.post("/predict", json=payload)

assert response.status_code == 200

data = response.json()
assert isinstance(data, list)
assert len(data) == len(payload['text'])

0 comments on commit ad697d9

Please sign in to comment.