-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
30 lines (24 loc) · 829 Bytes
/
tests.py
File metadata and controls
30 lines (24 loc) · 829 Bytes
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
# coding: utf-8
from starlette.testclient import TestClient
from app import api, _STYLE_NAMES
def test_get_greeting():
with TestClient(api) as client:
rsp = client.get("/api/v1/greet?name=Barry")
assert rsp.status_code == 200
data = rsp.json()
assert 'Barry' in data['greeting']
assert data['name'] == 'Barry'
assert data['style'] in _STYLE_NAMES
def test_get_greeting_without_user_returns_422():
with TestClient(api) as client:
rsp = client.get("/api/v1/greet")
assert rsp.status_code == 422
assert rsp.json() == {
"detail": [
{
"loc": ["query", "name"],
"msg": "field required",
"type": "value_error.missing",
}
]
}