-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathtest_examples.py
More file actions
87 lines (65 loc) · 2.41 KB
/
Copy pathtest_examples.py
File metadata and controls
87 lines (65 loc) · 2.41 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from application import app
def f():
return 3
def test_function():
assert f() == 3
def test_home_page():
"""
GIVEN a Flask application configured for testing
WHEN the '/' page is requested (GET)
THEN check that the response is valid
"""
# Create a test client using the Flask application configured for testing
with app.test_client() as test_client:
response = test_client.get('/home')
assert response.status_code == 200
assert b"Simple Python Web App" in response.data
assert b"Flask web microframework" in response.data
assert b"Version" in response.data
def test_welcome_page():
"""
GIVEN a Flask application configured for testing
WHEN the '/welcome/bob' page is requested (GET)
THEN check that the response is valid
"""
with app.test_client() as test_client:
response = test_client.get('/welcome/bob')
assert response.status_code == 200
assert b"Hello Bob." in response.data
assert b"Welcome Everyone!" in response.data
assert b"Version" in response.data
def test_welcome_page_with_team():
"""
GIVEN a Flask application configured for testing
WHEN the '/welcome/team' page is requested (GET)
THEN check that the response is valid
"""
with app.test_client() as test_client:
response = test_client.get('/welcome/team')
assert response.status_code == 200
assert b"Hello Team." in response.data
assert b"Welcome Everyone!" in response.data
assert b"Version" in response.data
def test_jokes_page():
"""
GIVEN a Flask application configured for testing
WHEN the '/joke' page is requested (GET)
THEN check that the response is valid
"""
with app.test_client() as test_client:
response = test_client.get('/joke')
assert response.status_code == 200
assert b"Tell me a joke" in response.data
assert b"Tell me another" in response.data
assert b"Version" in response.data
def test_joke_count():
"""
GIVEN a Flask application configured for testing
WHEN the '/joke' page is requested (GET)
THEN check that the correct number of jokes is displayed
"""
with app.test_client() as test_client:
response = test_client.get('/joke')
assert response.status_code == 200
assert b"Number of jokes" in response.data
assert b"21" in response.data