@@ -169,6 +169,13 @@ def model(fork):
169
169
def client (model , mocker ):
170
170
""" This fixture generates a client for testing endpoints, model will be used.
171
171
"""
172
+ # these methods have the @reify decorator, however we need for them to be recalculated
173
+ # so ``naucse.utils.routes.forks_enabled`` can be tested
174
+ if hasattr (model , "safe_runs" ):
175
+ delattr (model , "safe_runs" )
176
+ if hasattr (model , "safe_run_years" ):
177
+ delattr (model , "safe_run_years" )
178
+
172
179
mocker .patch ("naucse.routes._cached_model" , model )
173
180
from naucse import app
174
181
app .testing = True
@@ -299,7 +306,10 @@ def test_courses_page(mocker, client: FlaskClient):
299
306
# but working forks are still present
300
307
assert b"Course title" in response .data
301
308
302
- # test ignoring forks
309
+
310
+ def test_courses_page_ignore_forks (mocker , client : FlaskClient ):
311
+ """ Tests ignoring forks in courses page
312
+ """
303
313
mocker .patch ("naucse.utils.routes.forks_enabled" , lambda : False )
304
314
mocker .patch ("naucse.utils.routes.raise_errors_from_forks" , lambda : True )
305
315
@@ -311,11 +321,12 @@ def test_courses_page(mocker, client: FlaskClient):
311
321
def test_runs_page (mocker , client : FlaskClient ):
312
322
""" Tests how the /runs/ page behaves when a fork isn't returning information about a course.
313
323
"""
324
+ mocker .patch ("naucse.utils.routes.forks_enabled" , lambda : True )
314
325
mocker .patch ("naucse.utils.routes.raise_errors_from_forks" , lambda : True )
315
326
316
327
# there's a problem in one of the branches, it should raise error if the conditions for raising are True
317
328
with pytest .raises (BuildError ):
318
- client .get ("/runs/" )
329
+ client .get ("/runs/all/ " )
319
330
320
331
# unless problems are silenced
321
332
mocker .patch ("naucse.utils.routes.raise_errors_from_forks" , lambda : False )
@@ -325,11 +336,14 @@ def test_runs_page(mocker, client: FlaskClient):
325
336
# but working forks are still present
326
337
assert b"Run title" in response .data
327
338
328
- # test ignoring forks
339
+
340
+ def test_runs_page_ignore_forks (mocker , client : FlaskClient ):
341
+ """ Tests ignoring forks in runs page
342
+ """
329
343
mocker .patch ("naucse.utils.routes.forks_enabled" , lambda : False )
330
344
mocker .patch ("naucse.utils.routes.raise_errors_from_forks" , lambda : True )
331
345
332
- response = client .get ("/runs/" )
346
+ response = client .get ("/runs/all/ " )
333
347
334
348
assert b"Broken run title" not in response .data
335
349
assert b"Run title" not in response .data
0 commit comments