Commit cd522358 by John Eskew Committed by GitHub

Merge pull request #13706 from edx/jeskew/move_embargo_out_of_common

Move embargo from common to openedx/core/djangoapps.
parents 246bd19e e3cb462d
...@@ -368,7 +368,7 @@ MIDDLEWARE_CLASSES = ( ...@@ -368,7 +368,7 @@ MIDDLEWARE_CLASSES = (
# Allows us to dark-launch particular languages # Allows us to dark-launch particular languages
'openedx.core.djangoapps.dark_lang.middleware.DarkLangMiddleware', '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 # Detects user-requested locale from 'accept-language' header in http request
'django.middleware.locale.LocaleMiddleware', 'django.middleware.locale.LocaleMiddleware',
...@@ -866,7 +866,7 @@ INSTALLED_APPS = ( ...@@ -866,7 +866,7 @@ INSTALLED_APPS = (
'django_openid_auth', 'django_openid_auth',
# Country embargo support # Country embargo support
'embargo', 'openedx.core.djangoapps.embargo',
# Monitoring signals # Monitoring signals
'openedx.core.djangoapps.monitoring', 'openedx.core.djangoapps.monitoring',
......
...@@ -20,7 +20,7 @@ from xmodule.modulestore.tests.factories import CourseFactory ...@@ -20,7 +20,7 @@ from xmodule.modulestore.tests.factories import CourseFactory
from course_modes.models import CourseMode, Mode from course_modes.models import CourseMode, Mode
from course_modes.tests.factories import CourseModeFactory 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.models import CourseEnrollment
from student.tests.factories import CourseEnrollmentFactory, UserFactory from student.tests.factories import CourseEnrollmentFactory, UserFactory
from util.testing import UrlResetMixin from util.testing import UrlResetMixin
...@@ -409,7 +409,7 @@ class CourseModeViewTest(UrlResetMixin, ModuleStoreTestCase): ...@@ -409,7 +409,7 @@ class CourseModeViewTest(UrlResetMixin, ModuleStoreTestCase):
class TrackSelectionEmbargoTest(UrlResetMixin, ModuleStoreTestCase): class TrackSelectionEmbargoTest(UrlResetMixin, ModuleStoreTestCase):
"""Test embargo restrictions on the track selection page. """ """Test embargo restrictions on the track selection page. """
URLCONF_MODULES = ['embargo'] URLCONF_MODULES = ['openedx.core.djangoapps.embargo']
@patch.dict(settings.FEATURES, {'EMBARGO': True}) @patch.dict(settings.FEATURES, {'EMBARGO': True})
def setUp(self): def setUp(self):
......
...@@ -23,7 +23,7 @@ from lms.djangoapps.commerce.utils import EcommerceService ...@@ -23,7 +23,7 @@ from lms.djangoapps.commerce.utils import EcommerceService
from course_modes.models import CourseMode from course_modes.models import CourseMode
from courseware.access import has_access from courseware.access import has_access
from edxmako.shortcuts import render_to_response 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 student.models import CourseEnrollment
from util.db import outer_atomic from util.db import outer_atomic
......
...@@ -22,7 +22,6 @@ from django.test.utils import override_settings ...@@ -22,7 +22,6 @@ from django.test.utils import override_settings
import pytz import pytz
from course_modes.models import CourseMode from course_modes.models import CourseMode
from embargo.models import CountryAccessRule, Country, RestrictedCourse
from enrollment.views import EnrollmentUserThrottle from enrollment.views import EnrollmentUserThrottle
from util.models import RateLimitConfiguration from util.models import RateLimitConfiguration
from util.testing import UrlResetMixin from util.testing import UrlResetMixin
...@@ -34,7 +33,8 @@ from openedx.core.lib.django_test_client_utils import get_absolute_url ...@@ -34,7 +33,8 @@ from openedx.core.lib.django_test_client_utils import get_absolute_url
from student.models import CourseEnrollment from student.models import CourseEnrollment
from student.roles import CourseStaffRole from student.roles import CourseStaffRole
from student.tests.factories import AdminFactory, CourseModeFactory, UserFactory 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): class EnrollmentTestMixin(object):
...@@ -925,7 +925,7 @@ class EnrollmentEmbargoTest(EnrollmentTestMixin, UrlResetMixin, ModuleStoreTestC ...@@ -925,7 +925,7 @@ class EnrollmentEmbargoTest(EnrollmentTestMixin, UrlResetMixin, ModuleStoreTestC
EMAIL = "bob@example.com" EMAIL = "bob@example.com"
PASSWORD = "edx" PASSWORD = "edx"
URLCONF_MODULES = ['embargo'] URLCONF_MODULES = ['openedx.core.djangoapps.embargo']
@patch.dict(settings.FEATURES, {'EMBARGO': True}) @patch.dict(settings.FEATURES, {'EMBARGO': True})
def setUp(self): def setUp(self):
......
...@@ -17,7 +17,7 @@ from rest_framework.response import Response ...@@ -17,7 +17,7 @@ from rest_framework.response import Response
from rest_framework.throttling import UserRateThrottle from rest_framework.throttling import UserRateThrottle
from rest_framework.views import APIView from rest_framework.views import APIView
from opaque_keys.edx.keys import CourseKey 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.authentication import SessionAuthenticationCrossDomainCsrf
from openedx.core.djangoapps.cors_csrf.decorators import ensure_csrf_cookie_cross_domain from openedx.core.djangoapps.cors_csrf.decorators import ensure_csrf_cookie_cross_domain
from openedx.core.lib.api.authentication import ( from openedx.core.lib.api.authentication import (
......
...@@ -12,7 +12,7 @@ from course_modes.models import CourseMode ...@@ -12,7 +12,7 @@ from course_modes.models import CourseMode
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
from util.testing import UrlResetMixin 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.tests.factories import UserFactory, CourseModeFactory
from student.models import CourseEnrollment, CourseFullError from student.models import CourseEnrollment, CourseFullError
from student.roles import ( from student.roles import (
...@@ -32,7 +32,7 @@ class EnrollmentTest(UrlResetMixin, SharedModuleStoreTestCase): ...@@ -32,7 +32,7 @@ class EnrollmentTest(UrlResetMixin, SharedModuleStoreTestCase):
USERNAME = "Bob" USERNAME = "Bob"
EMAIL = "bob@example.com" EMAIL = "bob@example.com"
PASSWORD = "edx" PASSWORD = "edx"
URLCONF_MODULES = ['embargo'] URLCONF_MODULES = ['openedx.core.djangoapps.embargo']
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
......
...@@ -111,7 +111,7 @@ from student.cookies import set_logged_in_cookies, delete_logged_in_cookies ...@@ -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 student.models import anonymous_id_for_user, UserAttribute, EnrollStatusChange
from shoppingcart.models import DonationConfiguration, CourseRegistrationCode 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 import analytics
from eventtracking import tracker from eventtracking import tracker
......
...@@ -128,7 +128,7 @@ MOCK_MODULES = [ ...@@ -128,7 +128,7 @@ MOCK_MODULES = [
'celery', 'celery',
'celery.task', 'celery.task',
'student.roles', 'student.roles',
'embargo.models', 'openedx.core.djangoapps.embargo.models',
'xmodule.vertical_block', 'xmodule.vertical_block',
'xmodule.course_module', 'xmodule.course_module',
'user_api.accounts.api', 'user_api.accounts.api',
......
...@@ -22,7 +22,7 @@ from commerce.tests.mocks import mock_basket_order, mock_create_basket ...@@ -22,7 +22,7 @@ from commerce.tests.mocks import mock_basket_order, mock_create_basket
from commerce.tests.test_views import UserMixin from commerce.tests.test_views import UserMixin
from course_modes.models import CourseMode from course_modes.models import CourseMode
from edx_rest_api_client import exceptions 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 enrollment.api import get_enrollment
from openedx.core.lib.django_test_client_utils import get_absolute_url from openedx.core.lib.django_test_client_utils import get_absolute_url
from student.models import CourseEnrollment from student.models import CourseEnrollment
......
...@@ -15,7 +15,7 @@ from commerce.exceptions import InvalidResponseError ...@@ -15,7 +15,7 @@ from commerce.exceptions import InvalidResponseError
from commerce.http import DetailResponse, InternalRequestErrorResponse from commerce.http import DetailResponse, InternalRequestErrorResponse
from course_modes.models import CourseMode from course_modes.models import CourseMode
from courseware import courses 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.api import add_enrollment
from enrollment.views import EnrollmentCrossDomainSessionAuth from enrollment.views import EnrollmentCrossDomainSessionAuth
from openedx.core.djangoapps.commerce.utils import ecommerce_api_client from openedx.core.djangoapps.commerce.utils import ecommerce_api_client
......
...@@ -43,7 +43,7 @@ from courseware.tests.factories import InstructorFactory ...@@ -43,7 +43,7 @@ from courseware.tests.factories import InstructorFactory
from student.models import CourseEnrollment from student.models import CourseEnrollment
from course_modes.models import CourseMode from course_modes.models import CourseMode
from edxmako.shortcuts import render_to_response 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.processors import render_purchase_form_html
from shoppingcart.admin import SoftDeleteCouponAdmin from shoppingcart.admin import SoftDeleteCouponAdmin
from shoppingcart.views import initialize_report from shoppingcart.views import initialize_report
...@@ -1846,7 +1846,7 @@ class RedeemCodeEmbargoTests(UrlResetMixin, ModuleStoreTestCase): ...@@ -1846,7 +1846,7 @@ class RedeemCodeEmbargoTests(UrlResetMixin, ModuleStoreTestCase):
USERNAME = 'bob' USERNAME = 'bob'
PASSWORD = 'test' PASSWORD = 'test'
URLCONF_MODULES = ['embargo'] URLCONF_MODULES = ['openedx.core.djangoapps.embargo']
@patch.dict(settings.FEATURES, {'EMBARGO': True}) @patch.dict(settings.FEATURES, {'EMBARGO': True})
def setUp(self): def setUp(self):
......
...@@ -29,7 +29,7 @@ from config_models.decorators import require_config ...@@ -29,7 +29,7 @@ from config_models.decorators import require_config
from shoppingcart.reports import RefundReport, ItemizedPurchaseReport, UniversityRevenueShareReport, CertificateStatusReport from shoppingcart.reports import RefundReport, ItemizedPurchaseReport, UniversityRevenueShareReport, CertificateStatusReport
from student.models import CourseEnrollment, EnrollmentClosedError, CourseFullError, \ from student.models import CourseEnrollment, EnrollmentClosedError, CourseFullError, \
AlreadyEnrolledError AlreadyEnrolledError
from embargo import api as embargo_api from openedx.core.djangoapps.embargo import api as embargo_api
from .exceptions import ( from .exceptions import (
ItemAlreadyInCartException, AlreadyEnrolledInCourseException, ItemAlreadyInCartException, AlreadyEnrolledInCourseException,
CourseDoesNotExistException, ReportTypeDoesNotExistException, CourseDoesNotExistException, ReportTypeDoesNotExistException,
......
...@@ -281,7 +281,7 @@ class StudentAccountLoginAndRegistrationTest(ThirdPartyAuthTestMixin, UrlResetMi ...@@ -281,7 +281,7 @@ class StudentAccountLoginAndRegistrationTest(ThirdPartyAuthTestMixin, UrlResetMi
EMAIL = "bob@example.com" EMAIL = "bob@example.com"
PASSWORD = "password" PASSWORD = "password"
URLCONF_MODULES = ['embargo'] URLCONF_MODULES = ['openedx.core.djangoapps.embargo']
@mock.patch.dict(settings.FEATURES, {'EMBARGO': True}) @mock.patch.dict(settings.FEATURES, {'EMBARGO': True})
def setUp(self): def setUp(self):
......
...@@ -37,7 +37,7 @@ from courseware.url_helpers import get_redirect_url ...@@ -37,7 +37,7 @@ from courseware.url_helpers import get_redirect_url
from common.test.utils import XssTestMixin from common.test.utils import XssTestMixin
from commerce.models import CommerceConfiguration from commerce.models import CommerceConfiguration
from commerce.tests import TEST_PAYMENT_DATA, TEST_API_URL, TEST_API_SIGNING_KEY, TEST_PUBLIC_URL_ROOT 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.user_api.accounts.api import get_account_settings
from openedx.core.djangoapps.theming.tests.test_util import with_comprehensive_theme from openedx.core.djangoapps.theming.tests.test_util import with_comprehensive_theme
from shoppingcart.models import Order, CertificateItem from shoppingcart.models import Order, CertificateItem
...@@ -104,7 +104,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin): ...@@ -104,7 +104,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
YESTERDAY = NOW - timedelta(days=1) YESTERDAY = NOW - timedelta(days=1)
TOMORROW = 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}) @mock.patch.dict(settings.FEATURES, {'EMBARGO': True})
def setUp(self): def setUp(self):
......
...@@ -35,7 +35,7 @@ from course_modes.models import CourseMode ...@@ -35,7 +35,7 @@ from course_modes.models import CourseMode
from courseware.url_helpers import get_redirect_url from courseware.url_helpers import get_redirect_url
from edx_rest_api_client.exceptions import SlumberBaseException from edx_rest_api_client.exceptions import SlumberBaseException
from edxmako.shortcuts import render_to_response, render_to_string 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.commerce.utils import ecommerce_api_client
from openedx.core.djangoapps.user_api.accounts import NAME_MIN_LENGTH from openedx.core.djangoapps.user_api.accounts import NAME_MIN_LENGTH
from openedx.core.djangoapps.user_api.accounts.api import update_account_settings from openedx.core.djangoapps.user_api.accounts.api import update_account_settings
......
...@@ -1143,9 +1143,8 @@ MIDDLEWARE_CLASSES = ( ...@@ -1143,9 +1143,8 @@ MIDDLEWARE_CLASSES = (
'splash.middleware.SplashMiddleware', 'splash.middleware.SplashMiddleware',
'openedx.core.djangoapps.geoinfo.middleware.CountryMiddleware', 'openedx.core.djangoapps.geoinfo.middleware.CountryMiddleware',
'embargo.middleware.EmbargoMiddleware', 'openedx.core.djangoapps.embargo.middleware.EmbargoMiddleware',
# Allows us to set user preferences # Allows us to set user preferences
'openedx.core.djangoapps.lang_pref.middleware.LanguagePreferenceMiddleware', 'openedx.core.djangoapps.lang_pref.middleware.LanguagePreferenceMiddleware',
...@@ -2042,7 +2041,7 @@ INSTALLED_APPS = ( ...@@ -2042,7 +2041,7 @@ INSTALLED_APPS = (
'rss_proxy', 'rss_proxy',
# Country embargo support # Country embargo support
'embargo', 'openedx.core.djangoapps.embargo',
# Monitoring functionality # Monitoring functionality
'openedx.core.djangoapps.monitoring', 'openedx.core.djangoapps.monitoring',
......
...@@ -755,7 +755,7 @@ urlpatterns += ( ...@@ -755,7 +755,7 @@ urlpatterns += (
# Embargo # Embargo
if settings.FEATURES.get('EMBARGO'): if settings.FEATURES.get('EMBARGO'):
urlpatterns += ( urlpatterns += (
url(r'^embargo/', include('embargo.urls')), url(r'^embargo/', include('openedx.core.djangoapps.embargo.urls')),
) )
# Survey Djangoapp # Survey Djangoapp
......
...@@ -5,8 +5,12 @@ from django.contrib import admin ...@@ -5,8 +5,12 @@ from django.contrib import admin
import textwrap import textwrap
from config_models.admin import ConfigurationModelAdmin from config_models.admin import ConfigurationModelAdmin
from embargo.models import IPFilter, CountryAccessRule, RestrictedCourse from .models import (
from embargo.forms import IPFilterForm, RestrictedCourseForm IPFilter, CountryAccessRule, RestrictedCourse
)
from .forms import (
IPFilterForm, RestrictedCourseForm
)
class IPFilterAdmin(ConfigurationModelAdmin): class IPFilterAdmin(ConfigurationModelAdmin):
......
...@@ -15,7 +15,7 @@ from rest_framework import status ...@@ -15,7 +15,7 @@ from rest_framework import status
from ipware.ip import get_ip from ipware.ip import get_ip
from student.auth import has_course_author_access from student.auth import has_course_author_access
from embargo.models import CountryAccessRule, RestrictedCourse from .models import CountryAccessRule, RestrictedCourse
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
......
...@@ -11,7 +11,7 @@ from xmodule.modulestore.django import modulestore ...@@ -11,7 +11,7 @@ from xmodule.modulestore.django import modulestore
from opaque_keys import InvalidKeyError from opaque_keys import InvalidKeyError
from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.keys import CourseKey
from embargo.models import IPFilter, RestrictedCourse from .models import IPFilter, RestrictedCourse
class RestrictedCourseForm(forms.ModelForm): class RestrictedCourseForm(forms.ModelForm):
......
...@@ -35,8 +35,8 @@ from django.shortcuts import redirect ...@@ -35,8 +35,8 @@ from django.shortcuts import redirect
from ipware.ip import get_ip from ipware.ip import get_ip
from util.request import course_id_from_url from util.request import course_id_from_url
from embargo.models import IPFilter from .models import IPFilter
from embargo import api as embargo_api from . import api as embargo_api
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
......
...@@ -8,7 +8,7 @@ file and check it in at the same time as your model changes. To do that, ...@@ -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 1. Go to the edx-platform dir
2. ./manage.py lms schemamigration embargo --auto description_of_your_change 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 import ipaddr
...@@ -27,8 +27,8 @@ from django_countries import countries ...@@ -27,8 +27,8 @@ from django_countries import countries
from config_models.models import ConfigurationModel from config_models.models import ConfigurationModel
from openedx.core.djangoapps.xmodule_django.models import CourseKeyField, NoneToEmptyManager from openedx.core.djangoapps.xmodule_django.models import CourseKeyField, NoneToEmptyManager
from embargo.exceptions import InvalidAccessPoint from .exceptions import InvalidAccessPoint
from embargo.messages import ENROLL_MESSAGES, COURSEWARE_MESSAGES from .messages import ENROLL_MESSAGES, COURSEWARE_MESSAGES
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
...@@ -90,6 +90,9 @@ class EmbargoedState(ConfigurationModel): ...@@ -90,6 +90,9 @@ class EmbargoedState(ConfigurationModel):
return [] return []
return [country.strip().upper() for country in self.embargoed_countries.split(',')] return [country.strip().upper() for country in self.embargoed_countries.split(',')]
def __unicode__(self):
return self.embargoed_countries
class RestrictedCourse(models.Model): class RestrictedCourse(models.Model):
"""Course with access restrictions. """Course with access restrictions.
...@@ -575,6 +578,7 @@ post_delete.connect(invalidate_country_rule_cache, sender=RestrictedCourse) ...@@ -575,6 +578,7 @@ post_delete.connect(invalidate_country_rule_cache, sender=RestrictedCourse)
class CourseAccessRuleHistory(models.Model): class CourseAccessRuleHistory(models.Model):
"""History of course access rule changes. """ """History of course access rule changes. """
# pylint: disable=model-missing-unicode
timestamp = models.DateTimeField(db_index=True, auto_now_add=True) timestamp = models.DateTimeField(db_index=True, auto_now_add=True)
course_key = CourseKeyField(max_length=255, db_index=True) course_key = CourseKeyField(max_length=255, db_index=True)
...@@ -684,14 +688,14 @@ class IPFilter(ConfigurationModel): ...@@ -684,14 +688,14 @@ class IPFilter(ConfigurationModel):
for network in self.networks: for network in self.networks:
yield network yield network
def __contains__(self, ip): def __contains__(self, ip_addr):
try: try:
ip = ipaddr.IPAddress(ip) ip_addr = ipaddr.IPAddress(ip_addr)
except ValueError: except ValueError:
return False return False
for network in self.networks: for network in self.networks:
if network.Contains(ip): if network.Contains(ip_addr):
return True return True
return False return False
...@@ -713,3 +717,6 @@ class IPFilter(ConfigurationModel): ...@@ -713,3 +717,6 @@ class IPFilter(ConfigurationModel):
if self.blacklist == '': if self.blacklist == '':
return [] return []
return self.IPFilterList([addr.strip() for addr in self.blacklist.split(',')]) return self.IPFilterList([addr.strip() for addr in self.blacklist.split(',')])
def __unicode__(self):
return "Whitelist: {} - Blacklist: {}".format(self.whitelist_ips, self.blacklist_ips)
...@@ -6,7 +6,7 @@ import pygeoip ...@@ -6,7 +6,7 @@ import pygeoip
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.core.cache import cache from django.core.cache import cache
from embargo.models import Country, CountryAccessRule, RestrictedCourse from .models import Country, CountryAccessRule, RestrictedCourse
@contextlib.contextmanager @contextlib.contextmanager
......
...@@ -25,13 +25,13 @@ from student.roles import ( ...@@ -25,13 +25,13 @@ from student.roles import (
OrgStaffRole, OrgInstructorRole OrgStaffRole, OrgInstructorRole
) )
from embargo.models import ( from ..models import (
RestrictedCourse, Country, CountryAccessRule, RestrictedCourse, Country, CountryAccessRule,
) )
from util.testing import UrlResetMixin from util.testing import UrlResetMixin
from embargo import api as embargo_api from .. import api as embargo_api
from embargo.exceptions import InvalidAccessPoint from ..exceptions import InvalidAccessPoint
from mock import patch from mock import patch
...@@ -229,6 +229,9 @@ class EmbargoCheckAccessApiTests(ModuleStoreTestCase): ...@@ -229,6 +229,9 @@ class EmbargoCheckAccessApiTests(ModuleStoreTestCase):
@contextmanager @contextmanager
def _mock_geoip(self, country_code): def _mock_geoip(self, country_code):
"""
Mock for the GeoIP module.
"""
with mock.patch.object(pygeoip.GeoIP, 'country_code_by_addr') as mock_ip: with mock.patch.object(pygeoip.GeoIP, 'country_code_by_addr') as mock_ip:
mock_ip.return_value = country_code mock_ip.return_value = country_code
yield yield
...@@ -240,7 +243,7 @@ class EmbargoCheckAccessApiTests(ModuleStoreTestCase): ...@@ -240,7 +243,7 @@ class EmbargoCheckAccessApiTests(ModuleStoreTestCase):
class EmbargoMessageUrlApiTests(UrlResetMixin, ModuleStoreTestCase): class EmbargoMessageUrlApiTests(UrlResetMixin, ModuleStoreTestCase):
"""Test the embargo API calls for retrieving the blocking message URLs. """ """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'] ENABLED_CACHES = ['default', 'mongo_metadata_inheritance', 'loc_cache']
@patch.dict(settings.FEATURES, {'EMBARGO': True}) @patch.dict(settings.FEATURES, {'EMBARGO': True})
......
...@@ -9,8 +9,8 @@ from opaque_keys.edx.locator import CourseLocator ...@@ -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 # Explicitly import the cache from ConfigurationModel so we can reset it after each test
from config_models.models import cache from config_models.models import cache
from embargo.models import IPFilter from ..models import IPFilter
from embargo.forms import RestrictedCourseForm, IPFilterForm from ..forms import RestrictedCourseForm, IPFilterForm
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
...@@ -40,13 +40,17 @@ class RestrictedCourseFormTest(ModuleStoreTestCase): ...@@ -40,13 +40,17 @@ class RestrictedCourseFormTest(ModuleStoreTestCase):
self._assert_course_field_error(form) self._assert_course_field_error(form)
def _assert_course_field_error(self, form): def _assert_course_field_error(self, form):
# Validation shouldn't work """
Validation shouldn't work.
"""
self.assertFalse(form.is_valid()) self.assertFalse(form.is_valid())
msg = 'COURSE NOT FOUND' msg = 'COURSE NOT FOUND'
self.assertIn(msg, form._errors['course_key'][0]) # pylint: disable=protected-access 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() form.save()
...@@ -111,9 +115,11 @@ class IPFilterFormTest(TestCase): ...@@ -111,9 +115,11 @@ class IPFilterFormTest(TestCase):
form = IPFilterForm(data=form_data) form = IPFilterForm(data=form_data)
self.assertFalse(form.is_valid()) 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 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 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."): with self.assertRaisesRegexp(ValueError, "The IPFilter could not be created because the data didn't validate."):
......
...@@ -17,8 +17,8 @@ from xmodule.modulestore.tests.factories import CourseFactory ...@@ -17,8 +17,8 @@ from xmodule.modulestore.tests.factories import CourseFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from config_models.models import cache as config_cache from config_models.models import cache as config_cache
from embargo.models import RestrictedCourse, IPFilter from ..models import RestrictedCourse, IPFilter
from embargo.test_utils import restrict_course from ..test_utils import restrict_course
@attr(shard=3) @attr(shard=3)
...@@ -35,7 +35,7 @@ class EmbargoMiddlewareAccessTests(UrlResetMixin, ModuleStoreTestCase): ...@@ -35,7 +35,7 @@ class EmbargoMiddlewareAccessTests(UrlResetMixin, ModuleStoreTestCase):
USERNAME = 'fred' USERNAME = 'fred'
PASSWORD = 'secret' PASSWORD = 'secret'
URLCONF_MODULES = ['embargo'] URLCONF_MODULES = ['openedx.core.djangoapps.embargo']
@patch.dict(settings.FEATURES, {'EMBARGO': True}) @patch.dict(settings.FEATURES, {'EMBARGO': True})
def setUp(self): def setUp(self):
......
...@@ -3,7 +3,7 @@ import json ...@@ -3,7 +3,7 @@ import json
from django.test import TestCase from django.test import TestCase
from django.db.utils import IntegrityError from django.db.utils import IntegrityError
from opaque_keys.edx.locator import CourseLocator from opaque_keys.edx.locator import CourseLocator
from embargo.models import ( from ..models import (
EmbargoedCourse, EmbargoedState, IPFilter, RestrictedCourse, EmbargoedCourse, EmbargoedState, IPFilter, RestrictedCourse,
Country, CountryAccessRule, CourseAccessRuleHistory Country, CountryAccessRule, CourseAccessRuleHistory
) )
......
...@@ -7,7 +7,7 @@ from django.conf import settings ...@@ -7,7 +7,7 @@ from django.conf import settings
import ddt import ddt
from util.testing import UrlResetMixin from util.testing import UrlResetMixin
from embargo import messages from .. import messages
from openedx.core.djangolib.testing.utils import CacheIsolationTestCase from openedx.core.djangolib.testing.utils import CacheIsolationTestCase
from openedx.core.djangoapps.theming.tests.test_util import with_comprehensive_theme from openedx.core.djangoapps.theming.tests.test_util import with_comprehensive_theme
...@@ -34,7 +34,7 @@ class CourseAccessMessageViewTest(CacheIsolationTestCase, UrlResetMixin): ...@@ -34,7 +34,7 @@ class CourseAccessMessageViewTest(CacheIsolationTestCase, UrlResetMixin):
ENABLED_CACHES = ['default'] ENABLED_CACHES = ['default']
URLCONF_MODULES = ['embargo'] URLCONF_MODULES = ['openedx.core.djangoapps.embargo']
@patch.dict(settings.FEATURES, {'EMBARGO': True}) @patch.dict(settings.FEATURES, {'EMBARGO': True})
def setUp(self): def setUp(self):
......
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
from django.conf.urls import patterns, url from django.conf.urls import patterns, url
from embargo.views import CourseAccessMessageView from .views import CourseAccessMessageView
urlpatterns = patterns( urlpatterns = patterns(
'embargo.views', 'openedx.core.djangoapps.embargo.views',
url( url(
r'^blocked-message/(?P<access_point>enrollment|courseware)/(?P<message_key>.+)/$', r'^blocked-message/(?P<access_point>enrollment|courseware)/(?P<message_key>.+)/$',
CourseAccessMessageView.as_view(), CourseAccessMessageView.as_view(),
......
...@@ -5,7 +5,7 @@ from django.views.generic.base import View ...@@ -5,7 +5,7 @@ from django.views.generic.base import View
from edxmako.shortcuts import render_to_response from edxmako.shortcuts import render_to_response
from embargo import messages from . import messages
class CourseAccessMessageView(View): class CourseAccessMessageView(View):
......
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