-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
33 lines (26 loc) · 972 Bytes
/
test.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
32
33
from flaskapp import app
import pytest
@pytest.fixture
def client():
with app.test_client() as client:
yield client
def test_index(client):
response = client.get('/')
assert response.status_code == 200
assert b"Welcome to the API!" in response.data
def test_search_success(client):
response = client.get('/search?person=John')
assert response.status_code == 200
assert response.is_json
assert response.json == {"id": 1, "name": "John", "age": 25}
def test_search_failure(client):
response = client.get('/search?person=Mary')
assert response.status_code == 400
assert response.is_json
assert response.json == {"error": "No matching data found."}
def test4():
response = app.test_client().get("/search?person=Ducanh")
# assert b'{"error":"No matching data found."}\n' in response.data
assert response.status_code == 400
response = app.test_client().get('/search?person=ducanh')
print(response.data)