-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: Add tests for solution matrix
- Loading branch information
1 parent
0f29545
commit 3908869
Showing
7 changed files
with
157 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from lms.lmsdb.models import Course | ||
from lms.models import courses | ||
from tests import conftest | ||
|
||
|
||
class TestCourse: | ||
@staticmethod | ||
def test_course_exercises(course: Course): | ||
ex1 = conftest.create_exercise(course, 0) | ||
ex2 = conftest.create_exercise(course, 1) | ||
exercises = course.get_exercise_ids() | ||
assert len(exercises) == 2 | ||
assert ex1.id in exercises | ||
assert ex2.id in exercises | ||
|
||
@staticmethod | ||
def test_course_name(): | ||
course = conftest.create_course(name='Test course') | ||
assert course.name == 'Test course' | ||
|
||
@staticmethod | ||
def test_course_students(course: Course): | ||
course_id = course.id | ||
students = [conftest.create_user(index=i) for i in range(3)] | ||
|
||
# No users in course | ||
assert len(courses.get_students(course_id)) == 0 | ||
|
||
# Add users to course | ||
for student in students: | ||
conftest.create_usercourse(student, course) | ||
|
||
discovered = courses.get_students(course_id) | ||
assert len(discovered) == 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters