-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathtest_check_pages.py
67 lines (52 loc) · 2.58 KB
/
test_check_pages.py
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
import http
from unittest import mock
from flask.testing import FlaskClient
from lms.lmsdb.models import Solution
from lms.lmsweb import routes
from tests import conftest
celery_async = (
"lms.lmstests.public.general.tasks."
"reset_solution_state_if_needed.apply_async"
)
no_celery = mock.patch(celery_async, lambda *args, **kwargs: None)
class TestCheckPages:
@classmethod
def setup_method(cls):
cls.course = conftest.create_course()
cls.user = conftest.create_user(index=1)
cls.user2 = conftest.create_user(index=2)
cls.exercise = conftest.create_exercise(cls.course, number=1)
solution = conftest.create_solution
cls.solution1 = solution(cls.exercise, cls.user, code="A")
cls.solution2 = solution(cls.exercise, cls.user, code="B")
cls.solution3 = solution(cls.exercise, cls.user2)
@classmethod
def test_start_checking(cls, admin_client: FlaskClient):
check_url = f"check/exercise/{cls.exercise.id}"
with no_celery:
# You should check the newer, not the older (same user)
response = admin_client.get(check_url, follow_redirects=True)
assert response.request.url.endswith(f"view/{cls.solution2.id}")
# First exercise should be marked as checking
response = admin_client.get(check_url, follow_redirects=True)
assert response.request.url.endswith(f"view/{cls.solution3.id}")
# All exercises are checked
response = admin_client.get(check_url, follow_redirects=True)
status_page = response.request.url.strip("/")
assert status_page.endswith(f"/{routes.STATUS.strip('/')}")
@classmethod
def test_check_solution(cls, admin_client: FlaskClient):
check_url = "check/solution/{}"
go_to = admin_client.get
solution = check_url.format
with no_celery:
response = go_to(solution(5000), follow_redirects=True)
assert response.status_code == http.HTTPStatus.NOT_FOUND
assert cls.solution1.state == Solution.STATES.CREATED.name
response = go_to(solution(cls.solution1.id), follow_redirects=True)
assert response.request.url.endswith(f"view/{cls.solution1.id}")
cls.solution1 = Solution.get_by_id(cls.solution1.id) # Must refresh
assert cls.solution1.state == Solution.STATES.IN_CHECKING.name
cls.solution1.mark_as_checked()
response = go_to(solution(cls.solution1.id), follow_redirects=True)
assert response.request.url.endswith(f"view/{cls.solution1.id}")