def test_extract(self, monkeypatch):
        expected_results = dict(
            cumulative_active_user_count=52,  # previous cumulative is 50
            todays_active_user_count=2,
            total_user_count=len(self.users),
            course_count=len(CDM_INPUT_TEST_DATA),
            total_enrollment_count=150,
        )

        assert not StudentModule.objects.count()
        modified = as_datetime(self.date_for)

        def mock_student_modules_for_site(site):
            users = [UserFactory() for i in range(2)]
            for user in users:
                StudentModuleFactory(student=user, modified=modified)
                StudentModuleFactory(student=user, modified=modified)
            return StudentModule.objects.filter(student__in=users)

        monkeypatch.setattr(pipeline_sdm, 'get_student_modules_for_site',
                            mock_student_modules_for_site)

        for course in figures.sites.get_courses_for_site(self.site):
            assert course.created.date() < self.date_for
        for user in figures.sites.get_users_for_site(self.site):
            assert user.date_joined.date() < self.date_for

        actual = pipeline_sdm.SiteDailyMetricsExtractor().extract(
            site=self.site, date_for=self.date_for)

        for key, value in expected_results.iteritems():
            assert actual[key] == value, 'failed on key: "{}"'.format(key)
    def test_extract(self):
        expected_results = dict(
            cumulative_active_user_count=65,
            todays_active_user_count=15,
            total_user_count=len(self.users),
            course_count=len(CDM_INPUT_TEST_DATA),
            total_enrollment_count=150,
        )

        for course in CourseOverview.objects.all():
            assert course.created.date() < self.date_for
        for user in get_user_model().objects.all():
            assert user.date_joined.date() < self.date_for

        actual = pipeline_sdm.SiteDailyMetricsExtractor().extract(
            date_for=self.date_for)
        for key, value in expected_results.iteritems():
            assert actual[key] == value, 'failed on key: "{}"'.format(key)