Repository navigation
Expand file tree
/
Copy pathserve_test.py
More file actions
43 lines (39 loc) · 1.39 KB
/
Copy pathserve_test.py
File metadata and controls
43 lines (39 loc) · 1.39 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
"""Smoke test: serve dist/ and fetch key pages + assets, assert HTTP 200."""
import http.server
import socketserver
import threading
import urllib.request
from pathlib import Path
DIST = Path(__file__).resolve().parent / "dist"
PORT = 8799
handler = lambda *a, **k: http.server.SimpleHTTPRequestHandler(*a, directory=str(DIST), **k)
httpd = socketserver.TCPServer(("127.0.0.1", PORT), handler)
t = threading.Thread(target=httpd.serve_forever, daemon=True)
t.start()
paths = [
"/", "/sitemap.xml", "/robots.txt",
"/tlumachennia-staroho-zavitu/", "/tlumachennia-staroho-zavitu/buttia/",
"/tlumachennia-novoho-zavitu/", "/tlumachennia-sviatoho-pysma/",
"/history/", "/greek/", "/zhurnal/", "/novyny/",
"/kontakty/", "/vstup/", "/pochatkova-shkola/", "/peredplata-zhurnalu/",
"/pozhertvy/", "/video-lektsii/", "/biblioteka/",
"/media/css/main.css", "/media/img/logo.png", "/og/index.jpg",
]
bad = []
for p in paths:
try:
with urllib.request.urlopen(f"http://127.0.0.1:{PORT}{p}", timeout=5) as r:
code = r.status
ctype = r.headers.get("Content-Type", "")
except Exception as e:
bad.append((p, str(e)))
continue
if code != 200:
bad.append((p, code))
print(f"{code} {p} ({ctype})")
httpd.shutdown()
print("\n=== RESULT ===")
if bad:
print("FAILURES:", bad)
raise SystemExit(1)
print(f"ALL {len(paths)} REQUESTS 200 OK")