-
-
Notifications
You must be signed in to change notification settings - Fork 209
Expand file tree
/
Copy pathroutes_test.py
More file actions
256 lines (158 loc) · 6.54 KB
/
routes_test.py
File metadata and controls
256 lines (158 loc) · 6.54 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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
from server import app, talisman
from server.config import DEFAULT_YEAR
from server.language import DEFAULT_LANGUAGE
import pytest
# Create test client without https redirect
# (normally taken care of by running in debug)
@pytest.fixture
def client():
with app.test_client() as client:
talisman.force_https = False
yield client
# Add a function to test routes with optional location
def assert_route(client, path, status, location=None):
response = client.get(path)
redirect_loc = response.location
if redirect_loc:
redirect_loc = redirect_loc.replace("http://localhost", "")
if location is not None:
assert response.status_code == status and redirect_loc == location
else:
assert response.status_code == status
# All the tests
def test_render_en_2019_home(client):
assert_route(client, "/en/2019/", 200)
def test_render_invalid_lang_year(client):
assert_route(client, "/en/random/", 404)
def test_render_en_home(client):
assert_route(client, "/en/", 302, "/en/" + DEFAULT_YEAR + "/")
def test_render_en_no_slash_home(client):
assert_route(client, "/en", 308, "/en/")
def test_render_invalid_lang_home(client):
assert_route(client, "/random/", 404)
def test_render_invalid_lang_year_home(client):
assert_route(client, "/random/random/", 404)
def test_render_invalid_lang__valid_year_home(client):
assert_route(client, "/random/2019/", 404)
def test_render_home(client):
assert_route(
client, "/", 302, "/" + DEFAULT_LANGUAGE.lang_code + "/" + DEFAULT_YEAR + "/"
)
def test_render_en_2019_toc(client):
assert_route(client, "/en/2019/table-of-contents", 200)
def test_render_en_2019_toc_slash(client):
assert_route(
client, "/en/2019/table-of-contents/", 302, "/en/2019/table-of-contents"
)
def test_render_en_default_year_toc(client):
assert_route(client, "/en/" + DEFAULT_YEAR + "/table-of-contents", 200)
def test_render_en_2019_contributors(client):
assert_route(client, "/en/2019/contributors", 200)
def test_render_en_2019_contributors_slash(client):
assert_route(client, "/en/2019/contributors/", 302, "/en/2019/contributors")
def test_render_en_default_year_contributors(client):
assert_route(client, "/en/" + DEFAULT_YEAR + "/contributors", 200)
def test_render_en_2019_meth(client):
assert_route(client, "/en/2019/methodology", 200)
def test_render_caps_en_2019_meth(client):
assert_route(client, "/EN/2019/methodology", 302, "/en/2019/methodology")
def test_render_en_default_year_meth(client):
assert_route(client, "/en/" + DEFAULT_YEAR + "/methodology", 200)
def test_render_en_accessibility_statement(client):
assert_route(client, "/en/accessibility-statement", 200)
def test_render_en_accessibility_statement_slash(client):
assert_route(
client, "/en/accessibility-statement/", 301, "/en/accessibility-statement"
)
def test_render_search(client):
response = client.get("/en/search")
assert response.status_code == 200
def test_render_search_slash(client):
assert_route(client, "/en/search/", 301, "/en/search")
def test_render_search_year(client):
assert_route(client, "/en/2020/search", 301, "/en/search")
def test_render_search_year_slash(client):
assert_route(client, "/en/2020/search/", 301, "/en/search")
def test_render_sitemap(client):
assert_route(client, "/sitemap.xml", 200)
def test_render_en_rss(client):
assert_route(client, "/en/rss.xml", 200)
def test_render_base_rss(client):
assert_route(client, "/base/rss.xml", 404)
def test_render_en_2019_good_chapter(client):
assert_route(client, "/en/2019/css", 200)
def test_render_en_2019_bad_chapter(client):
assert_route(client, "/en/2019/random", 404)
def test_render_en_2019_good_chapter_slash(client):
assert_route(client, "/en/2019/css/", 302, "/en/2019/css")
def test_redirect_untranslated_chapter(client):
assert_route(client, "/nl/2019/http", 302, "/en/2019/http")
def test_redirect_untranslated_chapter_qith_queryparam(client):
assert_route(client, "/nl/2019/http?queryparam", 302, "/en/2019/http?queryparam")
def test_render_robots(client):
assert_route(client, "/robots.txt", 200)
def test_render_favicon(client):
assert_route(client, "/favicon.ico", 200)
def test_apple_icon_redirect(client):
assert_route(
client, "/apple-touch-icon.png", 301, "/static/images/apple-touch-icon.png"
)
def test_apple_icon_redirect_with_slash(client):
assert_route(
client, "/apple-touch-icon.png/", 301, "/static/images/apple-touch-icon.png"
)
def test_chapter_favicon_redirect(client):
assert_route(
client, "/static/images/2021/css/favicon.ico", 301, "/static/images/favicon.ico"
)
def test_render_en_2019_ebook(client):
assert_route(client, "/en/2019/ebook", 200)
def test_render_old_image_dir_redirect(client):
assert_route(
client,
"/static/images/2019/02_CSS/random.png",
301,
"/static/images/2019/css/random.png",
)
def test_render_pdf_redirect(client):
assert_route(
client,
"/static/pdfs/web_almanac_2019_en_cover_A5.pdf",
301,
"https://cdn.httparchive.org/v1/static/almanac/ebooks/web_almanac_2019_en_cover_A5.pdf",
)
def test_render_old_http_image_dir_redirect(client):
assert_route(
client,
"/static/images/2020/http2/random.png",
301,
"/static/images/2020/http/random.png",
)
def test_render_old_hero_image_dir_redirect(client):
assert_route(
client,
"/static/images/2019/jamstack/random.png",
301,
"/static/images/2020/jamstack/random.png",
)
def test_render_en_2020_story(client):
response = client.get("/en/2020/stories/page-content")
assert (
response.status_code == 200
and response.headers.get("X-Frame-Options") is None
and "frame-ancestors *" in response.headers.get("Content-Security-Policy")
)
def test_render_efonts_cache_control(client):
response = client.get("/static/fonts/Poppins-Bold.woff2")
assert response.status_code == 200 and "max-age=3153600" in response.headers.get(
"Cache-Control"
)
def test_test_webvitals_js(client):
response = client.get("/static/js/web-vitals.js")
assert response.status_code == 200
def test_test_webvitals_js_versioned(client):
response = client.get("/static/js/web-vitals.js?v=1234")
assert response.status_code == 200
def test_embed(client):
response = client.get("/en/2022/embeds/structured-data-sankey")
assert response.status_code == 200