diff --git a/openedx/core/djangoapps/oauth_dispatch/tests/factories.py b/openedx/core/djangoapps/oauth_dispatch/tests/factories.py index afb969e4c9..0c887e27c4 100644 --- a/openedx/core/djangoapps/oauth_dispatch/tests/factories.py +++ b/openedx/core/djangoapps/oauth_dispatch/tests/factories.py @@ -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 diff --git a/openedx/core/djangoapps/oauth_dispatch/tests/mixins.py b/openedx/core/djangoapps/oauth_dispatch/tests/mixins.py index f7be4c94b1..4df899301e 100644 --- a/openedx/core/djangoapps/oauth_dispatch/tests/mixins.py +++ b/openedx/core/djangoapps/oauth_dispatch/tests/mixins.py @@ -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 diff --git a/openedx/core/djangoapps/oauth_dispatch/tests/test_api.py b/openedx/core/djangoapps/oauth_dispatch/tests/test_api.py index 5d99069bec..52e43686f6 100644 --- a/openedx/core/djangoapps/oauth_dispatch/tests/test_api.py +++ b/openedx/core/djangoapps/oauth_dispatch/tests/test_api.py @@ -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: diff --git a/openedx/core/djangoapps/oauth_dispatch/tests/test_client_credentials.py b/openedx/core/djangoapps/oauth_dispatch/tests/test_client_credentials.py index 433c709276..a273837043 100644 --- a/openedx/core/djangoapps/oauth_dispatch/tests/test_client_credentials.py +++ b/openedx/core/djangoapps/oauth_dispatch/tests/test_client_credentials.py @@ -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") diff --git a/openedx/core/djangoapps/oauth_dispatch/tests/test_dop_adapter.py b/openedx/core/djangoapps/oauth_dispatch/tests/test_dop_adapter.py index a4656478a7..9fd7dab044 100644 --- a/openedx/core/djangoapps/oauth_dispatch/tests/test_dop_adapter.py +++ b/openedx/core/djangoapps/oauth_dispatch/tests/test_dop_adapter.py @@ -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 diff --git a/openedx/core/djangoapps/oauth_dispatch/tests/test_dot_adapter.py b/openedx/core/djangoapps/oauth_dispatch/tests/test_dot_adapter.py index fb670c7a13..083d73f0a3 100644 --- a/openedx/core/djangoapps/oauth_dispatch/tests/test_dot_adapter.py +++ b/openedx/core/djangoapps/oauth_dispatch/tests/test_dot_adapter.py @@ -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"".format( + self.assertEqual(six.text_type(self.restricted_app), u"".format( name=self.restricted_client.name )) diff --git a/openedx/core/djangoapps/oauth_dispatch/tests/test_dot_overrides.py b/openedx/core/djangoapps/oauth_dispatch/tests/test_dot_overrides.py index 16f4510740..9c562a3103 100644 --- a/openedx/core/djangoapps/oauth_dispatch/tests/test_dot_overrides.py +++ b/openedx/core/djangoapps/oauth_dispatch/tests/test_dot_overrides.py @@ -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 diff --git a/openedx/core/djangoapps/oauth_dispatch/tests/test_factories.py b/openedx/core/djangoapps/oauth_dispatch/tests/test_factories.py index ebf530a78c..fd63d2b2cc 100644 --- a/openedx/core/djangoapps/oauth_dispatch/tests/test_factories.py +++ b/openedx/core/djangoapps/oauth_dispatch/tests/test_factories.py @@ -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 diff --git a/openedx/core/djangoapps/oauth_dispatch/tests/test_jwt.py b/openedx/core/djangoapps/oauth_dispatch/tests/test_jwt.py index 4e7f3d268f..8f978a8ccf 100644 --- a/openedx/core/djangoapps/oauth_dispatch/tests/test_jwt.py +++ b/openedx/core/djangoapps/oauth_dispatch/tests/test_jwt.py @@ -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 diff --git a/openedx/core/djangoapps/oauth_dispatch/tests/test_models.py b/openedx/core/djangoapps/oauth_dispatch/tests/test_models.py index 9045f1f995..750e119dea 100644 --- a/openedx/core/djangoapps/oauth_dispatch/tests/test_models.py +++ b/openedx/core/djangoapps/oauth_dispatch/tests/test_models.py @@ -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])) diff --git a/openedx/core/djangoapps/oauth_dispatch/tests/test_scopes.py b/openedx/core/djangoapps/oauth_dispatch/tests/test_scopes.py index dab7d186fd..e38ce227eb 100644 --- a/openedx/core/djangoapps/oauth_dispatch/tests/test_scopes.py +++ b/openedx/core/djangoapps/oauth_dispatch/tests/test_scopes.py @@ -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), ) diff --git a/openedx/core/djangoapps/oauth_dispatch/tests/test_views.py b/openedx/core/djangoapps/oauth_dispatch/tests/test_views.py index 1cf00d9f1d..284dc2dffb 100644 --- a/openedx/core/djangoapps/oauth_dispatch/tests/test_views.py +++ b/openedx/core/djangoapps/oauth_dispatch/tests/test_views.py @@ -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')