-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathtest_sql_linter.py
32 lines (26 loc) · 1.05 KB
/
test_sql_linter.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
from lms.lmsdb.models import Comment, Solution
from lms.lmstests.public.linters import tasks
INVALID_CODE = 's1\n'
INVALID_CODE_MESSAGE = (
'Line 1, Position 1: Found unparsable section: 's1'' # Escape
)
VALID_CODE = 'SELECT 1\n'
class TestSQLLinter:
def test_invalid_solution(self, solution: Solution):
solution_file = solution.solution_files.get()
solution_file.path = 'sql.sql'
solution_file.code = INVALID_CODE
solution_file.save()
tasks.run_linter_on_solution(solution.id)
comments = tuple(Comment.by_solution(solution))
assert comments
assert len(comments) == 1
assert comments[0].comment.text == INVALID_CODE_MESSAGE
def test_valid_solution(self, solution: Solution):
solution_file = solution.solution_files.get()
solution_file.path = 'sql.sql'
solution_file.code = VALID_CODE
solution_file.save()
tasks.run_linter_on_solution(solution.id)
comments = tuple(Comment.by_solution(solution))
assert not comments