Commit d3e6836d by bmedx

Fixes to common/openedx tests that reference apps CMS doesn't use

parent aa0377b0
...@@ -2,10 +2,13 @@ import unittest ...@@ -2,10 +2,13 @@ import unittest
from django.conf import settings from django.conf import settings
from django.test import RequestFactory from django.test import RequestFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from entitlements.api.v1.serializers import CourseEntitlementSerializer # Entitlements is not in CMS' INSTALLED_APPS so these imports will error during test collection
from entitlements.tests.factories import CourseEntitlementFactory if settings.ROOT_URLCONF == 'lms.urls':
from entitlements.api.v1.serializers import CourseEntitlementSerializer
from entitlements.tests.factories import CourseEntitlementFactory
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms') @unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
......
...@@ -6,12 +6,14 @@ from django.conf import settings ...@@ -6,12 +6,14 @@ from django.conf import settings
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
from entitlements.tests.factories import CourseEntitlementFactory
from entitlements.models import CourseEntitlement
from entitlements.api.v1.serializers import CourseEntitlementSerializer
from student.tests.factories import CourseEnrollmentFactory, UserFactory, TEST_PASSWORD from student.tests.factories import CourseEnrollmentFactory, UserFactory, TEST_PASSWORD
# Entitlements is not in CMS' INSTALLED_APPS so these imports will error during test collection
if settings.ROOT_URLCONF == 'lms.urls':
from entitlements.tests.factories import CourseEntitlementFactory
from entitlements.models import CourseEntitlement
from entitlements.api.v1.serializers import CourseEntitlementSerializer
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms') @unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
class EntitlementViewSetTest(ModuleStoreTestCase): class EntitlementViewSetTest(ModuleStoreTestCase):
......
...@@ -8,8 +8,10 @@ from django.core.cache import cache ...@@ -8,8 +8,10 @@ from django.core.cache import cache
from django.test import TestCase from django.test import TestCase
from opaque_keys.edx.locations import CourseLocator from opaque_keys.edx.locations import CourseLocator
from .models import CourseMessage, GlobalStatusMessage # Status is not in CMS' INSTALLED_APPS so these imports will error during test collection
from .status import get_site_status_msg if settings.ROOT_URLCONF == 'lms.urls':
from .models import CourseMessage, GlobalStatusMessage
from .status import get_site_status_msg
@ddt.ddt @ddt.ddt
......
"""Tests for cross-domain request views. """ """Tests for cross-domain request views. """
import ddt
import json import json
import unittest
from django.conf import settings
from django.core.urlresolvers import NoReverseMatch, reverse
from django.test import TestCase from django.test import TestCase
from django.core.urlresolvers import reverse, NoReverseMatch
import ddt
from config_models.models import cache from config_models.models import cache
from ..models import XDomainProxyConfiguration # cors_csrf is not in CMS' INSTALLED_APPS so these imports will error during test collection
if settings.ROOT_URLCONF == 'lms.urls':
from ..models import XDomainProxyConfiguration
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
@ddt.ddt @ddt.ddt
class XDomainProxyTest(TestCase): class XDomainProxyTest(TestCase):
"""Tests for the xdomain proxy end-point. """ """Tests for the xdomain proxy end-point. """
......
...@@ -2,20 +2,22 @@ ...@@ -2,20 +2,22 @@
Tests for DOT Adapter Tests for DOT Adapter
""" """
import unittest
from datetime import timedelta from datetime import timedelta
import ddt
from django.conf import settings from django.conf import settings
from django.test import TestCase from django.test import TestCase
from django.utils.timezone import now from django.utils.timezone import now
from oauth2_provider import models
import unittest
import ddt
from oauth2_provider import models
from student.tests.factories import UserFactory from student.tests.factories import UserFactory
from ..adapters import DOTAdapter # oauth_dispatch is not in CMS' INSTALLED_APPS so these imports will error during test collection
from .constants import DUMMY_REDIRECT_URL, DUMMY_REDIRECT_URL2 if settings.FEATURES.get("ENABLE_OAUTH2_PROVIDER"):
from ..models import RestrictedApplication from ..adapters import DOTAdapter
from .constants import DUMMY_REDIRECT_URL, DUMMY_REDIRECT_URL2
from ..models import RestrictedApplication
@ddt.ddt @ddt.ddt
...@@ -24,11 +26,9 @@ class DOTAdapterTestCase(TestCase): ...@@ -24,11 +26,9 @@ class DOTAdapterTestCase(TestCase):
""" """
Test class for DOTAdapter. Test class for DOTAdapter.
""" """
adapter = DOTAdapter()
def setUp(self): def setUp(self):
super(DOTAdapterTestCase, self).setUp() super(DOTAdapterTestCase, self).setUp()
self.adapter = DOTAdapter()
self.user = UserFactory() self.user = UserFactory()
self.public_client = self.adapter.create_public_client( self.public_client = self.adapter.create_public_client(
name='public app', name='public app',
......
...@@ -3,12 +3,18 @@ Test of custom django-oauth-toolkit behavior ...@@ -3,12 +3,18 @@ Test of custom django-oauth-toolkit behavior
""" """
# pylint: disable=protected-access # pylint: disable=protected-access
import unittest
from django.conf import settings
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.test import TestCase, RequestFactory from django.test import TestCase, RequestFactory
from ..dot_overrides import EdxOAuth2Validator
# oauth_dispatch is not in CMS' INSTALLED_APPS so these imports will error during test collection
if settings.ROOT_URLCONF == 'lms.urls':
from ..dot_overrides import EdxOAuth2Validator
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
class AuthenticateTestCase(TestCase): class AuthenticateTestCase(TestCase):
""" """
Test that users can authenticate with either username or email Test that users can authenticate with either username or email
...@@ -38,6 +44,7 @@ class AuthenticateTestCase(TestCase): ...@@ -38,6 +44,7 @@ class AuthenticateTestCase(TestCase):
) )
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
class CustomValidationTestCase(TestCase): class CustomValidationTestCase(TestCase):
""" """
Test custom user validation works. Test custom user validation works.
......
...@@ -12,22 +12,26 @@ from django.conf import settings ...@@ -12,22 +12,26 @@ from django.conf import settings
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.test import RequestFactory, TestCase, override_settings from django.test import RequestFactory, TestCase, override_settings
from oauth2_provider import models as dot_models from oauth2_provider import models as dot_models
from provider import constants
from provider import constants
from student.tests.factories import UserFactory from student.tests.factories import UserFactory
from third_party_auth.tests.utils import ThirdPartyOAuthTestMixin, ThirdPartyOAuthTestMixinGoogle from third_party_auth.tests.utils import ThirdPartyOAuthTestMixin, ThirdPartyOAuthTestMixinGoogle
from . import mixins from . import mixins
from .constants import DUMMY_REDIRECT_URL
from .. import adapters
from .. import models
# NOTE (CCB): We use this feature flag in a roundabout way to determine if the oauth_dispatch app is installed # NOTE (CCB): We use this feature flag in a roundabout way to determine if the oauth_dispatch app is installed
# in the current service--LMS or Studio. Normally we would check if settings.ROOT_URLCONF == 'lms.urls'; however, # in the current service--LMS or Studio. Normally we would check if settings.ROOT_URLCONF == 'lms.urls'; however,
# simply importing the views will results in an error due to the requisite apps not being installed (in Studio). Thus, # simply importing the views will results in an error due to the requisite apps not being installed (in Studio). Thus,
# we are left with this hack, of checking the feature flag which will never be True for Studio. # we are left with this hack, of checking the feature flag which will never be True for Studio.
#
# NOTE (BJM): As of Django 1.9 we also can't import models for apps which aren't in INSTALLED_APPS, so making all of
# these imports conditional except mixins, which doesn't currently import forbidden models, and is needed at test
# discovery time.
OAUTH_PROVIDER_ENABLED = settings.FEATURES.get('ENABLE_OAUTH2_PROVIDER') OAUTH_PROVIDER_ENABLED = settings.FEATURES.get('ENABLE_OAUTH2_PROVIDER')
if OAUTH_PROVIDER_ENABLED: if OAUTH_PROVIDER_ENABLED:
from .constants import DUMMY_REDIRECT_URL
from .. import adapters
from .. import models
from .. import views from .. import views
...@@ -75,11 +79,10 @@ class _DispatchingViewTestCase(TestCase): ...@@ -75,11 +79,10 @@ class _DispatchingViewTestCase(TestCase):
Subclasses need to define self.url. Subclasses need to define self.url.
""" """
dop_adapter = adapters.DOPAdapter()
dot_adapter = adapters.DOTAdapter()
def setUp(self): def setUp(self):
super(_DispatchingViewTestCase, self).setUp() super(_DispatchingViewTestCase, self).setUp()
self.dop_adapter = adapters.DOPAdapter()
self.dot_adapter = adapters.DOTAdapter()
self.user = UserFactory() self.user = UserFactory()
self.dot_app = self.dot_adapter.create_public_client( self.dot_app = self.dot_adapter.create_public_client(
name='test dot application', name='test dot application',
...@@ -270,10 +273,9 @@ class TestAuthorizationView(_DispatchingViewTestCase): ...@@ -270,10 +273,9 @@ class TestAuthorizationView(_DispatchingViewTestCase):
Test class for AuthorizationView Test class for AuthorizationView
""" """
dop_adapter = adapters.DOPAdapter()
def setUp(self): def setUp(self):
super(TestAuthorizationView, self).setUp() super(TestAuthorizationView, self).setUp()
self.dop_adapter = adapters.DOPAdapter()
self.user = UserFactory() self.user = UserFactory()
self.dot_app = self.dot_adapter.create_confidential_client( self.dot_app = self.dot_adapter.create_confidential_client(
name='test dot application', name='test dot application',
...@@ -399,11 +401,10 @@ class TestViewDispatch(TestCase): ...@@ -399,11 +401,10 @@ class TestViewDispatch(TestCase):
Test that the DispatchingView dispatches the right way. Test that the DispatchingView dispatches the right way.
""" """
dop_adapter = adapters.DOPAdapter()
dot_adapter = adapters.DOTAdapter()
def setUp(self): def setUp(self):
super(TestViewDispatch, self).setUp() super(TestViewDispatch, self).setUp()
self.dop_adapter = adapters.DOPAdapter()
self.dot_adapter = adapters.DOTAdapter()
self.user = UserFactory() self.user = UserFactory()
self.view = views._DispatchingView() # pylint: disable=protected-access self.view = views._DispatchingView() # pylint: disable=protected-access
self.dop_adapter.create_public_client( self.dop_adapter.create_public_client(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment