Commit 986b63d8 by Jean Manuel Nater

Removed run_wrapped() and replaced its functionality with patch.dict():

parent e44ef1a5
...@@ -44,6 +44,10 @@ def check_for_post_code(self, code, url, data={}): ...@@ -44,6 +44,10 @@ def check_for_post_code(self, code, url, data={}):
class LoginEnrollmentTestCase(TestCase): class LoginEnrollmentTestCase(TestCase):
"""
Provides support for user creation,
activation, login, and course enrollment.
"""
def setup_user(self): def setup_user(self):
""" """
......
...@@ -21,7 +21,6 @@ class TestNavigation(ModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -21,7 +21,6 @@ class TestNavigation(ModuleStoreTestCase, LoginEnrollmentTestCase):
""" """
def setUp(self): def setUp(self):
xmodule.modulestore.django._MODULESTORES = {}
self.course = CourseFactory.create() self.course = CourseFactory.create()
self.full = CourseFactory.create(display_name='Robot_Sub_Course') self.full = CourseFactory.create(display_name='Robot_Sub_Course')
......
...@@ -10,7 +10,7 @@ from django.test.utils import override_settings ...@@ -10,7 +10,7 @@ from django.test.utils import override_settings
# Need access to internal func to put users in the right group # Need access to internal func to put users in the right group
from courseware.access import (has_access, _course_staff_group_name, from courseware.access import (has_access, _course_staff_group_name,
course_beta_test_group_name) course_beta_test_group_name, settings as access_settings)
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
...@@ -20,6 +20,7 @@ from helpers import LoginEnrollmentTestCase, check_for_get_code ...@@ -20,6 +20,7 @@ from helpers import LoginEnrollmentTestCase, check_for_get_code
from modulestore_config import TEST_DATA_MONGO_MODULESTORE from modulestore_config import TEST_DATA_MONGO_MODULESTORE
#@patch.dict(access_settings.MITX_FEATURES, {'DISABLE_START_DATES': True})
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE)
class TestViewAuth(ModuleStoreTestCase, LoginEnrollmentTestCase): class TestViewAuth(ModuleStoreTestCase, LoginEnrollmentTestCase):
""" """
...@@ -81,20 +82,13 @@ class TestViewAuth(ModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -81,20 +82,13 @@ class TestViewAuth(ModuleStoreTestCase, LoginEnrollmentTestCase):
""" """
List of urls that students should be able to see before List of urls that students should be able to see before
launch. launch.
`course` is an instance of CourseDescriptor.
""" """
urls = self._reverse_urls(['about_course'], course) urls = self._reverse_urls(['about_course'], course)
urls.append(reverse('courses')) urls.append(reverse('courses'))
return urls return urls
def instructor_urls(self, course):
"""
List of urls that only instructors/staff should be able to see.
"""
urls = self._reverse_urls(['instructor_dashboard',
'gradebook', 'grade_summary'], course)
return urls
def _check_non_staff_light(self, course): def _check_non_staff_light(self, course):
""" """
Check that non-staff have access to light urls. Check that non-staff have access to light urls.
...@@ -295,25 +289,12 @@ class TestViewAuth(ModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -295,25 +289,12 @@ class TestViewAuth(ModuleStoreTestCase, LoginEnrollmentTestCase):
Make sure that before course start, students can't access course Make sure that before course start, students can't access course
pages, but instructors can. pages, but instructors can.
""" """
self.run_wrapped(self._do_test_dark_launch_enrolled_student)
self.run_wrapped(self._do_test_dark_launch_instructor)
self.run_wrapped(self._do_test_dark_launch_staff)
def test_enrollment_period(self):
"""
Check that enrollment periods work.
"""
self.run_wrapped(self._do_test_enrollment_period)
# def test_beta_period(self): @patch.dict(access_settings.MITX_FEATURES, {'DISABLE_START_DATES': False})
# """ def test_dark_launch_enrolled_student(self):
# Check that beta-test access works.
# """
# self.run_wrapped(self._do_test_beta_period)
def _do_test_dark_launch_enrolled_student(self):
""" """
Actually do the test, relying on settings to be right. Make sure that before course start, students can't access course
pages.
""" """
student_email, student_password = self.ACCOUNT_INFO[0] student_email, student_password = self.ACCOUNT_INFO[0]
...@@ -328,7 +309,6 @@ class TestViewAuth(ModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -328,7 +309,6 @@ class TestViewAuth(ModuleStoreTestCase, LoginEnrollmentTestCase):
self.assertFalse(self.course.has_started()) self.assertFalse(self.course.has_started())
self.assertFalse(self.full.has_started()) self.assertFalse(self.full.has_started())
self.assertFalse(settings.MITX_FEATURES['DISABLE_START_DATES'])
# First, try with an enrolled student # First, try with an enrolled student
print '=== Testing student access....' print '=== Testing student access....'
...@@ -342,7 +322,12 @@ class TestViewAuth(ModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -342,7 +322,12 @@ class TestViewAuth(ModuleStoreTestCase, LoginEnrollmentTestCase):
self._check_non_staff_light(self.full) self._check_non_staff_light(self.full)
self._check_non_staff_dark(self.full) self._check_non_staff_dark(self.full)
def _do_test_dark_launch_instructor(self): @patch.dict(access_settings.MITX_FEATURES, {'DISABLE_START_DATES': False})
def test_dark_launch_instructor(self):
"""
Make sure that before course start instructors can access the
page for their course.
"""
instructor_email, instructor_password = self.ACCOUNT_INFO[1] instructor_email, instructor_password = self.ACCOUNT_INFO[1]
...@@ -369,7 +354,12 @@ class TestViewAuth(ModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -369,7 +354,12 @@ class TestViewAuth(ModuleStoreTestCase, LoginEnrollmentTestCase):
self._check_non_staff_dark(self.full) self._check_non_staff_dark(self.full)
self._check_staff(self.course) self._check_staff(self.course)
def _do_test_dark_launch_staff(self): @patch.dict(access_settings.MITX_FEATURES, {'DISABLE_START_DATES': False})
def test_dark_launch_staff(self):
"""
Make sure that before course start staff can access
course pages.
"""
instructor_email, instructor_password = self.ACCOUNT_INFO[1] instructor_email, instructor_password = self.ACCOUNT_INFO[1]
...@@ -394,9 +384,10 @@ class TestViewAuth(ModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -394,9 +384,10 @@ class TestViewAuth(ModuleStoreTestCase, LoginEnrollmentTestCase):
self._check_staff(self.course) self._check_staff(self.course)
self._check_staff(self.full) self._check_staff(self.full)
def _do_test_enrollment_period(self): @patch.dict(access_settings.MITX_FEATURES, {'DISABLE_START_DATES': False})
def test_enrollment_period(self):
""" """
Actually do the test, relying on settings to be right. Check that enrollment periods work.
""" """
student_email, student_password = self.ACCOUNT_INFO[0] student_email, student_password = self.ACCOUNT_INFO[0]
...@@ -447,20 +438,15 @@ class TestViewAuth(ModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -447,20 +438,15 @@ class TestViewAuth(ModuleStoreTestCase, LoginEnrollmentTestCase):
self.unenroll(self.course) self.unenroll(self.course)
self.assertTrue(self.enroll(self.course)) self.assertTrue(self.enroll(self.course))
#from courseware.access import MITX_FEATURES @patch.dict(access_settings.MITX_FEATURES, {'DISABLE_START_DATES': False})
def test_beta_period(self):
#@patch.dict(MITX_FEATURES, {'DISABLE_START_DATES': True})
def _do_test_beta_period(self):
""" """
Actually test beta periods, relying on settings to be right. Check that beta-test access works.
""" """
student_email, student_password = self.ACCOUNT_INFO[0] student_email, student_password = self.ACCOUNT_INFO[0]
instructor_email, instructor_password = self.ACCOUNT_INFO[1] instructor_email, instructor_password = self.ACCOUNT_INFO[1]
# trust, but verify :)
self.assertFalse(settings.MITX_FEATURES['DISABLE_START_DATES'])
# Make courses start in the future # Make courses start in the future
now = datetime.datetime.now(pytz.UTC) now = datetime.datetime.now(pytz.UTC)
tomorrow = now + datetime.timedelta(days=1) tomorrow = now + datetime.timedelta(days=1)
......
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