1
|
|
|
''' |
2
|
|
|
Test cases for tutor 'GET' views and actions. |
3
|
|
|
''' |
4
|
|
|
|
5
|
|
|
from opensubmit.models import Assignment, Submission |
6
|
|
|
from opensubmit.tests.cases import SubmitTutorTestCase |
7
|
|
|
|
8
|
|
|
from .helpers.user import get_student_dict, create_user, admin_dict |
9
|
|
|
from .helpers.submission import create_validated_submission |
10
|
|
|
from .helpers.submission import create_validatable_submission |
11
|
|
|
from .helpers.djangofiles import create_submission_file |
12
|
|
|
from .helpers.course import create_course |
13
|
|
|
from .helpers.assignment import create_pass_fail_grading |
14
|
|
|
from .helpers.assignment import create_open_file_assignment |
15
|
|
|
|
16
|
|
|
from django.contrib.admin.sites import AdminSite |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
class Tutor(SubmitTutorTestCase): |
20
|
|
|
|
21
|
|
|
def setUp(self): |
22
|
|
|
super(Tutor, self).setUp() |
23
|
|
|
self.admin = create_user(admin_dict) |
24
|
|
|
self.course = create_course(self.admin, self.user) |
25
|
|
|
grading = create_pass_fail_grading() |
26
|
|
|
self.assignment = create_open_file_assignment(self.course, grading) |
27
|
|
|
|
28
|
|
|
def test_teacher_dashboard_view(self): |
29
|
|
|
response = self.c.get('/teacher/') |
30
|
|
|
self.assertEqual(response.status_code, 200) |
31
|
|
|
|
32
|
|
|
def test_assignment_list_backend(self): |
33
|
|
|
from opensubmit.admin.assignment import AssignmentAdmin |
34
|
|
|
assadm = AssignmentAdmin(Assignment, AdminSite()) |
35
|
|
|
assignments_shown = assadm.get_queryset(self.request) |
36
|
|
|
self.assertIn(self.assignment, assignments_shown) |
37
|
|
|
|
38
|
|
|
def test_submission_list_view(self): |
39
|
|
|
response = self.c.get('/teacher/opensubmit/submission/') |
40
|
|
|
self.assertEqual(response.status_code, 200) |
41
|
|
|
|
42
|
|
|
def test_submission_edit_view(self): |
43
|
|
|
sub = create_validated_submission(self.user, self.assignment) |
44
|
|
|
response = self.c.get( |
45
|
|
|
'/teacher/opensubmit/submission/%u/change/' % sub.pk) |
46
|
|
|
self.assertEqual(response.status_code, 200) |
47
|
|
|
self.assertContains(response, str(sub.get_validation_result().result)) |
48
|
|
|
|
49
|
|
|
def test_grading_table_view(self): |
50
|
|
|
response = self.c.get('/course/%u/gradingtable/' % self.course.pk) |
51
|
|
|
self.assertEqual(response.status_code, 200) |
52
|
|
|
|
53
|
|
|
def test_duplicate_report_view(self): |
54
|
|
|
sub1 = create_validatable_submission( |
55
|
|
|
create_user(get_student_dict(0)), |
56
|
|
|
self.assignment, |
57
|
|
|
create_submission_file()) |
58
|
|
|
sub2 = create_validatable_submission( |
59
|
|
|
create_user(get_student_dict(1)), |
60
|
|
|
self.assignment, |
61
|
|
|
create_submission_file()) |
62
|
|
|
sub3 = create_validatable_submission( |
63
|
|
|
create_user(get_student_dict(2)), |
64
|
|
|
self.assignment, |
65
|
|
|
create_submission_file()) |
66
|
|
|
sub3.state = Submission.WITHDRAWN |
67
|
|
|
sub3.save() |
68
|
|
|
response = self.c.get('/assignments/%u/duplicates/' % |
69
|
|
|
self.assignment.pk) |
70
|
|
|
self.assertEqual(response.status_code, 200) |
71
|
|
|
# expect both submissions to be in the report |
72
|
|
|
self.assertIn('submission/%u/change' % sub1.pk, str(response.content)) |
73
|
|
|
self.assertIn('submission/%u/change' % sub2.pk, str(response.content)) |
74
|
|
|
# expect withdrawn submissions to be left out |
75
|
|
|
self.assertNotIn('#%u' % sub3.pk, str(response)) |
76
|
|
|
|
77
|
|
|
def test_preview_view(self): |
78
|
|
|
sub1 = create_validated_submission(self.user, self.assignment) |
79
|
|
|
response = self.c.get('/preview/%u/' % sub1.pk) |
80
|
|
|
self.assertEqual(response.status_code, 200) |
81
|
|
|
|
82
|
|
|
def test_preview_broken_view(self): |
83
|
|
|
''' |
84
|
|
|
Test proper handling of archives containing |
85
|
|
|
files with invalid unicode. |
86
|
|
|
''' |
87
|
|
|
sub1 = create_validated_submission(self.user, self.assignment) |
88
|
|
|
for fname in ['broken_preview.gz', |
89
|
|
|
'broken_preview2.gz', |
90
|
|
|
'broken_preview.zip']: |
91
|
|
|
subfile = create_submission_file( |
92
|
|
|
"submfiles/broken_preview/" + fname) |
93
|
|
|
sub1.file_upload = subfile |
94
|
|
|
sub1.save() |
95
|
|
|
response = self.c.get('/preview/%u/' % sub1.pk) |
96
|
|
|
self.assertEqual(response.status_code, 200) |
97
|
|
|
|
98
|
|
|
def test_add_course_tutor_signal_handler(self): |
99
|
|
|
# Add another user who had no backend rights before |
100
|
|
|
new_user = create_user(get_student_dict(1)) |
101
|
|
|
new_user.save() |
102
|
|
|
assert(not new_user.is_staff) |
103
|
|
|
self.course.tutors.add(new_user) |
104
|
|
|
self.course.save() |
105
|
|
|
# Check if he got them afterwards |
106
|
|
|
new_user.refresh_from_db() |
107
|
|
|
assert(new_user.is_staff) |
108
|
|
|
|
109
|
|
|
def test_remove_course_tutor_signal_handler(self): |
110
|
|
|
assert(self.user in self.course.tutors.all()) |
111
|
|
|
assert(self.user.is_staff) |
112
|
|
|
self.course.tutors.remove(self.user) |
113
|
|
|
self.course.save() |
114
|
|
|
self.user.refresh_from_db() |
115
|
|
|
assert(not self.user.is_staff) |
116
|
|
|
|
117
|
|
|
|