diff --git a/common/djangoapps/student/tests/test_reset_password.py b/common/djangoapps/student/tests/test_reset_password.py index 8c3535014d..8c7262ca58 100644 --- a/common/djangoapps/student/tests/test_reset_password.py +++ b/common/djangoapps/student/tests/test_reset_password.py @@ -21,7 +21,7 @@ from django.utils.http import int_to_base36 from mock import Mock, patch import ddt -from lms.djangoapps.oauth_dispatch.tests import factories as dot_factories +from openedx.core.djangoapps.oauth_dispatch.tests import factories as dot_factories from openedx.core.djangolib.testing.utils import CacheIsolationTestCase from student.views import password_reset, password_reset_confirm_wrapper, SETTING_CHANGE_INITIATED from student.tests.factories import UserFactory diff --git a/lms/djangoapps/student_account/test/test_views.py b/lms/djangoapps/student_account/test/test_views.py index e572269670..fb43b15bcc 100644 --- a/lms/djangoapps/student_account/test/test_views.py +++ b/lms/djangoapps/student_account/test/test_views.py @@ -35,7 +35,7 @@ from commerce.models import CommerceConfiguration from commerce.tests import TEST_API_URL, TEST_API_SIGNING_KEY, factories from commerce.tests.mocks import mock_get_orders from course_modes.models import CourseMode -from lms.djangoapps.oauth_dispatch.tests import factories as dot_factories +from openedx.core.djangoapps.oauth_dispatch.tests import factories as dot_factories from openedx.core.djangoapps.programs.tests.mixins import ProgramsApiConfigMixin from openedx.core.djangoapps.user_api.accounts.api import activate_account, create_account from openedx.core.djangoapps.user_api.accounts import EMAIL_MAX_LENGTH diff --git a/lms/envs/common.py b/lms/envs/common.py index 8d6c33da6c..c03ec38834 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -440,7 +440,7 @@ OAUTH_EXPIRE_PUBLIC_CLIENT_DAYS = 30 ################################## DJANGO OAUTH TOOLKIT ####################################### OAUTH2_PROVIDER = { - 'OAUTH2_VALIDATOR_CLASS': 'lms.djangoapps.oauth_dispatch.dot_overrides.EdxOAuth2Validator', + 'OAUTH2_VALIDATOR_CLASS': 'openedx.core.djangoapps.oauth_dispatch.dot_overrides.EdxOAuth2Validator', 'SCOPES': { 'read': 'Read scope', 'write': 'Write scope', @@ -1927,7 +1927,7 @@ INSTALLED_APPS = ( # django-oauth-toolkit 'oauth2_provider', - 'lms.djangoapps.oauth_dispatch.apps.OAuthDispatchAppConfig', + 'openedx.core.djangoapps.oauth_dispatch.apps.OAuthDispatchAppConfig', 'third_party_auth', @@ -1937,7 +1937,7 @@ INSTALLED_APPS = ( # defined by oauth_provider. If those tables don't exist, an error can occur. 'oauth_provider', - 'auth_exchange', + 'openedx.core.djangoapps.auth_exchange', # For the wiki 'wiki', # The new django-wiki from benjaoming diff --git a/lms/urls.py b/lms/urls.py index 2e165ec27b..4c0392476d 100644 --- a/lms/urls.py +++ b/lms/urls.py @@ -8,10 +8,10 @@ from django.views.generic.base import RedirectView from ratelimitbackend import admin from django.conf.urls.static import static -import auth_exchange.views from courseware.views.views import EnrollStaffView from config_models.views import ConfigurationModelCurrentAPIView from courseware.views.index import CoursewareIndex +from openedx.core.djangoapps.auth_exchange.views import LoginWithAccessTokenView from openedx.core.djangoapps.catalog.models import CatalogIntegration from openedx.core.djangoapps.programs.models import ProgramsApiConfig from openedx.core.djangoapps.self_paced.models import SelfPacedConfiguration @@ -860,7 +860,7 @@ if settings.FEATURES.get('ENABLE_OAUTH2_PROVIDER'): urlpatterns += ( # These URLs dispatch to django-oauth-toolkit or django-oauth2-provider as appropriate. # Developers should use these routes, to maintain compatibility for existing client code - url(r'^oauth2/', include('lms.djangoapps.oauth_dispatch.urls')), + url(r'^oauth2/', include('openedx.core.djangoapps.oauth_dispatch.urls')), # These URLs contain the django-oauth2-provider default behavior. It exists to provide # URLs for django-oauth2-provider to call using reverse() with the oauth2 namespace, and # also to maintain support for views that have not yet been wrapped in dispatch views. @@ -938,7 +938,7 @@ if settings.FEATURES.get('ENABLE_OAUTH2_PROVIDER'): urlpatterns += ( url( r'^oauth2/login/$', - auth_exchange.views.LoginWithAccessTokenView.as_view(), + LoginWithAccessTokenView.as_view(), name="login_with_access_token" ), ) diff --git a/common/djangoapps/auth_exchange/__init__.py b/openedx/core/djangoapps/auth_exchange/__init__.py similarity index 100% rename from common/djangoapps/auth_exchange/__init__.py rename to openedx/core/djangoapps/auth_exchange/__init__.py diff --git a/common/djangoapps/auth_exchange/forms.py b/openedx/core/djangoapps/auth_exchange/forms.py similarity index 100% rename from common/djangoapps/auth_exchange/forms.py rename to openedx/core/djangoapps/auth_exchange/forms.py diff --git a/common/djangoapps/auth_exchange/models.py b/openedx/core/djangoapps/auth_exchange/models.py similarity index 100% rename from common/djangoapps/auth_exchange/models.py rename to openedx/core/djangoapps/auth_exchange/models.py diff --git a/common/djangoapps/auth_exchange/tests/__init__.py b/openedx/core/djangoapps/auth_exchange/tests/__init__.py similarity index 100% rename from common/djangoapps/auth_exchange/tests/__init__.py rename to openedx/core/djangoapps/auth_exchange/tests/__init__.py diff --git a/common/djangoapps/auth_exchange/tests/mixins.py b/openedx/core/djangoapps/auth_exchange/tests/mixins.py similarity index 96% rename from common/djangoapps/auth_exchange/tests/mixins.py rename to openedx/core/djangoapps/auth_exchange/tests/mixins.py index 450f789657..66d4a46dfe 100644 --- a/common/djangoapps/auth_exchange/tests/mixins.py +++ b/openedx/core/djangoapps/auth_exchange/tests/mixins.py @@ -8,8 +8,8 @@ Django-OAuth2-Provider. from unittest import skip, expectedFailure from django.test.client import RequestFactory -from lms.djangoapps.oauth_dispatch import adapters -from lms.djangoapps.oauth_dispatch.tests.constants import DUMMY_REDIRECT_URL +from openedx.core.djangoapps.oauth_dispatch import adapters +from openedx.core.djangoapps.oauth_dispatch.tests.constants import DUMMY_REDIRECT_URL from ..views import DOTAccessTokenExchangeView diff --git a/common/djangoapps/auth_exchange/tests/test_forms.py b/openedx/core/djangoapps/auth_exchange/tests/test_forms.py similarity index 100% rename from common/djangoapps/auth_exchange/tests/test_forms.py rename to openedx/core/djangoapps/auth_exchange/tests/test_forms.py diff --git a/common/djangoapps/auth_exchange/tests/test_views.py b/openedx/core/djangoapps/auth_exchange/tests/test_views.py similarity index 97% rename from common/djangoapps/auth_exchange/tests/test_views.py rename to openedx/core/djangoapps/auth_exchange/tests/test_views.py index 60c687960c..5541a44baf 100644 --- a/common/djangoapps/auth_exchange/tests/test_views.py +++ b/openedx/core/djangoapps/auth_exchange/tests/test_views.py @@ -70,7 +70,10 @@ class AccessTokenExchangeViewTest(AccessTokenExchangeTestMixin): self._setup_provider_response(success=True) for single_access_token in [True, False]: - with mock.patch("auth_exchange.views.constants.SINGLE_ACCESS_TOKEN", single_access_token): + with mock.patch( + "openedx.core.djangoapps.auth_exchange.views.constants.SINGLE_ACCESS_TOKEN", + single_access_token, + ): first_response = self.client.post(self.url, self.data) second_response = self.client.post(self.url, self.data) self.assertEqual(first_response.status_code, 200) diff --git a/common/djangoapps/auth_exchange/tests/utils.py b/openedx/core/djangoapps/auth_exchange/tests/utils.py similarity index 100% rename from common/djangoapps/auth_exchange/tests/utils.py rename to openedx/core/djangoapps/auth_exchange/tests/utils.py diff --git a/common/djangoapps/auth_exchange/views.py b/openedx/core/djangoapps/auth_exchange/views.py similarity index 96% rename from common/djangoapps/auth_exchange/views.py rename to openedx/core/djangoapps/auth_exchange/views.py index 6669e489c5..ea1d270ad5 100644 --- a/common/djangoapps/auth_exchange/views.py +++ b/openedx/core/djangoapps/auth_exchange/views.py @@ -26,8 +26,8 @@ from rest_framework.response import Response from rest_framework.views import APIView import social.apps.django_app.utils as social_utils -from auth_exchange.forms import AccessTokenExchangeForm -from lms.djangoapps.oauth_dispatch import adapters +from openedx.core.djangoapps.auth_exchange.forms import AccessTokenExchangeForm +from openedx.core.djangoapps.oauth_dispatch import adapters from openedx.core.lib.api.authentication import OAuth2AuthenticationAllowInactiveUser @@ -53,7 +53,7 @@ class AccessTokenExchangeBase(APIView): """ form = AccessTokenExchangeForm(request=request, oauth2_adapter=self.oauth2_adapter, data=request.POST) # pylint: disable=no-member if not form.is_valid(): - return self.error_response(form.errors) + return self.error_response(form.errors) # pylint: disable=no-member user = form.cleaned_data["user"] scope = form.cleaned_data["scope"] diff --git a/lms/djangoapps/oauth_dispatch/__init__.py b/openedx/core/djangoapps/oauth_dispatch/__init__.py similarity index 100% rename from lms/djangoapps/oauth_dispatch/__init__.py rename to openedx/core/djangoapps/oauth_dispatch/__init__.py diff --git a/lms/djangoapps/oauth_dispatch/adapters/__init__.py b/openedx/core/djangoapps/oauth_dispatch/adapters/__init__.py similarity index 100% rename from lms/djangoapps/oauth_dispatch/adapters/__init__.py rename to openedx/core/djangoapps/oauth_dispatch/adapters/__init__.py diff --git a/lms/djangoapps/oauth_dispatch/adapters/dop.py b/openedx/core/djangoapps/oauth_dispatch/adapters/dop.py similarity index 100% rename from lms/djangoapps/oauth_dispatch/adapters/dop.py rename to openedx/core/djangoapps/oauth_dispatch/adapters/dop.py diff --git a/lms/djangoapps/oauth_dispatch/adapters/dot.py b/openedx/core/djangoapps/oauth_dispatch/adapters/dot.py similarity index 100% rename from lms/djangoapps/oauth_dispatch/adapters/dot.py rename to openedx/core/djangoapps/oauth_dispatch/adapters/dot.py diff --git a/lms/djangoapps/oauth_dispatch/admin.py b/openedx/core/djangoapps/oauth_dispatch/admin.py similarity index 100% rename from lms/djangoapps/oauth_dispatch/admin.py rename to openedx/core/djangoapps/oauth_dispatch/admin.py diff --git a/lms/djangoapps/oauth_dispatch/apps.py b/openedx/core/djangoapps/oauth_dispatch/apps.py similarity index 79% rename from lms/djangoapps/oauth_dispatch/apps.py rename to openedx/core/djangoapps/oauth_dispatch/apps.py index 3ef5a571f4..fa43d0e374 100644 --- a/lms/djangoapps/oauth_dispatch/apps.py +++ b/openedx/core/djangoapps/oauth_dispatch/apps.py @@ -11,4 +11,4 @@ class OAuthDispatchAppConfig(AppConfig): """ OAuthDispatch Configuration """ - name = u'lms.djangoapps.oauth_dispatch' + name = u'openedx.core.djangoapps.oauth_dispatch' diff --git a/lms/djangoapps/oauth_dispatch/dot_overrides.py b/openedx/core/djangoapps/oauth_dispatch/dot_overrides.py similarity index 100% rename from lms/djangoapps/oauth_dispatch/dot_overrides.py rename to openedx/core/djangoapps/oauth_dispatch/dot_overrides.py diff --git a/lms/djangoapps/oauth_dispatch/tests/__init__.py b/openedx/core/djangoapps/oauth_dispatch/tests/__init__.py similarity index 100% rename from lms/djangoapps/oauth_dispatch/tests/__init__.py rename to openedx/core/djangoapps/oauth_dispatch/tests/__init__.py diff --git a/lms/djangoapps/oauth_dispatch/tests/constants.py b/openedx/core/djangoapps/oauth_dispatch/tests/constants.py similarity index 100% rename from lms/djangoapps/oauth_dispatch/tests/constants.py rename to openedx/core/djangoapps/oauth_dispatch/tests/constants.py diff --git a/lms/djangoapps/oauth_dispatch/tests/factories.py b/openedx/core/djangoapps/oauth_dispatch/tests/factories.py similarity index 100% rename from lms/djangoapps/oauth_dispatch/tests/factories.py rename to openedx/core/djangoapps/oauth_dispatch/tests/factories.py diff --git a/lms/djangoapps/oauth_dispatch/tests/mixins.py b/openedx/core/djangoapps/oauth_dispatch/tests/mixins.py similarity index 100% rename from lms/djangoapps/oauth_dispatch/tests/mixins.py rename to openedx/core/djangoapps/oauth_dispatch/tests/mixins.py diff --git a/lms/djangoapps/oauth_dispatch/tests/test_client_credentials.py b/openedx/core/djangoapps/oauth_dispatch/tests/test_client_credentials.py similarity index 95% rename from lms/djangoapps/oauth_dispatch/tests/test_client_credentials.py rename to openedx/core/djangoapps/oauth_dispatch/tests/test_client_credentials.py index 44f7bf92bd..d171e2107a 100644 --- a/lms/djangoapps/oauth_dispatch/tests/test_client_credentials.py +++ b/openedx/core/djangoapps/oauth_dispatch/tests/test_client_credentials.py @@ -2,7 +2,9 @@ from __future__ import unicode_literals import json +import unittest +from django.conf import settings from django.core.urlresolvers import reverse from django.test import TestCase from edx_oauth2_provider.tests.factories import ClientFactory @@ -15,6 +17,7 @@ from .constants import DUMMY_REDIRECT_URL from ..adapters import DOTAdapter +@unittest.skipUnless(settings.FEATURES.get("ENABLE_OAUTH2_PROVIDER"), "OAuth2 not enabled") class ClientCredentialsTest(mixins.AccessTokenMixin, TestCase): """ Tests validating the client credentials grant behavior. """ diff --git a/lms/djangoapps/oauth_dispatch/tests/test_dop_adapter.py b/openedx/core/djangoapps/oauth_dispatch/tests/test_dop_adapter.py similarity index 100% rename from lms/djangoapps/oauth_dispatch/tests/test_dop_adapter.py rename to openedx/core/djangoapps/oauth_dispatch/tests/test_dop_adapter.py diff --git a/lms/djangoapps/oauth_dispatch/tests/test_dot_adapter.py b/openedx/core/djangoapps/oauth_dispatch/tests/test_dot_adapter.py similarity index 100% rename from lms/djangoapps/oauth_dispatch/tests/test_dot_adapter.py rename to openedx/core/djangoapps/oauth_dispatch/tests/test_dot_adapter.py diff --git a/lms/djangoapps/oauth_dispatch/tests/test_dot_overrides.py b/openedx/core/djangoapps/oauth_dispatch/tests/test_dot_overrides.py similarity index 100% rename from lms/djangoapps/oauth_dispatch/tests/test_dot_overrides.py rename to openedx/core/djangoapps/oauth_dispatch/tests/test_dot_overrides.py diff --git a/lms/djangoapps/oauth_dispatch/tests/test_factories.py b/openedx/core/djangoapps/oauth_dispatch/tests/test_factories.py similarity index 96% rename from lms/djangoapps/oauth_dispatch/tests/test_factories.py rename to openedx/core/djangoapps/oauth_dispatch/tests/test_factories.py index a48c88dc83..b6553f0528 100644 --- a/lms/djangoapps/oauth_dispatch/tests/test_factories.py +++ b/openedx/core/djangoapps/oauth_dispatch/tests/test_factories.py @@ -3,7 +3,7 @@ from django.test import TestCase from oauth2_provider.models import Application, AccessToken, RefreshToken -from lms.djangoapps.oauth_dispatch.tests import factories +from openedx.core.djangoapps.oauth_dispatch.tests import factories from student.tests.factories import UserFactory diff --git a/lms/djangoapps/oauth_dispatch/tests/test_views.py b/openedx/core/djangoapps/oauth_dispatch/tests/test_views.py similarity index 93% rename from lms/djangoapps/oauth_dispatch/tests/test_views.py rename to openedx/core/djangoapps/oauth_dispatch/tests/test_views.py index 835f1db4d3..57d83b9597 100644 --- a/lms/djangoapps/oauth_dispatch/tests/test_views.py +++ b/openedx/core/djangoapps/oauth_dispatch/tests/test_views.py @@ -5,30 +5,33 @@ Tests for Blocks Views import json import ddt +from django.conf import settings from django.test import RequestFactory, TestCase from django.core.urlresolvers import reverse import httpretty from provider import constants +import unittest from student.tests.factories import UserFactory from third_party_auth.tests.utils import ThirdPartyOAuthTestMixin, ThirdPartyOAuthTestMixinGoogle from .constants import DUMMY_REDIRECT_URL from .. import adapters -from .. import views +if settings.FEATURES.get("ENABLE_OAUTH2_PROVIDER"): + from .. import views from . import mixins +@unittest.skipUnless(settings.FEATURES.get("ENABLE_OAUTH2_PROVIDER"), "OAuth2 not enabled") class _DispatchingViewTestCase(TestCase): """ Base class for tests that exercise DispatchingViews. + + Subclasses need to define self.url. """ dop_adapter = adapters.DOPAdapter() dot_adapter = adapters.DOTAdapter() - view_class = None - url = None - def setUp(self): super(_DispatchingViewTestCase, self).setUp() self.user = UserFactory() @@ -50,7 +53,7 @@ class _DispatchingViewTestCase(TestCase): Call the view with a POST request objectwith the appropriate format, returning the response object. """ - return self.client.post(self.url, self._post_body(user, client, token_type)) + return self.client.post(self.url, self._post_body(user, client, token_type)) # pylint: disable=no-member def _post_body(self, user, client, token_type=None): """ @@ -64,9 +67,10 @@ class TestAccessTokenView(mixins.AccessTokenMixin, _DispatchingViewTestCase): """ Test class for AccessTokenView """ - - view_class = views.AccessTokenView - url = reverse('access_token') + def setUp(self): + self.url = reverse('access_token') + self.view_class = views.AccessTokenView + super(TestAccessTokenView, self).setUp() def _post_body(self, user, client, token_type=None): """ @@ -124,9 +128,10 @@ class TestAccessTokenExchangeView(ThirdPartyOAuthTestMixinGoogle, ThirdPartyOAut """ Test class for AccessTokenExchangeView """ - - view_class = views.AccessTokenExchangeView - url = reverse('exchange_access_token', kwargs={'backend': 'google-oauth2'}) + def setUp(self): + self.url = reverse('exchange_access_token', kwargs={'backend': 'google-oauth2'}) + self.view_class = views.AccessTokenExchangeView + super(TestAccessTokenExchangeView, self).setUp() def _post_body(self, user, client, token_type=None): return { @@ -143,6 +148,7 @@ class TestAccessTokenExchangeView(ThirdPartyOAuthTestMixinGoogle, ThirdPartyOAut self.assertEqual(response.status_code, 200) +# pylint: disable=abstract-method @ddt.ddt class TestAuthorizationView(_DispatchingViewTestCase): """ @@ -231,6 +237,7 @@ class TestAuthorizationView(_DispatchingViewTestCase): return response.redirect_chain[-1][0] +@unittest.skipUnless(settings.FEATURES.get("ENABLE_OAUTH2_PROVIDER"), "OAuth2 not enabled") class TestViewDispatch(TestCase): """ Test that the DispatchingView dispatches the right way. @@ -324,12 +331,11 @@ class TestRevokeTokenView(_DispatchingViewTestCase): # pylint: disable=abstract """ Test class for RevokeTokenView """ - - login_with_access_token_url = reverse("login_with_access_token") - revoke_token_url = reverse('revoke_token') - access_token_url = reverse('access_token') - def setUp(self): + self.login_with_access_token_url = reverse("login_with_access_token") + self.revoke_token_url = reverse('revoke_token') + self.access_token_url = reverse('access_token') + super(TestRevokeTokenView, self).setUp() response = self.client.post(self.access_token_url, self.access_token_post_body_with_password()) access_token_data = json.loads(response.content) diff --git a/lms/djangoapps/oauth_dispatch/urls.py b/openedx/core/djangoapps/oauth_dispatch/urls.py similarity index 100% rename from lms/djangoapps/oauth_dispatch/urls.py rename to openedx/core/djangoapps/oauth_dispatch/urls.py diff --git a/lms/djangoapps/oauth_dispatch/views.py b/openedx/core/djangoapps/oauth_dispatch/views.py similarity index 98% rename from lms/djangoapps/oauth_dispatch/views.py rename to openedx/core/djangoapps/oauth_dispatch/views.py index 385cd7f46f..c1f351adde 100644 --- a/lms/djangoapps/oauth_dispatch/views.py +++ b/openedx/core/djangoapps/oauth_dispatch/views.py @@ -7,11 +7,11 @@ from __future__ import unicode_literals import json -from auth_exchange import views as auth_exchange_views from django.views.generic import View from edx_oauth2_provider import views as dop_views # django-oauth2-provider views from oauth2_provider import models as dot_models, views as dot_views # django-oauth-toolkit +from openedx.core.djangoapps.auth_exchange import views as auth_exchange_views from openedx.core.lib.token_utils import JwtBuilder from . import adapters diff --git a/openedx/core/lib/api/tests/test_authentication.py b/openedx/core/lib/api/tests/test_authentication.py index ad3f2f8ffb..17370706ab 100644 --- a/openedx/core/lib/api/tests/test_authentication.py +++ b/openedx/core/lib/api/tests/test_authentication.py @@ -27,7 +27,7 @@ from rest_framework.views import APIView from rest_framework_oauth import permissions from rest_framework_oauth.compat import oauth2_provider, oauth2_provider_scope -from lms.djangoapps.oauth_dispatch import adapters +from openedx.core.djangoapps.oauth_dispatch import adapters from openedx.core.lib.api import authentication factory = APIRequestFactory() # pylint: disable=invalid-name diff --git a/openedx/core/lib/tests/test_token_utils.py b/openedx/core/lib/tests/test_token_utils.py index 0841a93810..bd62a372c1 100644 --- a/openedx/core/lib/tests/test_token_utils.py +++ b/openedx/core/lib/tests/test_token_utils.py @@ -4,7 +4,7 @@ from django.test import TestCase import jwt from nose.plugins.attrib import attr -from lms.djangoapps.oauth_dispatch.tests import mixins +from openedx.core.djangoapps.oauth_dispatch.tests import mixins from openedx.core.lib.token_utils import JwtBuilder from student.tests.factories import UserFactory, UserProfileFactory