def setUp(self): super(FlowPageVisitGradeTest, self).setUp() self.user = factories.UserFactory() self.participation = factories.ParticipationFactory(course=self.course, user=self.user) fs = factories.FlowSessionFactory(participation=self.participation) self.fpdata = factories.FlowPageDataFactory(flow_session=fs)
def setUpTestData(cls): # noqa super(CourseAdminSessionRelatedMixin, cls).setUpTestData() course1_session = factories.FlowSessionFactory.create( participation=cls.course1_student_participation2, flow_id="001-linalg-recap") course1_flow_page_data = factories.FlowPageDataFactory.create( flow_session=course1_session) factories.FlowPageVisitFactory.create(page_data=course1_flow_page_data) course2_sessions = factories.FlowSessionFactory.create_batch( size=3, participation=cls.course2_student_participation) cls.course2_session4 = factories.FlowSessionFactory(course=cls.course2, participation=None, user=None) for session in course2_sessions: course2_flow_page_data = factories.FlowPageDataFactory.create( flow_session=session, ) factories.FlowPageVisitFactory.create( page_data=course2_flow_page_data, answer={"answer": "hi"}) # a flow session without page_ordinal course2_non_ordinal_flow_page_data = factories.FlowPageDataFactory( flow_session=cls.course2_session4, page_ordinal=None) factories.FlowPageVisitFactory( page_data=course2_non_ordinal_flow_page_data) course1_sessions = models.FlowSession.objects.filter( course=cls.course1) cls.course1_session_count = course1_sessions.count() course1_visits = models.FlowPageVisit.objects.filter( flow_session__course=cls.course1) cls.course1_visits_count = course1_visits.count() cls.course1_visits_has_answer_count = course1_visits.filter( answer__isnull=False).count() cls.course2_sessions = models.FlowSession.objects.filter( course=cls.course2) cls.course2_session_count = cls.course2_sessions.count() course2_visits = models.FlowPageVisit.objects.filter( flow_session__course=cls.course2) cls.course2_visits_count = course2_visits.count() cls.course2_visits_has_answer_count = course2_visits.filter( answer__isnull=False).count()
def test_last_activity(self): fs = factories.FlowSessionFactory(participation=self.participation) fpdata = factories.FlowPageDataFactory(flow_session=fs) factories.FlowPageVisitFactory(page_data=fpdata, answer=None, visit_time=datetime(2019, 1, 1, tzinfo=pytz.UTC)) factories.FlowPageVisitFactory(page_data=fpdata, answer=None, visit_time=datetime(2019, 1, 2, tzinfo=pytz.UTC)) self.assertEqual(fs.last_activity(), None) fpv = factories.FlowPageVisitFactory( page_data=fpdata, answer={"answer": "hi"}, visit_time=datetime(2018, 12, 31, tzinfo=pytz.UTC)) self.assertEqual(fs.last_activity(), fpv.visit_time)
def test_unicode(self): fs = factories.FlowSessionFactory(participation=self.participation) fpdata = factories.FlowPageDataFactory(flow_session=fs) self.assertIsNotNone(str(fpdata))