-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_routes.py
38 lines (26 loc) · 1.17 KB
/
test_routes.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
from app import app
import json
from typing import Any
from werkzeug.test import TestResponse
def get_last_contact_id() -> int:
with open("contacts.json", "r") as contacts_file:
contacts: Any = json.load(contacts_file)
sorted_contacts: Any = sorted(contacts, key=lambda x: x["id"])
return sorted_contacts[-1]["id"]
def test_index() -> None:
response: TestResponse = app.test_client().get("/")
assert b"<sub-title>The Chapter 4 Demo</sub-title>" in response.data
def test_contacts_demo() -> None:
response: TestResponse = app.test_client().get("/contacts-demo")
assert response.data == b"You got contacts!"
def test_contacts_partial() -> None:
response: TestResponse = app.test_client().get("/contacts-partial")
assert (
b"<th>First</th> <th>Last</th> <th>Phone</th> <th>Email</th>" in response.data
)
def test_contacts_get() -> None:
response: TestResponse = app.test_client().get("/contacts")
assert b"<td>[email protected]</td>" in response.data
def test_contacts_post() -> None:
response: TestResponse = app.test_client().post("/contacts", data={"q": "Gross"})
assert b"<td>Gross</td>" in response.data