-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_api.py
31 lines (21 loc) · 967 Bytes
/
test_api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from fastapi.testclient import TestClient
from main import app
from pydantic import BaseModel
class TranslationRequest(BaseModel):
text: str
client = TestClient(app)
def test_hello():
translation_request = TranslationRequest(text='Один')
response = client.post("/translate", json=translation_request.dict())
assert response.status_code == 200
assert response.json()["translation"].replace(".", "") == "One"
def test_cat():
translation_request = TranslationRequest(text='Десять')
response = client.post("/translate", json=translation_request.dict())
assert response.status_code == 200
assert response.json()["translation"].replace(".", "") == "Ten"
def test_dog():
translation_request = TranslationRequest(text='Собака')
response = client.post("/translate", json=translation_request.dict())
assert response.status_code == 200
assert response.json()["translation"].replace(".", "") == "Dog"