diff --git a/cms/envs/common.py b/cms/envs/common.py index 07e17c727c..96fe79032a 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -368,7 +368,7 @@ MIDDLEWARE_CLASSES = ( # Allows us to dark-launch particular languages 'openedx.core.djangoapps.dark_lang.middleware.DarkLangMiddleware', - 'embargo.middleware.EmbargoMiddleware', + 'openedx.core.djangoapps.embargo.middleware.EmbargoMiddleware', # Detects user-requested locale from 'accept-language' header in http request 'django.middleware.locale.LocaleMiddleware', @@ -866,7 +866,7 @@ INSTALLED_APPS = ( 'django_openid_auth', # Country embargo support - 'embargo', + 'openedx.core.djangoapps.embargo', # Monitoring signals 'openedx.core.djangoapps.monitoring', diff --git a/common/djangoapps/course_modes/tests/test_views.py b/common/djangoapps/course_modes/tests/test_views.py index be2e7c2382..46e1ba2740 100644 --- a/common/djangoapps/course_modes/tests/test_views.py +++ b/common/djangoapps/course_modes/tests/test_views.py @@ -20,7 +20,7 @@ from xmodule.modulestore.tests.factories import CourseFactory from course_modes.models import CourseMode, Mode from course_modes.tests.factories import CourseModeFactory -from embargo.test_utils import restrict_course +from openedx.core.djangoapps.embargo.test_utils import restrict_course from student.models import CourseEnrollment from student.tests.factories import CourseEnrollmentFactory, UserFactory from util.testing import UrlResetMixin @@ -409,7 +409,7 @@ class CourseModeViewTest(UrlResetMixin, ModuleStoreTestCase): class TrackSelectionEmbargoTest(UrlResetMixin, ModuleStoreTestCase): """Test embargo restrictions on the track selection page. """ - URLCONF_MODULES = ['embargo'] + URLCONF_MODULES = ['openedx.core.djangoapps.embargo'] @patch.dict(settings.FEATURES, {'EMBARGO': True}) def setUp(self): diff --git a/common/djangoapps/course_modes/views.py b/common/djangoapps/course_modes/views.py index 57695c9da2..f74da9564c 100644 --- a/common/djangoapps/course_modes/views.py +++ b/common/djangoapps/course_modes/views.py @@ -23,7 +23,7 @@ from lms.djangoapps.commerce.utils import EcommerceService from course_modes.models import CourseMode from courseware.access import has_access from edxmako.shortcuts import render_to_response -from embargo import api as embargo_api +from openedx.core.djangoapps.embargo import api as embargo_api from student.models import CourseEnrollment from util.db import outer_atomic diff --git a/common/djangoapps/enrollment/tests/test_views.py b/common/djangoapps/enrollment/tests/test_views.py index 7409923bd4..8639480c1a 100644 --- a/common/djangoapps/enrollment/tests/test_views.py +++ b/common/djangoapps/enrollment/tests/test_views.py @@ -22,7 +22,6 @@ from django.test.utils import override_settings import pytz from course_modes.models import CourseMode -from embargo.models import CountryAccessRule, Country, RestrictedCourse from enrollment.views import EnrollmentUserThrottle from util.models import RateLimitConfiguration from util.testing import UrlResetMixin @@ -34,7 +33,8 @@ from openedx.core.lib.django_test_client_utils import get_absolute_url from student.models import CourseEnrollment from student.roles import CourseStaffRole from student.tests.factories import AdminFactory, CourseModeFactory, UserFactory -from embargo.test_utils import restrict_course +from openedx.core.djangoapps.embargo.models import CountryAccessRule, Country, RestrictedCourse +from openedx.core.djangoapps.embargo.test_utils import restrict_course class EnrollmentTestMixin(object): @@ -925,7 +925,7 @@ class EnrollmentEmbargoTest(EnrollmentTestMixin, UrlResetMixin, ModuleStoreTestC EMAIL = "bob@example.com" PASSWORD = "edx" - URLCONF_MODULES = ['embargo'] + URLCONF_MODULES = ['openedx.core.djangoapps.embargo'] @patch.dict(settings.FEATURES, {'EMBARGO': True}) def setUp(self): diff --git a/common/djangoapps/enrollment/views.py b/common/djangoapps/enrollment/views.py index ec84e5ee8c..c2bd566fb4 100644 --- a/common/djangoapps/enrollment/views.py +++ b/common/djangoapps/enrollment/views.py @@ -17,7 +17,7 @@ from rest_framework.response import Response from rest_framework.throttling import UserRateThrottle from rest_framework.views import APIView from opaque_keys.edx.keys import CourseKey -from embargo import api as embargo_api +from openedx.core.djangoapps.embargo import api as embargo_api from openedx.core.djangoapps.cors_csrf.authentication import SessionAuthenticationCrossDomainCsrf from openedx.core.djangoapps.cors_csrf.decorators import ensure_csrf_cookie_cross_domain from openedx.core.lib.api.authentication import ( diff --git a/common/djangoapps/student/tests/test_enrollment.py b/common/djangoapps/student/tests/test_enrollment.py index ce96ad3532..b7a73f50b4 100644 --- a/common/djangoapps/student/tests/test_enrollment.py +++ b/common/djangoapps/student/tests/test_enrollment.py @@ -12,7 +12,7 @@ from course_modes.models import CourseMode from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory from util.testing import UrlResetMixin -from embargo.test_utils import restrict_course +from openedx.core.djangoapps.embargo.test_utils import restrict_course from student.tests.factories import UserFactory, CourseModeFactory from student.models import CourseEnrollment, CourseFullError from student.roles import ( @@ -32,7 +32,7 @@ class EnrollmentTest(UrlResetMixin, SharedModuleStoreTestCase): USERNAME = "Bob" EMAIL = "bob@example.com" PASSWORD = "edx" - URLCONF_MODULES = ['embargo'] + URLCONF_MODULES = ['openedx.core.djangoapps.embargo'] @classmethod def setUpClass(cls): diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index aa0c0ce42f..f3ad650f92 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -111,7 +111,7 @@ from student.cookies import set_logged_in_cookies, delete_logged_in_cookies from student.models import anonymous_id_for_user, UserAttribute, EnrollStatusChange from shoppingcart.models import DonationConfiguration, CourseRegistrationCode -from embargo import api as embargo_api +from openedx.core.djangoapps.embargo import api as embargo_api import analytics from eventtracking import tracker diff --git a/docs/en_us/platform_api/source/conf.py b/docs/en_us/platform_api/source/conf.py index 807b1935f7..e11e9bf3d2 100644 --- a/docs/en_us/platform_api/source/conf.py +++ b/docs/en_us/platform_api/source/conf.py @@ -128,7 +128,7 @@ MOCK_MODULES = [ 'celery', 'celery.task', 'student.roles', - 'embargo.models', + 'openedx.core.djangoapps.embargo.models', 'xmodule.vertical_block', 'xmodule.course_module', 'user_api.accounts.api', diff --git a/lms/djangoapps/commerce/api/v0/tests/test_views.py b/lms/djangoapps/commerce/api/v0/tests/test_views.py index 60bdb1793c..f3b8491540 100644 --- a/lms/djangoapps/commerce/api/v0/tests/test_views.py +++ b/lms/djangoapps/commerce/api/v0/tests/test_views.py @@ -22,7 +22,7 @@ from commerce.tests.mocks import mock_basket_order, mock_create_basket from commerce.tests.test_views import UserMixin from course_modes.models import CourseMode from edx_rest_api_client import exceptions -from embargo.test_utils import restrict_course +from openedx.core.djangoapps.embargo.test_utils import restrict_course from enrollment.api import get_enrollment from openedx.core.lib.django_test_client_utils import get_absolute_url from student.models import CourseEnrollment diff --git a/lms/djangoapps/commerce/api/v0/views.py b/lms/djangoapps/commerce/api/v0/views.py index d3f6da98a3..3ea812412b 100644 --- a/lms/djangoapps/commerce/api/v0/views.py +++ b/lms/djangoapps/commerce/api/v0/views.py @@ -15,7 +15,7 @@ from commerce.exceptions import InvalidResponseError from commerce.http import DetailResponse, InternalRequestErrorResponse from course_modes.models import CourseMode from courseware import courses -from embargo import api as embargo_api +from openedx.core.djangoapps.embargo import api as embargo_api from enrollment.api import add_enrollment from enrollment.views import EnrollmentCrossDomainSessionAuth from openedx.core.djangoapps.commerce.utils import ecommerce_api_client diff --git a/lms/djangoapps/shoppingcart/tests/test_views.py b/lms/djangoapps/shoppingcart/tests/test_views.py index dc940fdac2..03d64db682 100644 --- a/lms/djangoapps/shoppingcart/tests/test_views.py +++ b/lms/djangoapps/shoppingcart/tests/test_views.py @@ -43,7 +43,7 @@ from courseware.tests.factories import InstructorFactory from student.models import CourseEnrollment from course_modes.models import CourseMode from edxmako.shortcuts import render_to_response -from embargo.test_utils import restrict_course +from openedx.core.djangoapps.embargo.test_utils import restrict_course from shoppingcart.processors import render_purchase_form_html from shoppingcart.admin import SoftDeleteCouponAdmin from shoppingcart.views import initialize_report @@ -1846,7 +1846,7 @@ class RedeemCodeEmbargoTests(UrlResetMixin, ModuleStoreTestCase): USERNAME = 'bob' PASSWORD = 'test' - URLCONF_MODULES = ['embargo'] + URLCONF_MODULES = ['openedx.core.djangoapps.embargo'] @patch.dict(settings.FEATURES, {'EMBARGO': True}) def setUp(self): diff --git a/lms/djangoapps/shoppingcart/views.py b/lms/djangoapps/shoppingcart/views.py index 988e023f59..d4e6c25762 100644 --- a/lms/djangoapps/shoppingcart/views.py +++ b/lms/djangoapps/shoppingcart/views.py @@ -29,7 +29,7 @@ from config_models.decorators import require_config from shoppingcart.reports import RefundReport, ItemizedPurchaseReport, UniversityRevenueShareReport, CertificateStatusReport from student.models import CourseEnrollment, EnrollmentClosedError, CourseFullError, \ AlreadyEnrolledError -from embargo import api as embargo_api +from openedx.core.djangoapps.embargo import api as embargo_api from .exceptions import ( ItemAlreadyInCartException, AlreadyEnrolledInCourseException, CourseDoesNotExistException, ReportTypeDoesNotExistException, diff --git a/lms/djangoapps/student_account/test/test_views.py b/lms/djangoapps/student_account/test/test_views.py index fb43b15bcc..d199dcac2d 100644 --- a/lms/djangoapps/student_account/test/test_views.py +++ b/lms/djangoapps/student_account/test/test_views.py @@ -281,7 +281,7 @@ class StudentAccountLoginAndRegistrationTest(ThirdPartyAuthTestMixin, UrlResetMi EMAIL = "bob@example.com" PASSWORD = "password" - URLCONF_MODULES = ['embargo'] + URLCONF_MODULES = ['openedx.core.djangoapps.embargo'] @mock.patch.dict(settings.FEATURES, {'EMBARGO': True}) def setUp(self): diff --git a/lms/djangoapps/verify_student/tests/test_views.py b/lms/djangoapps/verify_student/tests/test_views.py index f2a1c7f18f..c665f07891 100644 --- a/lms/djangoapps/verify_student/tests/test_views.py +++ b/lms/djangoapps/verify_student/tests/test_views.py @@ -37,7 +37,7 @@ from courseware.url_helpers import get_redirect_url from common.test.utils import XssTestMixin from commerce.models import CommerceConfiguration from commerce.tests import TEST_PAYMENT_DATA, TEST_API_URL, TEST_API_SIGNING_KEY, TEST_PUBLIC_URL_ROOT -from embargo.test_utils import restrict_course +from openedx.core.djangoapps.embargo.test_utils import restrict_course from openedx.core.djangoapps.user_api.accounts.api import get_account_settings from openedx.core.djangoapps.theming.tests.test_util import with_comprehensive_theme from shoppingcart.models import Order, CertificateItem @@ -104,7 +104,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin): YESTERDAY = NOW - timedelta(days=1) TOMORROW = NOW + timedelta(days=1) - URLCONF_MODULES = ['embargo'] + URLCONF_MODULES = ['openedx.core.djangoapps.embargo'] @mock.patch.dict(settings.FEATURES, {'EMBARGO': True}) def setUp(self): diff --git a/lms/djangoapps/verify_student/views.py b/lms/djangoapps/verify_student/views.py index 10f69d65a5..05889e5475 100644 --- a/lms/djangoapps/verify_student/views.py +++ b/lms/djangoapps/verify_student/views.py @@ -35,7 +35,7 @@ from course_modes.models import CourseMode from courseware.url_helpers import get_redirect_url from edx_rest_api_client.exceptions import SlumberBaseException from edxmako.shortcuts import render_to_response, render_to_string -from embargo import api as embargo_api +from openedx.core.djangoapps.embargo import api as embargo_api from openedx.core.djangoapps.commerce.utils import ecommerce_api_client from openedx.core.djangoapps.user_api.accounts import NAME_MIN_LENGTH from openedx.core.djangoapps.user_api.accounts.api import update_account_settings diff --git a/lms/envs/common.py b/lms/envs/common.py index 70b40c8627..684529b6fb 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -1143,9 +1143,8 @@ MIDDLEWARE_CLASSES = ( 'splash.middleware.SplashMiddleware', - 'openedx.core.djangoapps.geoinfo.middleware.CountryMiddleware', - 'embargo.middleware.EmbargoMiddleware', + 'openedx.core.djangoapps.embargo.middleware.EmbargoMiddleware', # Allows us to set user preferences 'openedx.core.djangoapps.lang_pref.middleware.LanguagePreferenceMiddleware', @@ -2042,7 +2041,7 @@ INSTALLED_APPS = ( 'rss_proxy', # Country embargo support - 'embargo', + 'openedx.core.djangoapps.embargo', # Monitoring functionality 'openedx.core.djangoapps.monitoring', diff --git a/lms/urls.py b/lms/urls.py index abec9f5444..daa61f8215 100644 --- a/lms/urls.py +++ b/lms/urls.py @@ -755,7 +755,7 @@ urlpatterns += ( # Embargo if settings.FEATURES.get('EMBARGO'): urlpatterns += ( - url(r'^embargo/', include('embargo.urls')), + url(r'^embargo/', include('openedx.core.djangoapps.embargo.urls')), ) # Survey Djangoapp diff --git a/common/djangoapps/embargo/__init__.py b/openedx/core/djangoapps/embargo/__init__.py similarity index 100% rename from common/djangoapps/embargo/__init__.py rename to openedx/core/djangoapps/embargo/__init__.py diff --git a/common/djangoapps/embargo/admin.py b/openedx/core/djangoapps/embargo/admin.py similarity index 89% rename from common/djangoapps/embargo/admin.py rename to openedx/core/djangoapps/embargo/admin.py index bc61f2ca31..72b267e70f 100644 --- a/common/djangoapps/embargo/admin.py +++ b/openedx/core/djangoapps/embargo/admin.py @@ -5,8 +5,12 @@ from django.contrib import admin import textwrap from config_models.admin import ConfigurationModelAdmin -from embargo.models import IPFilter, CountryAccessRule, RestrictedCourse -from embargo.forms import IPFilterForm, RestrictedCourseForm +from .models import ( + IPFilter, CountryAccessRule, RestrictedCourse +) +from .forms import ( + IPFilterForm, RestrictedCourseForm +) class IPFilterAdmin(ConfigurationModelAdmin): diff --git a/common/djangoapps/embargo/api.py b/openedx/core/djangoapps/embargo/api.py similarity index 99% rename from common/djangoapps/embargo/api.py rename to openedx/core/djangoapps/embargo/api.py index 40e578eee7..7ba8878808 100644 --- a/common/djangoapps/embargo/api.py +++ b/openedx/core/djangoapps/embargo/api.py @@ -15,7 +15,7 @@ from rest_framework import status from ipware.ip import get_ip from student.auth import has_course_author_access -from embargo.models import CountryAccessRule, RestrictedCourse +from .models import CountryAccessRule, RestrictedCourse log = logging.getLogger(__name__) diff --git a/common/djangoapps/embargo/exceptions.py b/openedx/core/djangoapps/embargo/exceptions.py similarity index 100% rename from common/djangoapps/embargo/exceptions.py rename to openedx/core/djangoapps/embargo/exceptions.py diff --git a/common/djangoapps/embargo/fixtures/__init__.py b/openedx/core/djangoapps/embargo/fixtures/__init__.py similarity index 100% rename from common/djangoapps/embargo/fixtures/__init__.py rename to openedx/core/djangoapps/embargo/fixtures/__init__.py diff --git a/common/djangoapps/embargo/fixtures/country_codes.py b/openedx/core/djangoapps/embargo/fixtures/country_codes.py similarity index 100% rename from common/djangoapps/embargo/fixtures/country_codes.py rename to openedx/core/djangoapps/embargo/fixtures/country_codes.py diff --git a/common/djangoapps/embargo/forms.py b/openedx/core/djangoapps/embargo/forms.py similarity index 98% rename from common/djangoapps/embargo/forms.py rename to openedx/core/djangoapps/embargo/forms.py index 12c845bfe2..9529f84b8b 100644 --- a/common/djangoapps/embargo/forms.py +++ b/openedx/core/djangoapps/embargo/forms.py @@ -11,7 +11,7 @@ from xmodule.modulestore.django import modulestore from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey -from embargo.models import IPFilter, RestrictedCourse +from .models import IPFilter, RestrictedCourse class RestrictedCourseForm(forms.ModelForm): diff --git a/common/djangoapps/embargo/messages.py b/openedx/core/djangoapps/embargo/messages.py similarity index 100% rename from common/djangoapps/embargo/messages.py rename to openedx/core/djangoapps/embargo/messages.py diff --git a/common/djangoapps/embargo/middleware.py b/openedx/core/djangoapps/embargo/middleware.py similarity index 98% rename from common/djangoapps/embargo/middleware.py rename to openedx/core/djangoapps/embargo/middleware.py index a8a285a0cc..c0d72524e9 100644 --- a/common/djangoapps/embargo/middleware.py +++ b/openedx/core/djangoapps/embargo/middleware.py @@ -35,8 +35,8 @@ from django.shortcuts import redirect from ipware.ip import get_ip from util.request import course_id_from_url -from embargo.models import IPFilter -from embargo import api as embargo_api +from .models import IPFilter +from . import api as embargo_api log = logging.getLogger(__name__) diff --git a/common/djangoapps/embargo/migrations/0001_initial.py b/openedx/core/djangoapps/embargo/migrations/0001_initial.py similarity index 100% rename from common/djangoapps/embargo/migrations/0001_initial.py rename to openedx/core/djangoapps/embargo/migrations/0001_initial.py diff --git a/common/djangoapps/embargo/migrations/0002_data__add_countries.py b/openedx/core/djangoapps/embargo/migrations/0002_data__add_countries.py similarity index 100% rename from common/djangoapps/embargo/migrations/0002_data__add_countries.py rename to openedx/core/djangoapps/embargo/migrations/0002_data__add_countries.py diff --git a/common/djangoapps/embargo/migrations/__init__.py b/openedx/core/djangoapps/embargo/migrations/__init__.py similarity index 100% rename from common/djangoapps/embargo/migrations/__init__.py rename to openedx/core/djangoapps/embargo/migrations/__init__.py diff --git a/common/djangoapps/embargo/models.py b/openedx/core/djangoapps/embargo/models.py similarity index 97% rename from common/djangoapps/embargo/models.py rename to openedx/core/djangoapps/embargo/models.py index 4c7f4ff055..a95dbf3e6b 100644 --- a/common/djangoapps/embargo/models.py +++ b/openedx/core/djangoapps/embargo/models.py @@ -8,7 +8,7 @@ file and check it in at the same time as your model changes. To do that, 1. Go to the edx-platform dir 2. ./manage.py lms schemamigration embargo --auto description_of_your_change -3. Add the migration file created in edx-platform/common/djangoapps/embargo/migrations/ +3. Add the migration file created in edx-platform/openedx/core/djangoapps/embargo/migrations/ """ import ipaddr @@ -27,8 +27,8 @@ from django_countries import countries from config_models.models import ConfigurationModel from openedx.core.djangoapps.xmodule_django.models import CourseKeyField, NoneToEmptyManager -from embargo.exceptions import InvalidAccessPoint -from embargo.messages import ENROLL_MESSAGES, COURSEWARE_MESSAGES +from .exceptions import InvalidAccessPoint +from .messages import ENROLL_MESSAGES, COURSEWARE_MESSAGES log = logging.getLogger(__name__) @@ -90,6 +90,9 @@ class EmbargoedState(ConfigurationModel): return [] return [country.strip().upper() for country in self.embargoed_countries.split(',')] + def __unicode__(self): + return self.embargoed_countries + class RestrictedCourse(models.Model): """Course with access restrictions. @@ -575,6 +578,7 @@ post_delete.connect(invalidate_country_rule_cache, sender=RestrictedCourse) class CourseAccessRuleHistory(models.Model): """History of course access rule changes. """ + # pylint: disable=model-missing-unicode timestamp = models.DateTimeField(db_index=True, auto_now_add=True) course_key = CourseKeyField(max_length=255, db_index=True) @@ -684,14 +688,14 @@ class IPFilter(ConfigurationModel): for network in self.networks: yield network - def __contains__(self, ip): + def __contains__(self, ip_addr): try: - ip = ipaddr.IPAddress(ip) + ip_addr = ipaddr.IPAddress(ip_addr) except ValueError: return False for network in self.networks: - if network.Contains(ip): + if network.Contains(ip_addr): return True return False @@ -713,3 +717,6 @@ class IPFilter(ConfigurationModel): if self.blacklist == '': return [] return self.IPFilterList([addr.strip() for addr in self.blacklist.split(',')]) + + def __unicode__(self): + return "Whitelist: {} - Blacklist: {}".format(self.whitelist_ips, self.blacklist_ips) diff --git a/common/djangoapps/embargo/test_utils.py b/openedx/core/djangoapps/embargo/test_utils.py similarity index 97% rename from common/djangoapps/embargo/test_utils.py rename to openedx/core/djangoapps/embargo/test_utils.py index dec25cf758..450e970fe7 100644 --- a/common/djangoapps/embargo/test_utils.py +++ b/openedx/core/djangoapps/embargo/test_utils.py @@ -6,7 +6,7 @@ import pygeoip from django.core.urlresolvers import reverse from django.core.cache import cache -from embargo.models import Country, CountryAccessRule, RestrictedCourse +from .models import Country, CountryAccessRule, RestrictedCourse @contextlib.contextmanager diff --git a/common/djangoapps/embargo/tests/__init__.py b/openedx/core/djangoapps/embargo/tests/__init__.py similarity index 100% rename from common/djangoapps/embargo/tests/__init__.py rename to openedx/core/djangoapps/embargo/tests/__init__.py diff --git a/common/djangoapps/embargo/tests/test_api.py b/openedx/core/djangoapps/embargo/tests/test_api.py similarity index 98% rename from common/djangoapps/embargo/tests/test_api.py rename to openedx/core/djangoapps/embargo/tests/test_api.py index 108b3b95bf..614e5cd67d 100644 --- a/common/djangoapps/embargo/tests/test_api.py +++ b/openedx/core/djangoapps/embargo/tests/test_api.py @@ -25,13 +25,13 @@ from student.roles import ( OrgStaffRole, OrgInstructorRole ) -from embargo.models import ( +from ..models import ( RestrictedCourse, Country, CountryAccessRule, ) from util.testing import UrlResetMixin -from embargo import api as embargo_api -from embargo.exceptions import InvalidAccessPoint +from .. import api as embargo_api +from ..exceptions import InvalidAccessPoint from mock import patch @@ -229,6 +229,9 @@ class EmbargoCheckAccessApiTests(ModuleStoreTestCase): @contextmanager def _mock_geoip(self, country_code): + """ + Mock for the GeoIP module. + """ with mock.patch.object(pygeoip.GeoIP, 'country_code_by_addr') as mock_ip: mock_ip.return_value = country_code yield @@ -240,7 +243,7 @@ class EmbargoCheckAccessApiTests(ModuleStoreTestCase): class EmbargoMessageUrlApiTests(UrlResetMixin, ModuleStoreTestCase): """Test the embargo API calls for retrieving the blocking message URLs. """ - URLCONF_MODULES = ['embargo'] + URLCONF_MODULES = ['openedx.core.djangoapps.embargo'] ENABLED_CACHES = ['default', 'mongo_metadata_inheritance', 'loc_cache'] @patch.dict(settings.FEATURES, {'EMBARGO': True}) diff --git a/common/djangoapps/embargo/tests/test_forms.py b/openedx/core/djangoapps/embargo/tests/test_forms.py similarity index 90% rename from common/djangoapps/embargo/tests/test_forms.py rename to openedx/core/djangoapps/embargo/tests/test_forms.py index 8b69f887cc..bfc032a975 100644 --- a/common/djangoapps/embargo/tests/test_forms.py +++ b/openedx/core/djangoapps/embargo/tests/test_forms.py @@ -9,8 +9,8 @@ from opaque_keys.edx.locator import CourseLocator # Explicitly import the cache from ConfigurationModel so we can reset it after each test from config_models.models import cache -from embargo.models import IPFilter -from embargo.forms import RestrictedCourseForm, IPFilterForm +from ..models import IPFilter +from ..forms import RestrictedCourseForm, IPFilterForm from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory @@ -40,13 +40,17 @@ class RestrictedCourseFormTest(ModuleStoreTestCase): self._assert_course_field_error(form) def _assert_course_field_error(self, form): - # Validation shouldn't work + """ + Validation shouldn't work. + """ self.assertFalse(form.is_valid()) msg = 'COURSE NOT FOUND' self.assertIn(msg, form._errors['course_key'][0]) # pylint: disable=protected-access - with self.assertRaisesRegexp(ValueError, "The RestrictedCourse could not be created because the data didn't validate."): + with self.assertRaisesRegexp( + ValueError, "The RestrictedCourse could not be created because the data didn't validate." + ): form.save() @@ -111,9 +115,11 @@ class IPFilterFormTest(TestCase): form = IPFilterForm(data=form_data) self.assertFalse(form.is_valid()) - wmsg = "Invalid IP Address(es): [u'.0.0.1', u':dead:beef:::', u'1.0.0.0/55'] Please fix the error(s) and try again." + wmsg = "Invalid IP Address(es): [u'.0.0.1', u':dead:beef:::', u'1.0.0.0/55']" \ + " Please fix the error(s) and try again." self.assertEquals(wmsg, form._errors['whitelist'][0]) # pylint: disable=protected-access - bmsg = "Invalid IP Address(es): [u'18.244.*', u'999999:c0a8:101::42', u'1.0.0.0/'] Please fix the error(s) and try again." + bmsg = "Invalid IP Address(es): [u'18.244.*', u'999999:c0a8:101::42', u'1.0.0.0/']" \ + " Please fix the error(s) and try again." self.assertEquals(bmsg, form._errors['blacklist'][0]) # pylint: disable=protected-access with self.assertRaisesRegexp(ValueError, "The IPFilter could not be created because the data didn't validate."): diff --git a/common/djangoapps/embargo/tests/test_middleware.py b/openedx/core/djangoapps/embargo/tests/test_middleware.py similarity index 98% rename from common/djangoapps/embargo/tests/test_middleware.py rename to openedx/core/djangoapps/embargo/tests/test_middleware.py index 55cac586df..cd64ab691c 100644 --- a/common/djangoapps/embargo/tests/test_middleware.py +++ b/openedx/core/djangoapps/embargo/tests/test_middleware.py @@ -17,8 +17,8 @@ from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from config_models.models import cache as config_cache -from embargo.models import RestrictedCourse, IPFilter -from embargo.test_utils import restrict_course +from ..models import RestrictedCourse, IPFilter +from ..test_utils import restrict_course @attr(shard=3) @@ -35,7 +35,7 @@ class EmbargoMiddlewareAccessTests(UrlResetMixin, ModuleStoreTestCase): USERNAME = 'fred' PASSWORD = 'secret' - URLCONF_MODULES = ['embargo'] + URLCONF_MODULES = ['openedx.core.djangoapps.embargo'] @patch.dict(settings.FEATURES, {'EMBARGO': True}) def setUp(self): diff --git a/common/djangoapps/embargo/tests/test_models.py b/openedx/core/djangoapps/embargo/tests/test_models.py similarity index 99% rename from common/djangoapps/embargo/tests/test_models.py rename to openedx/core/djangoapps/embargo/tests/test_models.py index 3f25d9d445..f05d4534c1 100644 --- a/common/djangoapps/embargo/tests/test_models.py +++ b/openedx/core/djangoapps/embargo/tests/test_models.py @@ -3,7 +3,7 @@ import json from django.test import TestCase from django.db.utils import IntegrityError from opaque_keys.edx.locator import CourseLocator -from embargo.models import ( +from ..models import ( EmbargoedCourse, EmbargoedState, IPFilter, RestrictedCourse, Country, CountryAccessRule, CourseAccessRuleHistory ) diff --git a/common/djangoapps/embargo/tests/test_views.py b/openedx/core/djangoapps/embargo/tests/test_views.py similarity index 97% rename from common/djangoapps/embargo/tests/test_views.py rename to openedx/core/djangoapps/embargo/tests/test_views.py index 0bc8f9ba62..48afff368c 100644 --- a/common/djangoapps/embargo/tests/test_views.py +++ b/openedx/core/djangoapps/embargo/tests/test_views.py @@ -7,7 +7,7 @@ from django.conf import settings import ddt from util.testing import UrlResetMixin -from embargo import messages +from .. import messages from openedx.core.djangolib.testing.utils import CacheIsolationTestCase from openedx.core.djangoapps.theming.tests.test_util import with_comprehensive_theme @@ -34,7 +34,7 @@ class CourseAccessMessageViewTest(CacheIsolationTestCase, UrlResetMixin): ENABLED_CACHES = ['default'] - URLCONF_MODULES = ['embargo'] + URLCONF_MODULES = ['openedx.core.djangoapps.embargo'] @patch.dict(settings.FEATURES, {'EMBARGO': True}) def setUp(self): diff --git a/common/djangoapps/embargo/urls.py b/openedx/core/djangoapps/embargo/urls.py similarity index 77% rename from common/djangoapps/embargo/urls.py rename to openedx/core/djangoapps/embargo/urls.py index 4f67b7da31..defd923d2c 100644 --- a/common/djangoapps/embargo/urls.py +++ b/openedx/core/djangoapps/embargo/urls.py @@ -2,11 +2,11 @@ from django.conf.urls import patterns, url -from embargo.views import CourseAccessMessageView +from .views import CourseAccessMessageView urlpatterns = patterns( - 'embargo.views', + 'openedx.core.djangoapps.embargo.views', url( r'^blocked-message/(?Penrollment|courseware)/(?P.+)/$', CourseAccessMessageView.as_view(), diff --git a/common/djangoapps/embargo/views.py b/openedx/core/djangoapps/embargo/views.py similarity index 98% rename from common/djangoapps/embargo/views.py rename to openedx/core/djangoapps/embargo/views.py index fe311ea01a..7e19220972 100644 --- a/common/djangoapps/embargo/views.py +++ b/openedx/core/djangoapps/embargo/views.py @@ -5,7 +5,7 @@ from django.views.generic.base import View from edxmako.shortcuts import render_to_response -from embargo import messages +from . import messages class CourseAccessMessageView(View):