def mock_refresh_all(self): """ Mock the E-Commerce API and refresh all course data. Returns: [dict]: List of dictionaries representing course content bodies. """ # Mock the call to the E-Commerce API, simulating multiple pages of data url = '{host}/courses/'.format(host=ECOMMERCE_API_URL) course_bodies = [ { 'id': 'a/b/c', 'url': 'https://ecommerce.example.com/api/v2/courses/a/b/c/', 'name': 'aaaaa', 'verification_deadline': '2022-01-01T01:00:00Z', 'type': 'verified', 'last_edited': '2015-08-19T15:47:24Z' }, { 'id': 'aaa/bbb/ccc', 'url': 'https://ecommerce.example.com/api/v2/courses/aaa/bbb/ccc/', 'name': 'Introduction to Biology - The Secret of Life', 'verification_deadline': None, 'type': 'audit', 'last_edited': '2015-08-06T19:11:19Z' } ] def request_callback(request): # pylint: disable=redefined-builtin next = None count = len(course_bodies) # Use the querystring to determine which page should be returned. Default to page 1. # Note that the values of the dict returned by `parse_qs` are lists, hence the `[1]` default value. qs = parse_qs(urlparse(request.path_url).query) page = int(qs.get('page', [1])[0]) if page < count: next = '{}?page={}'.format(url, page) body = { 'count': count, 'next': next, 'previous': None, 'results': [course_bodies[page - 1]] } return 200, {}, json.dumps(body) # pylint: disable=no-member responses.add_callback(responses.GET, url, callback=request_callback, content_type=JSON) # Refresh all course data Course.refresh_all(ACCESS_TOKEN) self.refresh_index() return course_bodies
def mock_refresh_all(self): """ Mock the E-Commerce API and refresh all course data. Returns: [dict]: List of dictionaries representing course content bodies. """ # Mock the call to the E-Commerce API, simulating multiple pages of data url = '{host}/courses/'.format(host=ECOMMERCE_API_URL) course_bodies = [{ 'id': 'a/b/c', 'url': 'https://ecommerce.example.com/api/v2/courses/a/b/c/', 'name': 'aaaaa', 'verification_deadline': '2022-01-01T01:00:00Z', 'type': 'verified', 'last_edited': '2015-08-19T15:47:24Z' }, { 'id': 'aaa/bbb/ccc', 'url': 'https://ecommerce.example.com/api/v2/courses/aaa/bbb/ccc/', 'name': 'Introduction to Biology - The Secret of Life', 'verification_deadline': None, 'type': 'audit', 'last_edited': '2015-08-06T19:11:19Z' }] def request_callback(request): # pylint: disable=redefined-builtin next = None count = len(course_bodies) # Use the querystring to determine which page should be returned. Default to page 1. # Note that the values of the dict returned by `parse_qs` are lists, hence the `[1]` default value. qs = parse_qs(urlparse(request.path_url).query) page = int(qs.get('page', [1])[0]) if page < count: next = '{}?page={}'.format(url, page) body = { 'count': count, 'next': next, 'previous': None, 'results': [course_bodies[page - 1]] } return 200, {}, json.dumps(body) # pylint: disable=no-member responses.add_callback(responses.GET, url, callback=request_callback, content_type=JSON) # Refresh all course data Course.refresh_all(ACCESS_TOKEN) self.refresh_index() return course_bodies
def handle(self, *args, **options): access_token = options.get('access_token') if not access_token: msg = 'Courses cannot be migrated if no access token is supplied.' logger.error(msg) raise CommandError(msg) Course.refresh_all(access_token=access_token)
def handle(self, *args, **options): access_token = options.get('access_token') if not access_token: msg = 'Courses cannot be migrated if no access token is supplied.' logger.error(msg) raise CommandError(msg) Course.refresh_all(access_token=access_token)