Skip to content

Commit 314c4fc

Browse files
committed
Fixed fork tests
1 parent 01dadfc commit 314c4fc

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

test_naucse/test_forks.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,13 @@ def model(fork):
169169
def client(model, mocker):
170170
""" This fixture generates a client for testing endpoints, model will be used.
171171
"""
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+
172179
mocker.patch("naucse.routes._cached_model", model)
173180
from naucse import app
174181
app.testing = True
@@ -299,7 +306,10 @@ def test_courses_page(mocker, client: FlaskClient):
299306
# but working forks are still present
300307
assert b"Course title" in response.data
301308

302-
# test ignoring forks
309+
310+
def test_courses_page_ignore_forks(mocker, client: FlaskClient):
311+
""" Tests ignoring forks in courses page
312+
"""
303313
mocker.patch("naucse.utils.routes.forks_enabled", lambda: False)
304314
mocker.patch("naucse.utils.routes.raise_errors_from_forks", lambda: True)
305315

@@ -311,11 +321,12 @@ def test_courses_page(mocker, client: FlaskClient):
311321
def test_runs_page(mocker, client: FlaskClient):
312322
""" Tests how the /runs/ page behaves when a fork isn't returning information about a course.
313323
"""
324+
mocker.patch("naucse.utils.routes.forks_enabled", lambda: True)
314325
mocker.patch("naucse.utils.routes.raise_errors_from_forks", lambda: True)
315326

316327
# there's a problem in one of the branches, it should raise error if the conditions for raising are True
317328
with pytest.raises(BuildError):
318-
client.get("/runs/")
329+
client.get("/runs/all/")
319330

320331
# unless problems are silenced
321332
mocker.patch("naucse.utils.routes.raise_errors_from_forks", lambda: False)
@@ -325,11 +336,14 @@ def test_runs_page(mocker, client: FlaskClient):
325336
# but working forks are still present
326337
assert b"Run title" in response.data
327338

328-
# test ignoring forks
339+
340+
def test_runs_page_ignore_forks(mocker, client: FlaskClient):
341+
""" Tests ignoring forks in runs page
342+
"""
329343
mocker.patch("naucse.utils.routes.forks_enabled", lambda: False)
330344
mocker.patch("naucse.utils.routes.raise_errors_from_forks", lambda: True)
331345

332-
response = client.get("/runs/")
346+
response = client.get("/runs/all/")
333347

334348
assert b"Broken run title" not in response.data
335349
assert b"Run title" not in response.data

0 commit comments

Comments
 (0)