@@ -46,6 +46,7 @@ def setUp(self) -> None:
46
46
test_client = TestClient (app )
47
47
self .session = test_client .__enter__ ()
48
48
self .session .auth = ('test_user' , 'test_pass' )
49
+ self .url_path_for = app .url_path_for
49
50
self .database = database
50
51
self .loop = asyncio .get_event_loop ()
51
52
@@ -54,12 +55,12 @@ def tearDown(self) -> None:
54
55
super ().tearDown ()
55
56
56
57
def test_app (self ) -> None :
57
- response = self .session .get ('/' )
58
+ response = self .session .get (self . url_path_for ( 'homepage' ) )
58
59
self .assertEqual (200 , response .status_code )
59
60
60
61
def test_app_requires_auth (self ) -> None :
61
62
self .session .auth = None
62
- response = self .session .get ('/' )
63
+ response = self .session .get (self . url_path_for ( 'homepage' ) )
63
64
self .assertEqual (401 , response .status_code )
64
65
self .assertIn ('WWW-Authenticate' , response .headers )
65
66
self .assertIn (' realm=' , response .headers ['WWW-Authenticate' ])
@@ -94,7 +95,7 @@ def test_shows_own_and_own_team_uploads(self) -> None:
94
95
),
95
96
))
96
97
97
- response = self .session .get ('/' )
98
+ response = self .session .get (self . url_path_for ( 'homepage' ) )
98
99
self .assertEqual (200 , response .status_code )
99
100
100
101
html = response .text
@@ -156,7 +157,7 @@ def test_shows_chosen_archive(self) -> None:
156
157
),
157
158
))
158
159
159
- response = self .session .get ('/' )
160
+ response = self .session .get (self . url_path_for ( 'homepage' ) )
160
161
self .assertEqual (200 , response .status_code )
161
162
162
163
html = response .text
@@ -182,11 +183,14 @@ def test_upload_file(self) -> None:
182
183
zip_file .writestr ('robot.py' , 'print("I am a robot")' )
183
184
184
185
response = self .session .post (
185
- '/ upload' ,
186
+ self . url_path_for ( ' upload') ,
186
187
files = {'archive' : ('whatever.zip' , contents .getvalue (), 'application/zip' )},
187
188
)
188
189
self .assertEqual (302 , response .status_code )
189
- self .assertEqual ('http://testserver/' , response .headers ['location' ])
190
+ self .assertEqual (
191
+ self .url_path_for ('homepage' ),
192
+ response .headers ['location' ],
193
+ )
190
194
191
195
archives = self .await_ (
192
196
self .database .fetch_all (Archive .select ()),
@@ -221,12 +225,15 @@ def test_upload_and_choose_file(self) -> None:
221
225
zip_file .writestr ('robot.py' , 'print("I am a robot")' )
222
226
223
227
response = self .session .post (
224
- '/ upload' ,
228
+ self . url_path_for ( ' upload') ,
225
229
data = {'choose' : 'on' },
226
230
files = {'archive' : ('whatever.zip' , contents .getvalue (), 'application/zip' )},
227
231
)
228
232
self .assertEqual (302 , response .status_code )
229
- self .assertEqual ('http://testserver/' , response .headers ['location' ])
233
+ self .assertEqual (
234
+ self .url_path_for ('homepage' ),
235
+ response .headers ['location' ],
236
+ )
230
237
231
238
archive , = self .await_ (
232
239
self .database .fetch_all (Archive .select ()),
@@ -254,7 +261,7 @@ def test_upload_and_choose_file(self) -> None:
254
261
255
262
def test_upload_bad_file (self ) -> None :
256
263
response = self .session .post (
257
- '/ upload' ,
264
+ self . url_path_for ( ' upload') ,
258
265
files = {'archive' : ('whatever.zip' , b'should-be-a-zip' , 'application/zip' )},
259
266
)
260
267
self .assertEqual (400 , response .status_code )
0 commit comments