blob: ab3b16a0177e5009319d482b7f6a14962cda5727 (
plain)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
#!/usr/bin/env python3
import logging
import sys
import uuid
from typing import Dict, List, Optional
import requests
BASE_URL = "http://localhost:8888"
POSTS_URL = f"{BASE_URL}/posts"
DELETE_UUID = "00000000-0000-dddd-0000-000000000000"
POST_UUID = "6d011855-6b0d-4202-a243-4d9db9807f14"
BAD_UUID = "00000000-0000-1111-0000-000000000000"
INVALID_UUID = "0"
JSON_ACCEPT_HEADER = {"Accept": "application/json"}
log = logging.getLogger(__name__)
log.setLevel(logging.INFO)
def test_redirect():
url = f"{BASE_URL}/asdf"
r = requests.get(url, allow_redirects=False)
assert r.status_code == 307
assert r.headers["Location"] == "/"
def test_html_get_post():
url = f"{POSTS_URL}/{POST_UUID}"
r = requests.get(url)
assert r.status_code == 200
text = r.text
assert "A Solid Breakdown of the Linux Font Rendering Stack" in text
assert "hinting and anti-aliasing" in text
assert "Debugging CGI / CGit" not in text
def test_html_get_base_url():
url = BASE_URL
r = requests.get(url)
assert r.status_code == 200
text = r.text
assert "A Solid Breakdown of the Linux Font Rendering Stack" in text
assert "hinting and anti-aliasing" in text
assert "Debugging CGI / CGit" in text
def test_html_get_posts():
url = POSTS_URL
r = requests.get(url)
assert r.status_code == 200
text = r.text
assert "A Solid Breakdown of the Linux Font Rendering Stack" in text
assert "hinting and anti-aliasing" in text
assert "Debugging CGI / CGit" in text
def test_html_get_post_not_found():
url = f"{POSTS_URL}/{BAD_UUID}"
r = requests.get(url)
assert r.status_code == 404
text = r.text
assert "Resource not found" in text
url = f"{POSTS_URL}/{INVALID_UUID}"
r = requests.get(url)
assert r.status_code == 404
text = r.text
assert "Resource not found" in text
def main():
winner = True
for func in dir(sys.modules[__name__]):
if func.startswith("test_"):
try:
globals()[func]()
except Exception as e:
winner = False
log.exception(f"🚫 {func} failed {e} 🚫")
print(f"🚫 {func} failed {e} 🚫")
if winner:
log.info("🏆 You're winner !")
print("🏆 You're winner !")
if __name__ == "__main__":
main()
|