Example #1
0
 def __init__(self,
              access_token,
              course_id,
              timeout=settings.LMS_DEFAULT_TIMEOUT):
     super(CourseAPIPresenterMixin, self).__init__(course_id, timeout)
     self.course_api_client = CourseStructureApiClient(
         settings.COURSE_API_URL, access_token)
Example #2
0
 def __init__(self,
              access_token,
              course_id,
              timeout=settings.LMS_DEFAULT_TIMEOUT):
     super(CoursePerformancePresenter,
           self).__init__(access_token, course_id, timeout)
     self.grading_policy_client = CourseStructureApiClient(
         settings.GRADING_POLICY_API_URL, access_token)
    def dispatch(self, request, *args, **kwargs):
        self.course_api_enabled = switch_is_active('enable_course_api')

        if self.course_api_enabled and request.user.is_authenticated():
            self.access_token = settings.COURSE_API_KEY or request.user.access_token
            self.course_api = CourseStructureApiClient(settings.COURSE_API_URL, self.access_token).courses

        return super(CourseAPIMixin, self).dispatch(request, *args, **kwargs)
Example #4
0
 def __init__(self,
              access_token,
              course_id,
              timeout=settings.LMS_DEFAULT_TIMEOUT):
     super(CoursePerformancePresenter,
           self).__init__(access_token, course_id, timeout)
     # the deprecated course structure API has grading policy. This will be replaced in AN-7716
     self.grading_policy_client = CourseStructureApiClient(
         settings.GRADING_POLICY_API_URL, access_token)
    def dispatch(self, request, *args, **kwargs):
        self.course_api_enabled = switch_is_active('enable_course_api')

        if self.course_api_enabled and request.user.is_authenticated():
            self.access_token = settings.COURSE_API_KEY or EdxRestApiClient.get_and_cache_jwt_oauth_access_token(
                settings.BACKEND_SERVICE_EDX_OAUTH2_PROVIDER_URL,
                settings.BACKEND_SERVICE_EDX_OAUTH2_KEY,
                settings.BACKEND_SERVICE_EDX_OAUTH2_SECRET,
            )[0]
            self.course_api = CourseStructureApiClient(settings.COURSE_API_URL,
                                                       self.access_token)

        return super(CourseAPIMixin, self).dispatch(request, *args, **kwargs)
Example #6
0
 def test_explicit_timeout(self):
     client = CourseStructureApiClient('http://example.com/', 'arbitrary_access_token', timeout=2.5)
     # pylint: disable=protected-access
     self.assertEqual(client._store['session'].timeout, 2.5)
Example #7
0
 def test_default_timeout(self):
     client = CourseStructureApiClient('http://example.com/', 'arbitrary_access_token')
     # pylint: disable=protected-access
     self.assertEqual(client._store['session'].timeout, settings.LMS_DEFAULT_TIMEOUT)
Example #8
0
 def test_required_args(self, url, access_token):
     with self.assertRaises(ValueError):
         CourseStructureApiClient(url, access_token)