XCOM-416: Embargo restrictions are now enforced during logistration
This commit is contained in:
@@ -5,6 +5,7 @@ from uuid import uuid4
|
||||
from nose.plugins.attrib import attr
|
||||
|
||||
import ddt
|
||||
from django.conf import settings
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.test import TestCase
|
||||
from django.test.utils import override_settings
|
||||
@@ -17,6 +18,8 @@ from commerce.constants import Messages
|
||||
from commerce.tests import TEST_BASKET_ID, TEST_ORDER_NUMBER, TEST_PAYMENT_DATA, TEST_API_URL, TEST_API_SIGNING_KEY
|
||||
from commerce.tests.mocks import mock_basket_order, mock_create_basket
|
||||
from course_modes.models import CourseMode
|
||||
from embargo.test_utils import restrict_course
|
||||
from openedx.core.lib.django_test_client_utils import get_absolute_url
|
||||
from enrollment.api import get_enrollment
|
||||
from student.models import CourseEnrollment
|
||||
from student.tests.factories import UserFactory, CourseModeFactory
|
||||
@@ -42,7 +45,6 @@ class BasketsViewTests(EnrollmentEventTestMixin, UserMixin, ModuleStoreTestCase)
|
||||
"""
|
||||
Tests for the commerce orders view.
|
||||
"""
|
||||
|
||||
def _post_to_view(self, course_id=None):
|
||||
"""
|
||||
POST to the view being tested.
|
||||
@@ -96,6 +98,17 @@ class BasketsViewTests(EnrollmentEventTestMixin, UserMixin, ModuleStoreTestCase)
|
||||
# Ignore events fired from UserFactory creation
|
||||
self.reset_tracker()
|
||||
|
||||
@mock.patch.dict(settings.FEATURES, {'EMBARGO': True})
|
||||
def test_embargo_restriction(self):
|
||||
"""
|
||||
The view should return HTTP 403 status if the course is embargoed.
|
||||
"""
|
||||
with restrict_course(self.course.id) as redirect_url:
|
||||
response = self._post_to_view()
|
||||
self.assertEqual(403, response.status_code)
|
||||
body = json.loads(response.content)
|
||||
self.assertEqual(get_absolute_url(redirect_url), body['user_message_url'])
|
||||
|
||||
def test_login_required(self):
|
||||
"""
|
||||
The view should return HTTP 403 status if the user is not logged in.
|
||||
|
||||
@@ -20,6 +20,7 @@ from course_modes.models import CourseMode
|
||||
from courseware import courses
|
||||
from edxmako.shortcuts import render_to_response
|
||||
from enrollment.api import add_enrollment
|
||||
from embargo import api as embargo_api
|
||||
from microsite_configuration import microsite
|
||||
from student.models import CourseEnrollment
|
||||
from openedx.core.lib.api.authentication import SessionAuthenticationAllowInactiveUser
|
||||
@@ -76,6 +77,11 @@ class BasketsView(APIView):
|
||||
if not valid:
|
||||
return DetailResponse(error, status=HTTP_406_NOT_ACCEPTABLE)
|
||||
|
||||
embargo_response = embargo_api.get_embargo_response(request, course_key, user)
|
||||
|
||||
if embargo_response:
|
||||
return embargo_response
|
||||
|
||||
# Don't do anything if an enrollment already exists
|
||||
course_id = unicode(course_key)
|
||||
enrollment = CourseEnrollment.get_enrollment(user, course_key)
|
||||
|
||||
Reference in New Issue
Block a user