コード例 #1
0
    def test_latest_previous_record(self):
        course_overview = CourseOverviewFactory()

        # Create a set of records with non-continuous dates
        dates = [
            datetime.date(2019, 10, 1),
            datetime.date(2019, 10, 2),
            datetime.date(2019, 10, 5),
            datetime.date(2019, 10, 29),
            datetime.date(2019, 11, 3),
        ]
        for rec_date in dates:
            cdms = CourseDailyMetricsFactory(site=self.site,
                                             course_id = course_overview.id,
                                             date_for=rec_date)

        rec = CourseDailyMetrics.latest_previous_record(
            site=self.site,
            course_id=course_overview.id)
        assert rec.date_for == dates[-1]

        rec2 = CourseDailyMetrics.latest_previous_record(
            site=self.site,
            course_id=course_overview.id,
            date_for=dates[-1])
        assert rec2.date_for == dates[-2]

        rec3 = CourseDailyMetrics.latest_previous_record(
            site=self.site,
            course_id=course_overview.id,
            date_for=dates[0])
        assert not rec3
コード例 #2
0
    def test_with_invalid_average_progress(self, average_progress):
        """
        Apparently Django models don't validate automatically on save
        """
        assert average_progress < 0 or average_progress > 1
        rec = dict(site=self.site,
                   date_for=datetime.date(2018, 2, 2),
                   course_id='course-v1:SomeOrg+ABC01+2121',
                   enrollment_count=11,
                   active_learners_today=1,
                   average_progress=average_progress,
                   average_days_to_complete=5,
                   num_learners_completed=10)
        obj = CourseDailyMetrics(**rec)
        with pytest.raises(ValidationError) as execinfo:
            obj.clean_fields()

        assert 'average_progress' in execinfo.value.message_dict
コード例 #3
0
def cdm_test_data(db, settings):
    """Build CourseDailyMetrics data to test certificate counts
    """
    our_site = SiteFactory()
    mock_today = date(year=2020, month=6, day=7)
    last_month = mock_today - relativedelta(months=1)
    courses = [CourseOverviewFactory() for i in range(2)]
    # Create data for previous month. Just need one record
    # purpose is to make sure it is not included in our production code request
    prev_month_cdm = [
        CourseDailyMetrics(site=our_site,
                           course_id=str(courses[0].id),
                           date_for=last_month)
    ]

    # Create data for our current month
    curr_month_cdm = []
    cdm_data = [
        dict(day=1, course_id=str(courses[0].id), num_learners_completed=1),
        dict(day=6, course_id=str(courses[0].id), num_learners_completed=10),
        dict(day=1, course_id=str(courses[1].id), num_learners_completed=2),
        dict(day=6, course_id=str(courses[1].id), num_learners_completed=20),
    ]

    expected_cert_count = 30
    for rec in cdm_data:
        date_for = date(year=mock_today.year,
                        month=mock_today.month,
                        day=rec['day'])
        cdm = CourseDailyMetricsFactory(
            site=our_site,
            course_id=rec['course_id'],
            date_for=date_for,
            num_learners_completed=rec['num_learners_completed'])
        curr_month_cdm.append(cdm)

    if organizations_support_sites():
        settings.FEATURES['FIGURES_IS_MULTISITE'] = True
        our_org = OrganizationFactory(sites=[our_site])
        for course in courses:
            OrganizationCourseFactory(organization=our_org,
                                      course_id=str(course.id))
    return dict(
        mock_today=mock_today,
        our_site=our_site,
        courses=courses,
        prev_month_cdm=prev_month_cdm,
        curr_month_cdm=curr_month_cdm,
        expected_cert_count=expected_cert_count,
    )