Merge pull request #20333 from edx/youngstrom/INCR-192

INCR-192
This commit is contained in:
Michael Youngstrom
2019-04-25 17:01:45 -04:00
committed by GitHub
12 changed files with 53 additions and 30 deletions

View File

@@ -1,13 +1,14 @@
# pylint: disable=missing-docstring
from __future__ import absolute_import
from datetime import datetime, timedelta
import factory
import pytz
from factory.django import DjangoModelFactory
from factory.fuzzy import FuzzyText
import pytz
from oauth2_provider.models import Application, AccessToken, RefreshToken
from oauth2_provider.models import AccessToken, Application, RefreshToken
from organizations.tests.factories import OrganizationFactory
from openedx.core.djangoapps.oauth_dispatch.models import ApplicationAccess, ApplicationOrganization

View File

@@ -1,11 +1,12 @@
"""
OAuth Dispatch test mixins
"""
from django.conf import settings
from __future__ import absolute_import
import jwt
from django.conf import settings
from jwkest.jwk import KEYS
from jwkest.jws import JWS
import jwt
from jwt.exceptions import ExpiredSignatureError
from student.models import UserProfile, anonymous_id_for_user

View File

@@ -1,12 +1,14 @@
""" Tests for OAuth Dispatch python API module. """
from __future__ import absolute_import
import unittest
from django.conf import settings
from django.http import HttpRequest
from django.test import TestCase
from oauth2_provider.models import AccessToken
from student.tests.factories import UserFactory
from student.tests.factories import UserFactory
OAUTH_PROVIDER_ENABLED = settings.FEATURES.get('ENABLE_OAUTH2_PROVIDER')
if OAUTH_PROVIDER_ENABLED:

View File

@@ -1,20 +1,21 @@
""" Tests for OAuth 2.0 client credentials support. """
from __future__ import unicode_literals
from __future__ import absolute_import, unicode_literals
import json
import unittest
from django.conf import settings
from django.urls import reverse
from django.test import TestCase
from django.urls import reverse
from edx_oauth2_provider.tests.factories import ClientFactory
from oauth2_provider.models import Application
from provider.oauth2.models import AccessToken
from student.tests.factories import UserFactory
from ..adapters import DOTAdapter
from . import mixins
from .constants import DUMMY_REDIRECT_URL
from ..adapters import DOTAdapter
@unittest.skipUnless(settings.FEATURES.get("ENABLE_OAUTH2_PROVIDER"), "OAuth2 not enabled")

View File

@@ -2,13 +2,15 @@
Tests for DOP Adapter
"""
from __future__ import absolute_import
from datetime import timedelta
import ddt
from django.test import TestCase
from django.utils.timezone import now
from provider.oauth2 import models
from provider import constants
from provider.oauth2 import models
from student.tests.factories import UserFactory

View File

@@ -2,15 +2,18 @@
Tests for DOT Adapter
"""
from __future__ import absolute_import
import unittest
from datetime import timedelta
import ddt
import six
from django.conf import settings
from django.test import TestCase
from django.utils.timezone import now
import ddt
from oauth2_provider import models
from student.tests.factories import UserFactory
# oauth_dispatch is not in CMS' INSTALLED_APPS so these imports will error during test collection
@@ -54,7 +57,7 @@ class DOTAdapterTestCase(TestCase):
"""
Make sure unicode representation of RestrictedApplication is correct
"""
self.assertEqual(unicode(self.restricted_app), u"<RestrictedApplication '{name}'>".format(
self.assertEqual(six.text_type(self.restricted_app), u"<RestrictedApplication '{name}'>".format(
name=self.restricted_client.name
))

View File

@@ -3,13 +3,16 @@ Test of custom django-oauth-toolkit behavior
"""
# pylint: disable=protected-access
from __future__ import absolute_import
import datetime
import unittest
from django.conf import settings
from django.contrib.auth.models import User
from django.test import RequestFactory, TestCase
from django.utils import timezone
from django.test import TestCase, RequestFactory
from student.tests.factories import UserFactory
# oauth_dispatch is not in CMS' INSTALLED_APPS so these imports will error during test collection

View File

@@ -1,9 +1,12 @@
# pylint: disable=missing-docstring
from __future__ import absolute_import
import unittest
from django.conf import settings
from django.test import TestCase
from oauth2_provider.models import Application, AccessToken, RefreshToken
import unittest
from oauth2_provider.models import AccessToken, Application, RefreshToken
from openedx.core.djangoapps.oauth_dispatch.tests import factories
from student.tests.factories import UserFactory

View File

@@ -1,15 +1,16 @@
""" Tests for OAuth Dispatch's jwt module. """
from __future__ import absolute_import
import itertools
from datetime import timedelta
from mock import patch
import ddt
from django.test import TestCase
from django.utils.timezone import now
from mock import patch
from openedx.core.djangoapps.oauth_dispatch import jwt as jwt_api
from openedx.core.djangoapps.oauth_dispatch.adapters import DOTAdapter, DOPAdapter
from openedx.core.djangoapps.oauth_dispatch.adapters import DOPAdapter, DOTAdapter
from openedx.core.djangoapps.oauth_dispatch.models import RestrictedApplication
from openedx.core.djangoapps.oauth_dispatch.tests.mixins import AccessTokenMixin
from openedx.core.djangoapps.oauth_dispatch.toggles import ENFORCE_JWT_SCOPES

View File

@@ -1,6 +1,9 @@
"""
Tests for oauth_dispatch models.
"""
from __future__ import absolute_import
import six
from django.test import TestCase
from openedx.core.djangoapps.oauth_dispatch.tests.factories import ApplicationOrganizationFactory
@@ -17,4 +20,4 @@ class ApplicationOrganizationTestCase(TestCase):
org_relation = ApplicationOrganizationFactory()
organization = org_relation.organization
jwt_filter_claim = org_relation.to_jwt_filter_claim()
assert jwt_filter_claim == unicode(':'.join([org_relation.relation_type, organization.short_name]))
assert jwt_filter_claim == six.text_type(':'.join([org_relation.relation_type, organization.short_name]))

View File

@@ -1,6 +1,8 @@
"""
Tests for custom DOT scopes backend.
"""
from __future__ import absolute_import
import ddt
from django.conf import settings
from django.test import TestCase
@@ -29,5 +31,5 @@ class ApplicationModelScopesTestCase(TestCase):
scopes = ApplicationModelScopes()
self.assertEqual(
set(scopes.get_available_scopes(application_access.application)),
set(settings.OAUTH2_DEFAULT_SCOPES.keys() + expected_additional_scopes),
set(list(settings.OAUTH2_DEFAULT_SCOPES.keys()) + expected_additional_scopes),
)

View File

@@ -2,26 +2,27 @@
Tests for Blocks Views
"""
from __future__ import absolute_import
import json
import unittest
import ddt
import httpretty
from django.conf import settings
from django.urls import reverse
from django.test import RequestFactory, TestCase
from mock import call, patch
from Cryptodome.PublicKey import RSA
from django.conf import settings
from django.test import RequestFactory, TestCase
from django.urls import reverse
from jwkest import jwk
from mock import call, patch
from oauth2_provider import models as dot_models
from organizations.tests.factories import OrganizationFactory
from provider import constants
from openedx.core.djangoapps.oauth_dispatch.toggles import ENFORCE_JWT_SCOPES
from provider import constants
from student.tests.factories import UserFactory
from third_party_auth.tests.utils import ThirdPartyOAuthTestMixin, ThirdPartyOAuthTestMixinGoogle
from . import mixins
# NOTE (CCB): We use this feature flag in a roundabout way to determine if the oauth_dispatch app is installed
@@ -559,7 +560,7 @@ class TestViewDispatch(TestCase):
msg_not_callable = _msg_base.format(view=view_candidate, reason=u'it is not callable')
msg_no_request = _msg_base.format(view=view_candidate, reason=u'it has no request argument')
self.assertTrue(hasattr(view_candidate, '__call__'), msg_not_callable)
args = view_candidate.func_code.co_varnames
args = view_candidate.__code__.co_varnames
self.assertTrue(args, msg_no_request)
self.assertEqual(args[0], 'request')