def test_finish_in_progress_sessions_past_due_only_dued(self): # now_datetime > grading_rule.due fake_grading_rule = self.get_hacked_session_grading_rule( due=now() + timedelta(days=1)) with mock.patch("course.flow.get_session_grading_rule") as \ mock_get_grading_rule: mock_get_grading_rule.return_value = fake_grading_rule finish_in_progress_sessions(self.gopp.course_id, self.gopp.flow_id, rule_tag=None, now_datetime=now() + timedelta(days=3), past_due_only=True) self.assertEqual( models.FlowSession.objects.filter(in_progress=True).count(), 0) self.assertEqual( models.FlowSession.objects.filter(in_progress=False).count(), self.all_sessions_count) self.assertEqual( models.FlowPageVisitGrade.objects.filter( visit__flow_session__in=self.ended_sessions).count(), 0) for ended_session in self.in_progress_sessions: self.assertTrue( models.FlowPageVisitGrade.objects.filter( visit__flow_session=ended_session).count() > 0) self.assertEqual(self.mock_update_state.call_count, self.in_progress_sessions_count)
def test_finish_in_progress_sessions_all(self): finish_in_progress_sessions(self.gopp.course_id, self.gopp.flow_id, rule_tag=None, now_datetime=now(), past_due_only=False) self.assertEqual( models.FlowSession.objects.filter(in_progress=True).count(), 0) self.assertEqual( models.FlowSession.objects.filter(in_progress=False).count(), self.all_sessions_count) self.assertEqual( models.FlowPageVisitGrade.objects.filter( visit__flow_session__in=self.ended_sessions).count(), 0) # each ended sessions in this operation got page grades for session in self.in_progress_sessions: self.assertTrue( models.FlowPageVisitGrade.objects.filter( visit__flow_session=session).count() > 0) # each previously ended sessions didn't got page grades for session in self.ended_sessions: self.assertTrue( models.FlowPageVisitGrade.objects.filter( visit__flow_session=session).count() == 0) self.assertEqual(self.mock_update_state.call_count, self.in_progress_sessions_count)
def test_finish_in_progress_sessions_past_due_only_dued(self): # now_datetime > grading_rule.due fake_grading_rule = self.get_hacked_session_grading_rule( due=now() + timedelta(days=1)) with mock.patch("course.flow.get_session_grading_rule") as \ mock_get_grading_rule: mock_get_grading_rule.return_value = fake_grading_rule finish_in_progress_sessions( self.gopp.course_id, self.gopp.flow_id, rule_tag=None, now_datetime=now()+timedelta(days=3), past_due_only=True) self.assertEqual( models.FlowSession.objects.filter(in_progress=True).count(), 0) self.assertEqual( models.FlowSession.objects.filter(in_progress=False).count(), self.all_sessions_count) self.assertEqual( models.FlowPageVisitGrade.objects.filter( visit__flow_session__in=self.ended_sessions).count(), 0) for ended_session in self.in_progress_sessions: self.assertTrue( models.FlowPageVisitGrade.objects.filter( visit__flow_session=ended_session).count() > 0) self.assertEqual( self.mock_update_state.call_count, self.in_progress_sessions_count)
def test_finish_in_progress_sessions_all(self): finish_in_progress_sessions( self.gopp.course_id, self.gopp.flow_id, rule_tag=None, now_datetime=now(), past_due_only=False ) self.assertEqual( models.FlowSession.objects.filter(in_progress=True).count(), 0) self.assertEqual( models.FlowSession.objects.filter(in_progress=False).count(), self.all_sessions_count) self.assertEqual( models.FlowPageVisitGrade.objects.filter( visit__flow_session__in=self.ended_sessions).count(), 0 ) # each ended sessions in this operation got page grades for session in self.in_progress_sessions: self.assertTrue( models.FlowPageVisitGrade.objects.filter( visit__flow_session=session).count() > 0 ) # each previously ended sessions didn't got page grades for session in self.ended_sessions: self.assertTrue( models.FlowPageVisitGrade.objects.filter( visit__flow_session=session).count() == 0 )
def test_finish_in_progress_sessions(self): with mock.patch("course.tasks.Course.objects.get")\ as mock_course_object_get: # This is to avoid errors mock_course_object_get.return_value = self.course finish_in_progress_sessions(self.course.pk, self.flow_id, rule_tag=None, now_datetime=now(), past_due_only=True) mock_course_object_get.assert_called_once_with(id=self.course.pk)
def test_finish_in_progress_sessions(self): with mock.patch("course.tasks.Course.objects.get")\ as mock_course_object_get: # This is to avoid errors mock_course_object_get.return_value = self.course finish_in_progress_sessions( self.course.pk, self.flow_id, rule_tag=None, now_datetime=now(), past_due_only=True ) mock_course_object_get.assert_called_once_with(id=self.course.pk)
def test_finish_in_progress_sessions_past_due_only_due_none(self): # grading_rule.due is None finish_in_progress_sessions(self.gopp.course_id, self.gopp.flow_id, rule_tag=None, now_datetime=now(), past_due_only=True) self.assertEqual( models.FlowSession.objects.filter(in_progress=True).count(), self.in_progress_sessions_count) self.assertEqual( models.FlowSession.objects.filter(in_progress=False).count(), self.ended_sessions_count) self.assertEqual(models.FlowPageVisitGrade.objects.count(), 0)
def test_finish_in_progress_sessions_past_due_only_due_none(self): # grading_rule.due is None finish_in_progress_sessions( self.gopp.course_id, self.gopp.flow_id, rule_tag=None, now_datetime=now(), past_due_only=True ) self.assertEqual( models.FlowSession.objects.filter(in_progress=True).count(), self.in_progress_sessions_count) self.assertEqual( models.FlowSession.objects.filter(in_progress=False).count(), self.ended_sessions_count) self.assertEqual( models.FlowPageVisitGrade.objects.count(), 0 )
def test_finish_in_progress_sessions_past_due_only_not_dued(self): # now_datetime < grading_rule.due with mock.patch("course.flow.get_session_grading_rule") as \ mock_get_grading_rule: mock_get_grading_rule.side_effect = ( get_session_grading_rule_1_day_due_side_effect) finish_in_progress_sessions(self.gopp.course_id, self.gopp.flow_id, rule_tag=None, now_datetime=now(), past_due_only=True) self.assertEqual( models.FlowSession.objects.filter(in_progress=True).count(), self.in_progress_sessions_count) self.assertEqual( models.FlowSession.objects.filter(in_progress=False).count(), self.ended_sessions_count) self.assertEqual(models.FlowPageVisitGrade.objects.count(), 0)
def test_finish_in_progress_sessions_past_due_only_not_dued(self): # now_datetime < grading_rule.due with mock.patch("course.flow.get_session_grading_rule") as \ mock_get_grading_rule: mock_get_grading_rule.side_effect = ( get_session_grading_rule_1_day_due_side_effect) finish_in_progress_sessions( self.gopp.course_id, self.gopp.flow_id, rule_tag=None, now_datetime=now(), past_due_only=True ) self.assertEqual( models.FlowSession.objects.filter(in_progress=True).count(), self.in_progress_sessions_count) self.assertEqual( models.FlowSession.objects.filter(in_progress=False).count(), self.ended_sessions_count) self.assertEqual( models.FlowPageVisitGrade.objects.count(), 0 )