Newer
Older
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
self.assertEqual(
models.FlowPageVisit.objects.filter(answer__isnull=False).count(),
1)
last_answered_visit = (
models.FlowPageVisit.objects.filter(answer__isnull=False).first())
last_answered_visit.visit_time = now() - timedelta(hours=1)
last_answered_visit.save()
self.assertEqual(models.GradeChange.objects.count(), 0)
with mock.patch("course.flow.get_session_grading_rule") as \
mock_get_grading_rule:
mock_get_grading_rule.side_effect = (
get_session_grading_rule_use_last_activity_as_cmplt_time_side_effect) # noqa
resp = self.end_flow()
self.assertEqual(resp.status_code, 200)
self.assertEqual(models.GradeChange.objects.count(), 1)
latest_gchange = models.GradeChange.objects.last()
latest_flow_session = models.FlowSession.objects.last()
self.assertIsNotNone(latest_flow_session.last_activity())
self.assertEqual(latest_flow_session.completion_time,
latest_flow_session.last_activity())
self.assertEqual(latest_gchange.effective_time,
latest_flow_session.last_activity())
# {{{ Fixed issue #263 and #417
def test_update_latest_gc_of_ealier_finished_session(self):
self.use_default_setup()
self.assertGradeChangeMachineReadableStateEqual(6)
# Issue #263 and #417
# gc_session1 is the GradeChange object of session 1, update it's
# value won't change the consumed state.
self.update_gc(self.gc_session1, points=10)
self.assertGradeChangeMachineReadableStateEqual(6)
self.assertGradeChangeStateEqual("6.00% (/3)")
def test_special_case(self):
# https://github.com/inducer/relate/pull/423#discussion_r162121467
gc2015 = factories.GradeChangeFactory.create(**(self.gc(points=5)))
session1 = factories.FlowSessionFactory.create(
participation=self.student_participation,
start_time=self.time-timedelta(days=17),
completion_time=self.time-timedelta(days=14))
self.time_increment()
gc2016 = factories.GradeChangeFactory.create(
**(self.gc(points=0, flow_session=session1, grade_time=self.time)))
gc2017 = factories.GradeChangeFactory.create(**(self.gc(points=7)))
session2 = factories.FlowSessionFactory.create(
participation=self.student_participation,
start_time=self.time-timedelta(days=17),
completion_time=self.time-timedelta(days=15))
self.time_increment()
gc2018 = factories.GradeChangeFactory.create(
**(self.gc(points=6, flow_session=session2)))
assert models.GradingOpportunity.objects.count() == 1
assert models.GradeChange.objects.count() == 4
assert models.FlowSession.objects.count() == 2
self.assertTrue(session2.completion_time < session1.completion_time)
self.assertTrue(
gc2015.grade_time < gc2016.grade_time < gc2017.grade_time
< gc2018.grade_time)
self.assertGradeChangeMachineReadableStateEqual(gc2017.percentage())
# {{{ When two grade changes have the same grade_time
# The expected behavior is GradeChange object with the larger pk
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
# dominate. Fixed with #263 and #417
def test_gcs_have_same_grade_time1(self):
gc1 = factories.GradeChangeFactory.create(**(self.gc(points=0)))
session = factories.FlowSessionFactory.create(
participation=self.student_participation,
completion_time=gc1.grade_time-timedelta(days=1))
factories.GradeChangeFactory.create(
**(self.gc(points=5, flow_session=session,
grade_time=gc1.grade_time)))
self.assertGradeChangeMachineReadableStateEqual(5)
self.assertGradeChangeStateEqual("5.0% (/2)")
def test_gc_have_same_grade_time2(self):
session = factories.FlowSessionFactory.create(
participation=self.student_participation,
start_time=self.time-timedelta(days=1),
completion_time=self.time)
self.time_increment()
gc1 = factories.GradeChangeFactory.create(
**(self.gc(points=5, flow_session=session)))
factories.GradeChangeFactory.create(
**(self.gc(points=0, grade_time=gc1.grade_time)))
self.assertGradeChangeMachineReadableStateEqual(0)
self.assertGradeChangeStateEqual("0.00% (/2)")
# }}}
# {{{ Fix #430
def test_reopen_session2(self):
self.use_default_setup()
# original state
self.assertGradeChangeMachineReadableStateEqual("6")
n_gc = models.GradeChange.objects.count()
self.reopen_session2()
# A new GradeChange object is created, with state "do_over"
expected_n_gc = models.GradeChange.objects.count()
self.assertEqual(expected_n_gc, n_gc + 1)
self.assertEqual(
models.GradeChange.objects.order_by("grade_time").last().state,
g_state.do_over)
self.assertGradeChangeMachineReadableStateEqual("NONE")
self.assertGradeChangeStateEqual("- ∅ - (/3)")
def test_reopen_session_without_existing_gc(self):
# This is rare, because a completed_session should had created
# a GradeChange object.
session_temp = factories.FlowSessionFactory.create(
participation=self.student_participation, completion_time=self.time)
existing_gc_count = models.GradeChange.objects.count()
reopen_session(now_datetime=local_now(), session=session_temp,
generate_grade_change=True,
suppress_log=True)
self.assertEqual(models.GradeChange.objects.count(), existing_gc_count)
def test_reopen_session1(self):
self.use_default_setup()
self.assertGradeChangeMachineReadableStateEqual("6")
n_gc = models.GradeChange.objects.count()
self.reopen_session1()
# A new GradeChange object is created, with state "do_over"
expected_n_gc = models.GradeChange.objects.count()
self.assertEqual(expected_n_gc, n_gc + 1)
self.assertEqual(
models.GradeChange.objects.order_by("grade_time").last().state,
g_state.do_over)
# session 1 is not the latest session
self.assertGradeChangeMachineReadableStateEqual("6")
self.assertGradeChangeStateEqual("6.00% (/3)")
def _get_admin_flow_session_delete_url(self, args):
return reverse("admin:course_flowsession_delete", args=args)
def _delete_flow_session_admin(self, flow_session):
exist_flow_session_count = models.FlowSession.objects.count()
flow_session_delete_url = self._get_admin_flow_session_delete_url(
args=(flow_session.id,))
delete_dict = {'post': 'yes'}
with self.temporarily_switch_to_user(self.superuser):
resp = self.c.get(flow_session_delete_url)
self.assertEqual(resp.status_code, 200)
resp = self.c.post(flow_session_delete_url, data=delete_dict)
self.assertEqual(resp.status_code, 302)
self.assertEqual(exist_flow_session_count,
models.FlowSession.objects.count() + 1)
def test_delete_flow_session_admin_new_exempt_gradechange_created(self):
self.use_default_setup()
exist_grade_change_count = models.GradeChange.objects.count()
# session1 has related grade changes, so a new grade change with 'exempt' is
# created
self._delete_flow_session_admin(self.session1)
self.assertEqual(exist_grade_change_count + 1,
models.GradeChange.objects.count())
last_gchange = (
models.GradeChange.objects
.order_by("-grade_time").first())
self.assertIsNone(last_gchange.flow_session)
self.assertEqual(last_gchange.state, g_state.exempt)
def test_delete_flow_session_admin_no_new_gradechange_created(self):
session_temp = factories.FlowSessionFactory.create(
participation=self.student_participation, completion_time=self.time)
exist_grade_change_count = models.GradeChange.objects.count()
last_gchange_of_session_temp = (
models.GradeChange.objects
.filter(flow_session=session_temp)
.order_by("-grade_time")[:1])
self.assertEqual(last_gchange_of_session_temp.count(), 0)
# session_temp has no related grade changes, so no new grade change
# is created after deleted
self._delete_flow_session_admin(session_temp)
self.assertEqual(exist_grade_change_count,
models.GradeChange.objects.count())
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
def test_backward_compatibility_merging_466(self):
# this make sure after merging https://github.com/inducer/relate/pull/466
# gchanges are consumed without issue
self.use_default_setup()
self.gc_session2.effective_time = None
self.gc_session2.save()
self.gc_session2.refresh_from_db()
# We are not using reopen_session(), because that will create new
# gchange, which only happen after #466 was merged.
self.session2.in_progress = True
self.session2.save()
self.session2.refresh_from_db()
machine = self.get_gc_machine()
# session2's gchange is excluded
self.assertGradeChangeMachineReadableStateEqual(7)
self.assertEqual(machine.valid_percentages, [0, 7])
self.assertGradeChangeStateEqual("7.00% (/2)")
# {{{ test new gchange created when finishing flow
def test_new_gchange_created_when_finish_flow_use_last_no_activity(self):
# With use_last_activity_as_completion_time = True, if a flow session has
# no last_activity, the expected effective_time of the new gchange should
# be the completion time of the related flow_session.
with self.temporarily_switch_to_user(self.student_participation.user):
self.start_flow(QUIZ_FLOW_ID)
self.assertEqual(models.GradeChange.objects.count(), 0)
with mock.patch("course.flow.get_session_grading_rule") as \
mock_get_grading_rule:
mock_get_grading_rule.side_effect = (
get_session_grading_rule_use_last_activity_as_cmplt_time_side_effect) # noqa
resp = self.end_flow()
self.assertEqual(resp.status_code, 200)
self.assertEqual(models.GradeChange.objects.count(), 1)
latest_gchange = models.GradeChange.objects.last()
latest_flow_session = models.FlowSession.objects.last()
self.assertIsNone(latest_flow_session.last_activity())
self.assertEqual(latest_gchange.effective_time,
latest_flow_session.completion_time)
def test_new_gchange_created_when_finish_flow_not_use_last_no_activity(self):
# With use_last_activity_as_completion_time = False, if a flow session has
# no last_activity, the expected effective_time of the new gchange should
# be the completion time of the related flow_session.
with self.temporarily_switch_to_user(self.student_participation.user):
self.start_flow(QUIZ_FLOW_ID)
self.assertEqual(models.GradeChange.objects.count(), 0)
resp = self.end_flow()
self.assertEqual(resp.status_code, 200)
self.assertEqual(models.GradeChange.objects.count(), 1)
latest_gchange = models.GradeChange.objects.last()
latest_flow_session = models.FlowSession.objects.last()
self.assertIsNone(latest_flow_session.last_activity())
self.assertEqual(latest_gchange.effective_time,
latest_flow_session.completion_time)
def test_new_gchange_created_when_finish_flow_not_use_last_has_activity(self):
# With use_last_activity_as_completion_time = False, even if a flow session
# HAS last_activity, the expected effective_time of the new gchange should
# be the completion_time of the related flow_session.
with self.temporarily_switch_to_user(self.instructor_participation.user):
self.start_flow(QUIZ_FLOW_ID)
# create a flow page visit, then there should be last_activity() for
# the session.
self.post_answer_by_ordinal(1, {"answer": ['0.5']})
self.assertEqual(
models.FlowPageVisit.objects.filter(answer__isnull=False).count(),
1)
last_answered_visit = (
models.FlowPageVisit.objects.filter(answer__isnull=False).first())
last_answered_visit.visit_time = now() - timedelta(hours=1)
last_answered_visit.save()
self.assertEqual(models.GradeChange.objects.count(), 0)
resp = self.end_flow()
self.assertEqual(resp.status_code, 200)
self.assertEqual(models.GradeChange.objects.count(), 1)
latest_gchange = models.GradeChange.objects.last()
latest_flow_session = models.FlowSession.objects.last()
self.assertIsNotNone(latest_flow_session.last_activity())
self.assertNotEqual(latest_flow_session.completion_time,
latest_flow_session.last_activity())
self.assertEqual(latest_gchange.effective_time,
latest_flow_session.completion_time)