Newer
Older
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
from __future__ import division
__copyright__ = "Copyright (C) 2018 Dong Zhuang"
__license__ = """
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
"""
import os
from django.core import mail
from django.test import TestCase
from tests.base_test_mixins import SingleCoursePageTestMixin
from tests.test_pages import QUIZ_FLOW_ID
from tests import factories
class SingleCourseQuizPageGradeInterfaceTestMixin(SingleCoursePageTestMixin):
flow_id = QUIZ_FLOW_ID
@classmethod
def setUpTestData(cls): # noqa
super(SingleCourseQuizPageGradeInterfaceTestMixin, cls).setUpTestData()
cls.c.force_login(cls.student_participation.user)
cls.start_flow(cls.flow_id)
cls.this_flow_session_id = cls.default_flow_params["flow_session_id"]
cls.any_up_page_id = "anyup"
cls.submit_any_upload_question()
def submit_any_upload_question_null(self):
return self.post_answer_by_page_id(
"anyup", {"uploaded_file": []})
@classmethod
def submit_any_upload_question(cls):
with open(
os.path.join(os.path.dirname(__file__),
'fixtures', 'test_file.txt'), 'rb') as fp:
answer_data = {"uploaded_file": fp}
return cls.post_answer_by_page_id_class(
cls.any_up_page_id, answer_data, **cls.default_flow_params)
class SingleCourseQuizPageGradeInterfaceTest(
SingleCourseQuizPageGradeInterfaceTestMixin, TestCase):
@classmethod
def setUpTestData(cls): # noqa
super(SingleCourseQuizPageGradeInterfaceTest, cls).setUpTestData()
cls.end_flow()
def setUp(self): # noqa
# This is needed to ensure student is logged in to submit page or end flow.
self.c.force_login(self.student_participation.user)
def test_post_grades(self):
grade_data = {
"grade_percent": ["100"],
"released": ["on"]
}
resp = self.post_grade_by_page_id(self.any_up_page_id, grade_data)
self.assertTrue(resp.status_code, 200)
self.assertSessionScoreEqual(5)
grade_data = {
"grade_points": ["4"],
"released": []
}
resp = self.post_grade_by_page_id(self.any_up_page_id, grade_data)
self.assertTrue(resp.status_code, 200)
self.assertSessionScoreEqual(None)
grade_data = {
"grade_points": ["4"],
"released": ["on"]
}
resp = self.post_grade_by_page_id(self.any_up_page_id, grade_data)
self.assertTrue(resp.status_code, 200)
self.assertSessionScoreEqual(4)
def test_post_grades_success(self):
grade_data = {
"grade_percent": ["100"],
"released": ['on']
}
resp = self.post_grade_by_page_id(self.any_up_page_id, grade_data)
self.assertTrue(resp.status_code, 200)
self.assertSessionScoreEqual(5)
def test_post_grades_huge_points_failure(self):
grade_data = {
"grade_percent": ["2000"],
"released": ['on']
}
resp = self.post_grade_by_page_id(self.any_up_page_id, grade_data)
self.assertTrue(resp.status_code, 200)
# value exceeded allowed
self.assertResponseContextContains(
resp, "grading_form_html",
"Ensure this value is less than or equal to")
self.assertSessionScoreEqual(None)
def test_post_grades_forbidden(self):
grade_data = {
"grade_percent": ["100"],
"released": ['on']
}
# with self.student_participation.user logged in
resp = self.post_grade_by_page_id(self.any_up_page_id, grade_data,
force_login_instructor=False)
self.assertTrue(resp.status_code, 403)
self.assertSessionScoreEqual(None)
def test_feedback_and_notify(self):
grade_data = {
"grade_percent": ["100"],
"released": ['on'],
"feedback_text": ['test feedback']
}
self.post_grade_by_page_id(self.any_up_page_id, grade_data)
self.assertEqual(len(mail.outbox), 0)
grade_data["notify"] = ["on"]
self.post_grade_by_page_id(self.any_up_page_id, grade_data)
self.assertEqual(len(mail.outbox), 1)
self.assertEqual(mail.outbox[0].reply_to, [])
def test_feedback_email_may_reply(self):
grade_data = {
"grade_percent": ["100"],
"released": ['on'],
"feedback_text": ['test feedback'],
"notify": ["on"],
"may_reply": ["on"]
}
with self.temporarily_switch_to_user(self.ta_participation.user):
self.post_grade_by_page_id(self.any_up_page_id, grade_data,
force_login_instructor=False)
self.assertEqual(len(mail.outbox), 1)
self.assertEqual(mail.outbox[0].reply_to,
[self.ta_participation.user.email])
def test_notes_and_notify(self):
grade_data = {
"grade_percent": ["100"],
"released": ['on'],
"notes": ['test notes']
}
self.post_grade_by_page_id(self.any_up_page_id, grade_data)
self.assertEqual(len(mail.outbox), 0)
grade_data["notify_instructor"] = ["on"]
self.post_grade_by_page_id(self.any_up_page_id, grade_data)
self.assertEqual(len(mail.outbox), 1)
# {{{ tests on grading history dropdown
def test_grade_history_failure_no_perm(self):
ta_flow_session = factories.FlowSessionFactory(
participation=self.ta_participation)
# no pperm to view other's grade_history
resp = self.c.post(
self.get_page_grade_history_url_by_ordinal(
page_ordinal=1, flow_session_id=ta_flow_session.pk))
self.assertEqual(resp.status_code, 403)
def test_grade_history_failure_not_ajax(self):
resp = self.c.get(
self.get_page_grade_history_url_by_ordinal(
page_ordinal=1))
self.assertEqual(resp.status_code, 403)
def test_submit_history_failure_not_get(self):
resp = self.c.post(
self.get_page_grade_history_url_by_ordinal(
page_ordinal=1), HTTP_X_REQUESTED_WITH='XMLHttpRequest')
self.assertEqual(resp.status_code, 403)
def test_grade_history_failure_not_authenticated(self):
with self.temporarily_switch_to_user(None):
resp = self.c.get(
self.get_page_grade_history_url_by_ordinal(
page_ordinal=1), HTTP_X_REQUESTED_WITH='XMLHttpRequest')
self.assertEqual(resp.status_code, 403)
# }}}
class SingleCourseQuizPageGradeInterfaceTestExtra(
SingleCourseQuizPageGradeInterfaceTestMixin, TestCase):
def setUp(self): # noqa
# This is needed to ensure student is logged in to submit page or end flow.
self.c.force_login(self.student_participation.user)
def test_post_grades_history(self):
# This submission failed
resp = self.submit_any_upload_question_null()
self.assertFormErrorLoose(resp, "This field is required.")
# 2nd submission succeeded
resp = self.submit_any_upload_question()
self.end_flow()
grade_data = {
"grade_percent": ["100"],
"released": ["on"]
}
resp = self.post_grade_by_page_id(self.any_up_page_id, grade_data)
self.assertTrue(resp.status_code, 200)
self.assertSessionScoreEqual(5)
ordinal = self.get_page_ordinal_via_page_id(self.any_up_page_id)
self.assertGradeHistoryItemsCount(page_ordinal=ordinal, expected_count=3)
grade_data = {
"grade_points": ["4"],
"released": []
}
resp = self.post_grade_by_page_id(self.any_up_page_id, grade_data)
self.assertTrue(resp.status_code, 200)
self.assertSessionScoreEqual(None)
self.assertGradeHistoryItemsCount(page_ordinal=ordinal, expected_count=4)
grade_data = {
"grade_points": ["4"],
"released": ["on"]
}
resp = self.post_grade_by_page_id(self.any_up_page_id, grade_data)
self.assertTrue(resp.status_code, 200)
self.assertSessionScoreEqual(4)
self.assertGradeHistoryItemsCount(page_ordinal=ordinal,
expected_count=5)
# vim: fdm=marker