-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_routes.py
26 lines (18 loc) · 848 Bytes
/
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
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'<li><a href="mailto:[email protected]">Joe</a></li>' in response.data