示例#1
0
    def test_edrec_exists_older_lcgm(self):
        ce = self.enrollments[0]
        older_date = days_from(self.date_for, -2)

        # Create existing Figures records
        EnrollmentDataFactory(site=self.site,
                              user=ce.user,
                              course_id=str(ce.course_id),
                              date_for=older_date)
        older_lcgm = LearnerCourseGradeMetricsFactory(site=self.site,
                                                      user=ce.user,
                                                      course_id=str(
                                                          ce.course_id),
                                                      date_for=older_date)

        # Make sure that the LCGM we created is the most recent one
        assert LearnerCourseGradeMetrics.objects.latest_lcgm(
            ce.user, ce.course_id) == older_lcgm
        # assert lcgm1 == older_lcgm
        # run our code under test
        ed, created = EnrollmentData.objects.update_metrics(self.site, ce)
        # verify our Figures records are updated
        after_lcgm = LearnerCourseGradeMetrics.objects.latest_lcgm(
            ce.user, ce.course_id)
        after_ed = EnrollmentData.objects.get(site=self.site,
                                              user=ce.user,
                                              course_id=str(ce.course_id))
        assert after_lcgm.date_for == self.date_for
        assert after_ed.date_for == self.date_for
 def test_calc_course_progress(self):
     """The course has EnrollmentData records
     """
     some_percentages = [0.0, 25.0, 50.0]
     expected_average = sum(some_percentages)/len(some_percentages)
     [
         EnrollmentDataFactory(course_id=str(self.course_overview.id), progress_percent=pp)
         for pp in some_percentages
     ]
     results = calculate_course_progress(self.course_overview.id)
     assert results['average_progress'] == pytest.approx(expected_average)
def test_backfill_enrollment_data_for_course(transactional_db, monkeypatch):
    """
    The Celery task is a simple wrapper around the pipeline function
    """
    course_id = 'course-v1:SomeOrg+SomeNum+SomeRun'
    ed_recs = [EnrollmentDataFactory() for _ in range(2)]

    func_path = 'figures.tasks.update_enrollment_data_for_course'
    monkeypatch.setattr(func_path, lambda course_id: ed_recs)
    ed_ids = backfill_enrollment_data_for_course(course_id)
    assert set(ed_ids) == set([obj.id for obj in ed_recs])
示例#4
0
 def setup(self, db):
     self.enrollment_data = EnrollmentDataFactory()
     self.expected_fields = [
         'id',
         'course_id',
         'date_enrolled',
         'is_enrolled',
         'is_completed',
         'progress_percent',
         'progress_details',
     ]
     self.date_enrolled_format = '%Y-%m-%d'
def test_set_enrollment_data_update_existing(site_data):
    """Test we update an existing EnrollmentData record
    """
    site = site_data['site']
    ce = site_data['enrollments'][0]
    lcgm = site_data['lcgm'][0]
    ed = EnrollmentDataFactory(site=site,
                               course_id=str(ce.course_id),
                               user=ce.user)
    assert EnrollmentData.objects.count() == 1
    obj, created = EnrollmentData.objects.set_enrollment_data(
        site=site, user=ce.user, course_id=ce.course_id)
    assert EnrollmentData.objects.count() == 1
示例#6
0
 def test_exists_no_force(self):
     ce = self.enrollments[0]
     construct_kwargs = dict(site=self.site,
                             user=ce.user,
                             course_id=str(ce.course_id),
                             date_for=self.date_for)
     before_ed = EnrollmentDataFactory(**construct_kwargs)
     LearnerCourseGradeMetricsFactory(**construct_kwargs)
     with patch(
             'figures.models.EnrollmentProgress._get_progress') as get_prog:
         ed, created = EnrollmentData.objects.update_metrics(self.site, ce)
         assert not get_prog.called
         assert ed == before_ed
示例#7
0
    def test_force_update(self):
        ce = self.enrollments[0]

        # Create existing Figures records
        # We only need to assign one progress value but we assign the possible
        # and earned for one to make sure that the earned is not more than the
        # possible. We arbitrarily choose points. We could have also chosen
        # sections or assigned both
        construct_kwargs = dict(site=self.site,
                                user=ce.user,
                                course_id=str(ce.course_id),
                                date_for=self.date_for,
                                points_earned=5,
                                points_possible=10)
        EnrollmentDataFactory(**construct_kwargs)
        before_lcgm = LearnerCourseGradeMetricsFactory(**construct_kwargs)

        fake_progress = dict(points_possible=50,
                             points_earned=25,
                             sections_possible=10,
                             sections_worked=5)

        with patch('figures.models.EnrollmentProgress._get_progress',
                   return_value=fake_progress):
            ed, created = EnrollmentData.objects.update_metrics(
                self.site, ce, force_update=True)

        # verify our Figures records are updated
        lcgm = LearnerCourseGradeMetrics.objects.latest_lcgm(
            ce.user, ce.course_id)
        check_ed = EnrollmentData.objects.get(site=self.site,
                                              user=ce.user,
                                              course_id=str(ce.course_id))
        assert check_ed == ed
        assert not created
        assert check_ed.date_for == self.date_for
        assert check_ed.points_earned == fake_progress['points_earned']
        assert lcgm.date_for == self.date_for
        assert lcgm.id == before_lcgm.id
        # We only need to check one of the progress fields to know it was updated
        assert lcgm.points_earned == fake_progress['points_earned']