def setup(self, db, settings): # Set up data that's the same for standalone or multisite self.date_for = utc_yesterday() self.site = Site.objects.first() self.courses = [CourseOverviewFactory(), CourseOverviewFactory()] # Two for "our" course, one for another course in the same site self.enrollments = [ CourseEnrollmentFactory(course_id=self.courses[0].id), CourseEnrollmentFactory(course_id=self.courses[0].id), CourseEnrollmentFactory(course_id=self.courses[1].id), ] self.ce0_sm = StudentModuleFactory.from_course_enrollment( self.enrollments[0], created=as_datetime(self.date_for), modified=as_datetime(self.date_for)) # Handle site mode specifices if organizations_support_sites(): settings.FEATURES['FIGURES_IS_MULTISITE'] = True self.org = OrganizationFactory(sites=[self.site]) for course in self.courses: OrganizationCourseFactory(organization=self.org, course_id=str(course.id)) map_users_to_org(self.org, [ce.user for ce in self.enrollments]) # For our tests, we focus on a single enrollment. We should not # need to stand up other site data, but if we find we do need to, # then here's the place to do it else: self.org = OrganizationFactory()
def test_enrollments_active_on_date(self): our_date_for = fake.date_this_year() other_date_for = days_from(our_date_for, -1) our_ce = [ CourseEnrollmentFactory(course_id=self.course_overview.id) for _ in range(2) ] our_sm = [] for ce in our_ce: our_sm.extend([ StudentModuleFactory.from_course_enrollment( ce, modified=our_date_for), StudentModuleFactory.from_course_enrollment( ce, created=our_date_for) ]) # Create enrollment we should not get in our results other_ce = CourseEnrollmentFactory(course_id=self.course_overview.id) StudentModuleFactory.from_course_enrollment(other_ce, created=other_date_for, modified=other_date_for) course = Course(self.course_overview.id) found_ce = course.enrollments_active_on_date(our_date_for) assert set(found_ce) == set(our_ce)