-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_app.py
61 lines (43 loc) · 1.48 KB
/
test_app.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import pytest
from src.app import app
from src.process_query import process_query
def test_knows_about_dinosaurs():
expected = "Dinosaurs ruled the Earth 200 million years ago"
assert process_query("dinosaurs") == expected
def test_does_not_know_about_asteroids():
assert process_query("asteroids") == "Unknown"
def test_what_is_your_name():
assert process_query("What is your name?") == "SiCi"
@pytest.fixture
def client():
with app.test_client() as client:
yield client
def test_hello_world(client):
response = client.get("/")
assert response.status_code == 200
def test_submit_happy(client):
response = client.post("/submit", data={
"name": "Alice",
"age": "30",
"gender": "female",
"happy": "5"
})
assert response.status_code == 200
assert b"Hello Alice" in response.data
def test_submit_sad(client):
response = client.post("/submit", data={
"name": "Bob",
"age": "25",
"gender": "male",
"happy": "-1"
})
assert response.status_code == 200
assert b"Hello Bob" in response.data
def test_query(client):
response = client.get("/query", query_string={"q": "dinosaurs"})
assert response.status_code == 200
assert b"Dinosaurs ruled the Earth 200 million years ago" in response.data
def test_query_unknown(client):
response = client.get("/query", query_string={"q": "asteroid"})
assert response.status_code == 200
assert b"Unknown" in response.data