-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_hosting.py
91 lines (69 loc) · 2.55 KB
/
test_hosting.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
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
import os
from pathlib import Path
import requests
BASE_URL = os.environ.get("BASE_URL", "https://thatsgroce.web.app")
BUILD_ROOT = Path("build")
def get(uri, *args, **kwargs):
url = BASE_URL + uri
return requests.get(url, *args, **kwargs)
def test_index_html():
r = get("/")
assert r.status_code == 200
assert r.headers["content-type"] == "text/html; charset=utf-8"
def test_about():
r = get("/about")
assert r.status_code == 200
assert r.headers["content-type"] == "text/html; charset=utf-8"
assert "<title>About That" in r.text
def test_shopping():
r = get("/shopping")
assert r.status_code == 200
assert r.headers["content-type"] == "text/html; charset=utf-8"
assert "<title>That" in r.text
def test_version_page():
r = get("/version")
assert r.status_code == 200
assert r.headers["content-type"] == "text/html; charset=utf-8"
def test_shopping_list():
r = get("/shopping/xyz")
assert r.status_code == 200
assert r.headers["content-type"] == "text/html; charset=utf-8"
assert "<title>That" in r.text
def test_explicit_index_html():
r = get("/index.html")
assert r.status_code == 200
assert r.headers["content-type"] == "text/html; charset=utf-8"
assert "<title>That" in r.text
def test_200_bundles():
for path in [
x
for x in BUILD_ROOT.iterdir()
if x.name.startswith("bundle") and ".esm." in x.name
]:
uri = f"/{path.relative_to(BUILD_ROOT)}"
r = get(uri)
assert r.status_code == 200
if uri.endswith(".map"):
# https://stackoverflow.com/a/19912684/205832
assert r.headers["content-type"].startswith("application/json")
else:
assert r.headers["content-type"].startswith("text/javascript") or r.headers[
"content-type"
].startswith("application/javascript")
assert r.headers["cache-control"] == "max-age=315360000"
def test_400_nonexistant_bundle():
r = get("/bundle.404000.js")
assert r.status_code == 404
def test_sw_headers():
r = get("/sw.js")
assert r.status_code == 200
assert r.headers["content-type"].startswith("text/javascript") or r.headers[
"content-type"
].startswith("application/javascript")
assert r.headers["cache-control"] == "no-cache"
r = get("/sw-esm.js")
assert r.status_code == 200
assert r.headers["content-type"].startswith("text/javascript") or r.headers[
"content-type"
].startswith("application/javascript")
assert r.headers["cache-control"] == "no-cache"