コード例 #1
0
 def test_dates_lcgm_is_future_is_false(self):
     """
     Note: This should probably be an error state
     """
     lcgm = LearnerCourseGradeMetricsFactory(
         date_for=self.student_module.modified.date() +
         relativedelta(days=1))
     assert not _enrollment_metrics_needs_update(lcgm, self.student_module)
コード例 #2
0
 def test_existence_yes_lcgm_no_sm_is_false(self, caplog):
     lcgm = LearnerCourseGradeMetricsFactory()
     assert not _enrollment_metrics_needs_update(lcgm, None)
     last_log = caplog.records[-1]
     assert last_log.message.startswith('FIGURES:PIPELINE:LCGM')
     # import pdb; pdb.set_trace()
     assert lcgm.course_id in last_log.message
     assert str(lcgm.id) in last_log.message
     assert str(lcgm.user.id) in last_log.message
コード例 #3
0
    def test_has_lcgm_and_needs_update(self, monkeypatch):
        """We have an LCGM record, but it is not up to date with the SM

        The function under test should return a new LCGM

        TODO: Add test where we pass in `date_for` to the function under test
        """
        assert not LearnerCourseGradeMetrics.objects.filter(
            user=self.course_enrollment.user,
            course_id=str(self.course_enrollment.course_id)).exists()
        lcgm = self.create_lcgm(date_for=self.datetime_1.date(),
                                course_enrollment=self.course_enrollment)
        # lcgm = LearnerCourseGradeMetricsFactory()
        # Maybe remove these, but first make code sample to show how to mock
        # multisite. This helps in abstracting our tests, but risks wrong
        # behavior in production
        # If we do monkeypatch like this, we will need to also monkeypatch the
        # user belonging to the site
        monkeypatch.setattr(
            'figures.pipeline.enrollment_metrics.get_site_for_course',
            lambda val: self.site)
        monkeypatch.setattr(
            'figures.pipeline.enrollment_metrics._collect_progress_data',
            lambda val: self.progress_data)

        # assert isinstance(lcgm.date_for, date)
        # import pdb; pdb.set_trace()
        assert _enrollment_metrics_needs_update(lcgm, self.learner_sm[0])
        metrics = collect_metrics_for_enrollment(
            site=self.site,
            course_enrollment=self.course_enrollment,
            date_for=self.today,
            student_modules=self.learner_sm)

        self.check_response_metrics(metrics, self.progress_data)
        assert metrics != lcgm

        # This works because we pick dates in the past. Better is to  fix this
        # by either using freezegun or monkeypatching `_new_enrollment_metrics_record
        assert metrics.date_for >= self.datetime_2.date()
コード例 #4
0
 def test_dates_lcgm_is_past_is_true(self):
     lcgm = LearnerCourseGradeMetricsFactory(
         date_for=self.student_module.modified.date() -
         relativedelta(days=1))
     assert _enrollment_metrics_needs_update(lcgm, self.student_module)
コード例 #5
0
 def test_dates_lcgm_is_current_is_false(self):
     lcgm = LearnerCourseGradeMetricsFactory(
         date_for=self.student_module.modified.date())
     assert not _enrollment_metrics_needs_update(lcgm, self.student_module)
コード例 #6
0
 def test_existence_yes_lcgm_no_sm_is_false(self):
     path = 'figures.pipeline.enrollment_metrics.log_error'
     with mock.patch(path) as mock_log_error:
         assert not _enrollment_metrics_needs_update(
             LearnerCourseGradeMetricsFactory(), None)
         mock_log_error.assert_called()
コード例 #7
0
 def test_existence_no_lcgm_yes_sm_is_true(self):
     assert _enrollment_metrics_needs_update(None, self.student_module)
コード例 #8
0
 def test_existence_no_lcgm_no_sm_is_false(self):
     """Test if there is not a LearnerCourseGradeMetrics  record and not a
     SiteModule, then it returns false
     """
     assert not _enrollment_metrics_needs_update(None, None)