Country Access: Block enrollment from third party auth
Users who are blocked from enrolling in a course due to an embargo are redirected to the blocked message page after authentication completes.
This commit is contained in:
@@ -4,20 +4,22 @@ from collections import namedtuple
|
||||
|
||||
import datetime
|
||||
import unittest
|
||||
from mock import patch
|
||||
import ddt
|
||||
import pytz
|
||||
from util.testing import UrlResetMixin
|
||||
from third_party_auth import pipeline
|
||||
from shoppingcart.models import Order, PaidCourseRegistration # pylint: disable=import-error
|
||||
from social.apps.django_app import utils as social_utils
|
||||
from django.conf import settings
|
||||
from django.contrib.sessions.backends import cache
|
||||
from django.test import RequestFactory
|
||||
from django.test.utils import override_settings
|
||||
from xmodule.modulestore.tests.factories import CourseFactory
|
||||
from student.tests.factories import UserFactory, CourseModeFactory
|
||||
from student.models import CourseEnrollment
|
||||
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
|
||||
from openedx.core.djangoapps.user_api.models import UserOrgTag
|
||||
from embargo.test_utils import restrict_course
|
||||
|
||||
|
||||
THIRD_PARTY_AUTH_CONFIGURED = (
|
||||
@@ -27,15 +29,17 @@ THIRD_PARTY_AUTH_CONFIGURED = (
|
||||
|
||||
|
||||
@unittest.skipUnless(THIRD_PARTY_AUTH_CONFIGURED, "Third party auth must be configured")
|
||||
@patch.dict(settings.FEATURES, {'ENABLE_COUNTRY_ACCESS': True})
|
||||
@ddt.ddt
|
||||
class PipelineEnrollmentTest(ModuleStoreTestCase):
|
||||
class PipelineEnrollmentTest(UrlResetMixin, ModuleStoreTestCase):
|
||||
"""Test that the pipeline auto-enrolls students upon successful authentication. """
|
||||
|
||||
BACKEND_NAME = "google-oauth2"
|
||||
|
||||
@patch.dict(settings.FEATURES, {'ENABLE_COUNTRY_ACCESS': True})
|
||||
def setUp(self):
|
||||
"""Create a test course and user. """
|
||||
super(PipelineEnrollmentTest, self).setUp()
|
||||
super(PipelineEnrollmentTest, self).setUp('embargo')
|
||||
self.course = CourseFactory.create()
|
||||
self.user = UserFactory.create()
|
||||
|
||||
@@ -125,6 +129,30 @@ class PipelineEnrollmentTest(ModuleStoreTestCase):
|
||||
self.assertEqual(result, {})
|
||||
self.assertFalse(CourseEnrollment.is_enrolled(self.user, self.course.id))
|
||||
|
||||
@patch.dict(settings.FEATURES, {'ENABLE_COUNTRY_ACCESS': True})
|
||||
def test_blocked_by_embargo(self):
|
||||
strategy = self._fake_strategy()
|
||||
strategy.session_set('enroll_course_id', unicode(self.course.id))
|
||||
|
||||
with restrict_course(self.course.id):
|
||||
result = pipeline.change_enrollment(strategy, 1, user=self.user) # pylint: disable=assignment-from-no-return,redundant-keyword-arg
|
||||
|
||||
# Verify that we were NOT enrolled
|
||||
self.assertEqual(result, {})
|
||||
self.assertFalse(CourseEnrollment.is_enrolled(self.user, self.course.id))
|
||||
|
||||
def test_skip_enroll_from_dashboard(self):
|
||||
strategy = self._fake_strategy()
|
||||
strategy.session_set('enroll_course_id', unicode(self.course.id))
|
||||
|
||||
# Simulate completing the pipeline from the student dashboard's
|
||||
# "link account" button.
|
||||
result = pipeline.change_enrollment(strategy, 1, user=self.user, is_dashboard=True) # pylint: disable=assignment-from-no-return,redundant-keyword-arg
|
||||
|
||||
# Verify that we were NOT enrolled
|
||||
self.assertEqual(result, {})
|
||||
self.assertFalse(CourseEnrollment.is_enrolled(self.user, self.course.id))
|
||||
|
||||
def test_url_creation(self):
|
||||
strategy = self._fake_strategy()
|
||||
strategy.session_set('enroll_course_id', unicode(self.course.id))
|
||||
|
||||
Reference in New Issue
Block a user