def test_caching(self): # Add fake course enrollment information to the fake data API fake_data_api.add_course(self.COURSE_ID, course_modes=['honor', 'verified', 'audit']) # Hit the fake data API. details = api.get_course_enrollment_details(self.COURSE_ID) # Reset the fake data API, should rely on the cache. fake_data_api.reset() cached_details = api.get_course_enrollment_details(self.COURSE_ID) # The data matches self.assertEqual(len(details['course_modes']), 3) self.assertEqual(details, cached_details)
def get(self, request, course_id=None): """Read enrollment information for a particular course. HTTP Endpoint for retrieving course level enrollment information. Args: request (Request): To get current course enrollment information, a GET request will return information for the specified course. course_id (str): URI element specifying the course location. Enrollment information will be returned. Return: A JSON serialized representation of the course enrollment details. """ try: return Response( api.get_course_enrollment_details( course_id, bool(request.GET.get('include_expired', '')))) except CourseNotFoundError: return Response( status=status.HTTP_400_BAD_REQUEST, data={ "message": (u"No course found for course ID '{course_id}'").format( course_id=course_id) })
def get(self, request, course_id=None): """Read enrollment information for a particular course. HTTP Endpoint for retrieving course level enrollment information. Args: request (Request): To get current course enrollment information, a GET request will return information for the specified course. course_id (str): URI element specifying the course location. Enrollment information will be returned. Return: A JSON serialized representation of the course enrollment details. """ try: return Response(api.get_course_enrollment_details(course_id)) except CourseNotFoundError: return Response( status=status.HTTP_400_BAD_REQUEST, data={ "message": ( u"No course found for course ID '{course_id}'" ).format(course_id=course_id) } )
def test_get_course_details(self): # Add a fake course enrollment information to the fake data API fake_data_api.add_course(self.COURSE_ID, course_modes=['honor', 'verified', 'audit']) result = api.get_course_enrollment_details(self.COURSE_ID) self.assertEquals(result['course_id'], self.COURSE_ID) self.assertEquals(3, len(result['course_modes']))
def course_open_for_self_enrollment(course_key): """ For a given course_key, determine if the course is available for enrollment """ # Check to see if learners can enroll themselves. if not can_self_enroll_in_course(course_key): return False # Check the enrollment start and end dates. course_details = get_course_enrollment_details(unicode(course_key)) now = datetime.now().replace(tzinfo=pytz.UTC) start = course_details['enrollment_start'] end = course_details['enrollment_end'] start = start if start is not None else now end = end if end is not None else now # If we are not within the start and end date for enrollment. if now < start or end < now: return False return True