Commit c680dfdd by Will Daly

Merge pull request #768 from edx/will/use-mixed-modulestore-in-tests

Will/use mixed modulestore in tests
parents 9899b1a4 1cb52df1
...@@ -60,11 +60,11 @@ class UploadTestCase(CourseTestCase): ...@@ -60,11 +60,11 @@ class UploadTestCase(CourseTestCase):
f = BytesIO("sample content") f = BytesIO("sample content")
f.name = "sample.txt" f.name = "sample.txt"
resp = self.client.post(self.url, {"name": "my-name", "file": f}) resp = self.client.post(self.url, {"name": "my-name", "file": f})
self.assert2XX(resp.status_code) self.assertEquals(resp.status_code, 200)
def test_no_file(self): def test_no_file(self):
resp = self.client.post(self.url, {"name": "file.txt"}) resp = self.client.post(self.url, {"name": "file.txt"})
self.assert4XX(resp.status_code) self.assertEquals(resp.status_code, 400)
def test_get(self): def test_get(self):
resp = self.client.get(self.url) resp = self.client.get(self.url)
......
...@@ -1408,7 +1408,7 @@ class ContentStoreTest(ModuleStoreTestCase): ...@@ -1408,7 +1408,7 @@ class ContentStoreTest(ModuleStoreTestCase):
'course': loc.course, 'course': loc.course,
'name': loc.name})) 'name': loc.name}))
self.assert2XX(resp.status_code) self.assertEqual(resp.status_code, 200)
self.assertContains(resp, 'Chapter 2') self.assertContains(resp, 'Chapter 2')
# go to various pages # go to various pages
...@@ -1418,92 +1418,92 @@ class ContentStoreTest(ModuleStoreTestCase): ...@@ -1418,92 +1418,92 @@ class ContentStoreTest(ModuleStoreTestCase):
kwargs={'org': loc.org, kwargs={'org': loc.org,
'course': loc.course, 'course': loc.course,
'name': loc.name})) 'name': loc.name}))
self.assert2XX(resp.status_code) self.assertEqual(resp.status_code, 200)
# export page # export page
resp = self.client.get(reverse('export_course', resp = self.client.get(reverse('export_course',
kwargs={'org': loc.org, kwargs={'org': loc.org,
'course': loc.course, 'course': loc.course,
'name': loc.name})) 'name': loc.name}))
self.assert2XX(resp.status_code) self.assertEqual(resp.status_code, 200)
# manage users # manage users
resp = self.client.get(reverse('manage_users', resp = self.client.get(reverse('manage_users',
kwargs={'org': loc.org, kwargs={'org': loc.org,
'course': loc.course, 'course': loc.course,
'name': loc.name})) 'name': loc.name}))
self.assert2XX(resp.status_code) self.assertEqual(resp.status_code, 200)
# course info # course info
resp = self.client.get(reverse('course_info', resp = self.client.get(reverse('course_info',
kwargs={'org': loc.org, kwargs={'org': loc.org,
'course': loc.course, 'course': loc.course,
'name': loc.name})) 'name': loc.name}))
self.assert2XX(resp.status_code) self.assertEqual(resp.status_code, 200)
# settings_details # settings_details
resp = self.client.get(reverse('settings_details', resp = self.client.get(reverse('settings_details',
kwargs={'org': loc.org, kwargs={'org': loc.org,
'course': loc.course, 'course': loc.course,
'name': loc.name})) 'name': loc.name}))
self.assert2XX(resp.status_code) self.assertEqual(resp.status_code, 200)
# settings_details # settings_details
resp = self.client.get(reverse('settings_grading', resp = self.client.get(reverse('settings_grading',
kwargs={'org': loc.org, kwargs={'org': loc.org,
'course': loc.course, 'course': loc.course,
'name': loc.name})) 'name': loc.name}))
self.assert2XX(resp.status_code) self.assertEqual(resp.status_code, 200)
# static_pages # static_pages
resp = self.client.get(reverse('static_pages', resp = self.client.get(reverse('static_pages',
kwargs={'org': loc.org, kwargs={'org': loc.org,
'course': loc.course, 'course': loc.course,
'coursename': loc.name})) 'coursename': loc.name}))
self.assert2XX(resp.status_code) self.assertEqual(resp.status_code, 200)
# static_pages # static_pages
resp = self.client.get(reverse('asset_index', resp = self.client.get(reverse('asset_index',
kwargs={'org': loc.org, kwargs={'org': loc.org,
'course': loc.course, 'course': loc.course,
'name': loc.name})) 'name': loc.name}))
self.assert2XX(resp.status_code) self.assertEqual(resp.status_code, 200)
# go look at a subsection page # go look at a subsection page
subsection_location = loc.replace(category='sequential', name='test_sequence') subsection_location = loc.replace(category='sequential', name='test_sequence')
resp = self.client.get(reverse('edit_subsection', resp = self.client.get(reverse('edit_subsection',
kwargs={'location': subsection_location.url()})) kwargs={'location': subsection_location.url()}))
self.assert2XX(resp.status_code) self.assertEqual(resp.status_code, 200)
# go look at the Edit page # go look at the Edit page
unit_location = loc.replace(category='vertical', name='test_vertical') unit_location = loc.replace(category='vertical', name='test_vertical')
resp = self.client.get(reverse('edit_unit', resp = self.client.get(reverse('edit_unit',
kwargs={'location': unit_location.url()})) kwargs={'location': unit_location.url()}))
self.assert2XX(resp.status_code) self.assertEqual(resp.status_code, 200)
# delete a component # delete a component
del_loc = loc.replace(category='html', name='test_html') del_loc = loc.replace(category='html', name='test_html')
resp = self.client.post(reverse('delete_item'), resp = self.client.post(reverse('delete_item'),
json.dumps({'id': del_loc.url()}), "application/json") json.dumps({'id': del_loc.url()}), "application/json")
self.assert2XX(resp.status_code) self.assertEqual(resp.status_code, 204)
# delete a unit # delete a unit
del_loc = loc.replace(category='vertical', name='test_vertical') del_loc = loc.replace(category='vertical', name='test_vertical')
resp = self.client.post(reverse('delete_item'), resp = self.client.post(reverse('delete_item'),
json.dumps({'id': del_loc.url()}), "application/json") json.dumps({'id': del_loc.url()}), "application/json")
self.assert2XX(resp.status_code) self.assertEqual(resp.status_code, 204)
# delete a unit # delete a unit
del_loc = loc.replace(category='sequential', name='test_sequence') del_loc = loc.replace(category='sequential', name='test_sequence')
resp = self.client.post(reverse('delete_item'), resp = self.client.post(reverse('delete_item'),
json.dumps({'id': del_loc.url()}), "application/json") json.dumps({'id': del_loc.url()}), "application/json")
self.assert2XX(resp.status_code) self.assertEqual(resp.status_code, 204)
# delete a chapter # delete a chapter
del_loc = loc.replace(category='chapter', name='chapter_2') del_loc = loc.replace(category='chapter', name='chapter_2')
resp = self.client.post(reverse('delete_item'), resp = self.client.post(reverse('delete_item'),
json.dumps({'id': del_loc.url()}), "application/json") json.dumps({'id': del_loc.url()}), "application/json")
self.assert2XX(resp.status_code) self.assertEqual(resp.status_code, 204)
def test_import_into_new_course_id(self): def test_import_into_new_course_id(self):
module_store = modulestore('direct') module_store = modulestore('direct')
......
...@@ -439,12 +439,12 @@ class CourseGraderUpdatesTest(CourseTestCase): ...@@ -439,12 +439,12 @@ class CourseGraderUpdatesTest(CourseTestCase):
def test_get(self): def test_get(self):
resp = self.client.get(self.url) resp = self.client.get(self.url)
self.assert2XX(resp.status_code) self.assertEqual(resp.status_code, 200)
obj = json.loads(resp.content) obj = json.loads(resp.content)
def test_delete(self): def test_delete(self):
resp = self.client.delete(self.url) resp = self.client.delete(self.url)
self.assert2XX(resp.status_code) self.assertEqual(resp.status_code, 204)
def test_post(self): def test_post(self):
grader = { grader = {
...@@ -455,5 +455,5 @@ class CourseGraderUpdatesTest(CourseTestCase): ...@@ -455,5 +455,5 @@ class CourseGraderUpdatesTest(CourseTestCase):
"weight": 17.3, "weight": 17.3,
} }
resp = self.client.post(self.url, grader) resp = self.client.post(self.url, grader)
self.assert2XX(resp.status_code) self.assertEqual(resp.status_code, 200)
obj = json.loads(resp.content) obj = json.loads(resp.content)
...@@ -34,7 +34,7 @@ class DeleteItem(CourseTestCase): ...@@ -34,7 +34,7 @@ class DeleteItem(CourseTestCase):
resp.content, resp.content,
"application/json" "application/json"
) )
self.assert2XX(resp.status_code) self.assertEqual(resp.status_code, 204)
class TestCreateItem(CourseTestCase): class TestCreateItem(CourseTestCase):
......
...@@ -23,7 +23,7 @@ class TextbookIndexTestCase(CourseTestCase): ...@@ -23,7 +23,7 @@ class TextbookIndexTestCase(CourseTestCase):
def test_view_index(self): def test_view_index(self):
"Basic check that the textbook index page responds correctly" "Basic check that the textbook index page responds correctly"
resp = self.client.get(self.url) resp = self.client.get(self.url)
self.assert2XX(resp.status_code) self.assertEqual(resp.status_code, 200)
# we don't have resp.context right now, # we don't have resp.context right now,
# due to bugs in our testing harness :( # due to bugs in our testing harness :(
if resp.context: if resp.context:
...@@ -36,7 +36,7 @@ class TextbookIndexTestCase(CourseTestCase): ...@@ -36,7 +36,7 @@ class TextbookIndexTestCase(CourseTestCase):
HTTP_ACCEPT="application/json", HTTP_ACCEPT="application/json",
HTTP_X_REQUESTED_WITH='XMLHttpRequest' HTTP_X_REQUESTED_WITH='XMLHttpRequest'
) )
self.assert2XX(resp.status_code) self.assertEqual(resp.status_code, 200)
obj = json.loads(resp.content) obj = json.loads(resp.content)
self.assertEqual(self.course.pdf_textbooks, obj) self.assertEqual(self.course.pdf_textbooks, obj)
...@@ -73,7 +73,7 @@ class TextbookIndexTestCase(CourseTestCase): ...@@ -73,7 +73,7 @@ class TextbookIndexTestCase(CourseTestCase):
HTTP_ACCEPT="application/json", HTTP_ACCEPT="application/json",
HTTP_X_REQUESTED_WITH='XMLHttpRequest' HTTP_X_REQUESTED_WITH='XMLHttpRequest'
) )
self.assert2XX(resp.status_code) self.assertEqual(resp.status_code, 200)
obj = json.loads(resp.content) obj = json.loads(resp.content)
self.assertEqual(content, obj) self.assertEqual(content, obj)
...@@ -90,7 +90,7 @@ class TextbookIndexTestCase(CourseTestCase): ...@@ -90,7 +90,7 @@ class TextbookIndexTestCase(CourseTestCase):
HTTP_ACCEPT="application/json", HTTP_ACCEPT="application/json",
HTTP_X_REQUESTED_WITH='XMLHttpRequest' HTTP_X_REQUESTED_WITH='XMLHttpRequest'
) )
self.assert2XX(resp.status_code) self.assertEqual(resp.status_code, 200)
# reload course # reload course
store = get_modulestore(self.course.location) store = get_modulestore(self.course.location)
...@@ -111,7 +111,7 @@ class TextbookIndexTestCase(CourseTestCase): ...@@ -111,7 +111,7 @@ class TextbookIndexTestCase(CourseTestCase):
HTTP_ACCEPT="application/json", HTTP_ACCEPT="application/json",
HTTP_X_REQUESTED_WITH='XMLHttpRequest' HTTP_X_REQUESTED_WITH='XMLHttpRequest'
) )
self.assert4XX(resp.status_code) self.assertEqual(resp.status_code, 400)
obj = json.loads(resp.content) obj = json.loads(resp.content)
self.assertIn("error", obj) self.assertIn("error", obj)
...@@ -184,7 +184,7 @@ class TextbookCreateTestCase(CourseTestCase): ...@@ -184,7 +184,7 @@ class TextbookCreateTestCase(CourseTestCase):
HTTP_ACCEPT="application/json", HTTP_ACCEPT="application/json",
HTTP_X_REQUESTED_WITH="XMLHttpRequest", HTTP_X_REQUESTED_WITH="XMLHttpRequest",
) )
self.assert4XX(resp.status_code) self.assertEqual(resp.status_code, 400)
self.assertNotIn("Location", resp) self.assertNotIn("Location", resp)
...@@ -238,14 +238,14 @@ class TextbookByIdTestCase(CourseTestCase): ...@@ -238,14 +238,14 @@ class TextbookByIdTestCase(CourseTestCase):
def test_get_1(self): def test_get_1(self):
"Get the first textbook" "Get the first textbook"
resp = self.client.get(self.url1) resp = self.client.get(self.url1)
self.assert2XX(resp.status_code) self.assertEqual(resp.status_code, 200)
compare = json.loads(resp.content) compare = json.loads(resp.content)
self.assertEqual(compare, self.textbook1) self.assertEqual(compare, self.textbook1)
def test_get_2(self): def test_get_2(self):
"Get the second textbook" "Get the second textbook"
resp = self.client.get(self.url2) resp = self.client.get(self.url2)
self.assert2XX(resp.status_code) self.assertEqual(resp.status_code, 200)
compare = json.loads(resp.content) compare = json.loads(resp.content)
self.assertEqual(compare, self.textbook2) self.assertEqual(compare, self.textbook2)
...@@ -257,7 +257,7 @@ class TextbookByIdTestCase(CourseTestCase): ...@@ -257,7 +257,7 @@ class TextbookByIdTestCase(CourseTestCase):
def test_delete(self): def test_delete(self):
"Delete a textbook by ID" "Delete a textbook by ID"
resp = self.client.delete(self.url1) resp = self.client.delete(self.url1)
self.assert2XX(resp.status_code) self.assertEqual(resp.status_code, 204)
course = self.store.get_item(self.course.location) course = self.store.get_item(self.course.location)
self.assertEqual(course.pdf_textbooks, [self.textbook2]) self.assertEqual(course.pdf_textbooks, [self.textbook2])
...@@ -288,7 +288,7 @@ class TextbookByIdTestCase(CourseTestCase): ...@@ -288,7 +288,7 @@ class TextbookByIdTestCase(CourseTestCase):
) )
self.assertEqual(resp.status_code, 201) self.assertEqual(resp.status_code, 201)
resp2 = self.client.get(url) resp2 = self.client.get(url)
self.assert2XX(resp2.status_code) self.assertEqual(resp2.status_code, 200)
compare = json.loads(resp2.content) compare = json.loads(resp2.content)
self.assertEqual(compare, textbook) self.assertEqual(compare, textbook)
course = self.store.get_item(self.course.location) course = self.store.get_item(self.course.location)
...@@ -311,7 +311,7 @@ class TextbookByIdTestCase(CourseTestCase): ...@@ -311,7 +311,7 @@ class TextbookByIdTestCase(CourseTestCase):
) )
self.assertEqual(resp.status_code, 201) self.assertEqual(resp.status_code, 201)
resp2 = self.client.get(self.url2) resp2 = self.client.get(self.url2)
self.assert2XX(resp2.status_code) self.assertEqual(resp2.status_code, 200)
compare = json.loads(resp2.content) compare = json.loads(resp2.content)
self.assertEqual(compare, replacement) self.assertEqual(compare, replacement)
course = self.store.get_item(self.course.location) course = self.store.get_item(self.course.location)
......
...@@ -72,13 +72,13 @@ class UsersTestCase(CourseTestCase): ...@@ -72,13 +72,13 @@ class UsersTestCase(CourseTestCase):
def test_detail_inactive(self): def test_detail_inactive(self):
resp = self.client.get(self.inactive_detail_url) resp = self.client.get(self.inactive_detail_url)
self.assert2XX(resp.status_code) self.assertEqual(resp.status_code, 200)
result = json.loads(resp.content) result = json.loads(resp.content)
self.assertFalse(result["active"]) self.assertFalse(result["active"])
def test_detail_invalid(self): def test_detail_invalid(self):
resp = self.client.get(self.invalid_detail_url) resp = self.client.get(self.invalid_detail_url)
self.assert4XX(resp.status_code) self.assertEqual(resp.status_code, 404)
result = json.loads(resp.content) result = json.loads(resp.content)
self.assertIn("error", result) self.assertIn("error", result)
...@@ -87,7 +87,7 @@ class UsersTestCase(CourseTestCase): ...@@ -87,7 +87,7 @@ class UsersTestCase(CourseTestCase):
self.detail_url, self.detail_url,
data={"role": None}, data={"role": None},
) )
self.assert2XX(resp.status_code) self.assertEqual(resp.status_code, 204)
# reload user from DB # reload user from DB
ext_user = User.objects.get(email=self.ext_user.email) ext_user = User.objects.get(email=self.ext_user.email)
groups = [g.name for g in ext_user.groups.all()] groups = [g.name for g in ext_user.groups.all()]
...@@ -103,7 +103,7 @@ class UsersTestCase(CourseTestCase): ...@@ -103,7 +103,7 @@ class UsersTestCase(CourseTestCase):
content_type="application/json", content_type="application/json",
HTTP_ACCEPT="application/json", HTTP_ACCEPT="application/json",
) )
self.assert2XX(resp.status_code) self.assertEqual(resp.status_code, 204)
# reload user from DB # reload user from DB
ext_user = User.objects.get(email=self.ext_user.email) ext_user = User.objects.get(email=self.ext_user.email)
groups = [g.name for g in ext_user.groups.all()] groups = [g.name for g in ext_user.groups.all()]
...@@ -122,7 +122,7 @@ class UsersTestCase(CourseTestCase): ...@@ -122,7 +122,7 @@ class UsersTestCase(CourseTestCase):
content_type="application/json", content_type="application/json",
HTTP_ACCEPT="application/json", HTTP_ACCEPT="application/json",
) )
self.assert2XX(resp.status_code) self.assertEqual(resp.status_code, 204)
# reload user from DB # reload user from DB
ext_user = User.objects.get(email=self.ext_user.email) ext_user = User.objects.get(email=self.ext_user.email)
groups = [g.name for g in ext_user.groups.all()] groups = [g.name for g in ext_user.groups.all()]
...@@ -142,7 +142,7 @@ class UsersTestCase(CourseTestCase): ...@@ -142,7 +142,7 @@ class UsersTestCase(CourseTestCase):
content_type="application/json", content_type="application/json",
HTTP_ACCEPT="application/json", HTTP_ACCEPT="application/json",
) )
self.assert2XX(resp.status_code) self.assertEqual(resp.status_code, 204)
# reload user from DB # reload user from DB
ext_user = User.objects.get(email=self.ext_user.email) ext_user = User.objects.get(email=self.ext_user.email)
groups = [g.name for g in ext_user.groups.all()] groups = [g.name for g in ext_user.groups.all()]
...@@ -157,7 +157,7 @@ class UsersTestCase(CourseTestCase): ...@@ -157,7 +157,7 @@ class UsersTestCase(CourseTestCase):
content_type="application/json", content_type="application/json",
HTTP_ACCEPT="application/json", HTTP_ACCEPT="application/json",
) )
self.assert4XX(resp.status_code) self.assertEqual(resp.status_code, 400)
result = json.loads(resp.content) result = json.loads(resp.content)
self.assertIn("error", result) self.assertIn("error", result)
self.assert_not_enrolled() self.assert_not_enrolled()
...@@ -169,7 +169,7 @@ class UsersTestCase(CourseTestCase): ...@@ -169,7 +169,7 @@ class UsersTestCase(CourseTestCase):
content_type="application/json", content_type="application/json",
HTTP_ACCEPT="application/json", HTTP_ACCEPT="application/json",
) )
self.assert4XX(resp.status_code) self.assertEqual(resp.status_code, 400)
result = json.loads(resp.content) result = json.loads(resp.content)
self.assertIn("error", result) self.assertIn("error", result)
self.assert_not_enrolled() self.assert_not_enrolled()
...@@ -180,7 +180,7 @@ class UsersTestCase(CourseTestCase): ...@@ -180,7 +180,7 @@ class UsersTestCase(CourseTestCase):
data={"role": "staff"}, data={"role": "staff"},
HTTP_ACCEPT="application/json", HTTP_ACCEPT="application/json",
) )
self.assert2XX(resp.status_code) self.assertEqual(resp.status_code, 204)
# reload user from DB # reload user from DB
ext_user = User.objects.get(email=self.ext_user.email) ext_user = User.objects.get(email=self.ext_user.email)
groups = [g.name for g in ext_user.groups.all()] groups = [g.name for g in ext_user.groups.all()]
...@@ -197,7 +197,7 @@ class UsersTestCase(CourseTestCase): ...@@ -197,7 +197,7 @@ class UsersTestCase(CourseTestCase):
self.detail_url, self.detail_url,
HTTP_ACCEPT="application/json", HTTP_ACCEPT="application/json",
) )
self.assert2XX(resp.status_code) self.assertEqual(resp.status_code, 204)
# reload user from DB # reload user from DB
ext_user = User.objects.get(email=self.ext_user.email) ext_user = User.objects.get(email=self.ext_user.email)
groups = [g.name for g in ext_user.groups.all()] groups = [g.name for g in ext_user.groups.all()]
...@@ -214,7 +214,7 @@ class UsersTestCase(CourseTestCase): ...@@ -214,7 +214,7 @@ class UsersTestCase(CourseTestCase):
self.detail_url, self.detail_url,
HTTP_ACCEPT="application/json", HTTP_ACCEPT="application/json",
) )
self.assert2XX(resp.status_code) self.assertEqual(resp.status_code, 204)
# reload user from DB # reload user from DB
ext_user = User.objects.get(email=self.ext_user.email) ext_user = User.objects.get(email=self.ext_user.email)
groups = [g.name for g in ext_user.groups.all()] groups = [g.name for g in ext_user.groups.all()]
...@@ -273,7 +273,7 @@ class UsersTestCase(CourseTestCase): ...@@ -273,7 +273,7 @@ class UsersTestCase(CourseTestCase):
data={"role": "instructor"}, data={"role": "instructor"},
HTTP_ACCEPT="application/json", HTTP_ACCEPT="application/json",
) )
self.assert4XX(resp.status_code) self.assertEqual(resp.status_code, 400)
result = json.loads(resp.content) result = json.loads(resp.content)
self.assertIn("error", result) self.assertIn("error", result)
...@@ -288,7 +288,7 @@ class UsersTestCase(CourseTestCase): ...@@ -288,7 +288,7 @@ class UsersTestCase(CourseTestCase):
data={"role": "instructor"}, data={"role": "instructor"},
HTTP_ACCEPT="application/json", HTTP_ACCEPT="application/json",
) )
self.assert4XX(resp.status_code) self.assertEqual(resp.status_code, 400)
result = json.loads(resp.content) result = json.loads(resp.content)
self.assertIn("error", result) self.assertIn("error", result)
...@@ -306,7 +306,7 @@ class UsersTestCase(CourseTestCase): ...@@ -306,7 +306,7 @@ class UsersTestCase(CourseTestCase):
}) })
resp = self.client.delete(self_url) resp = self.client.delete(self_url)
self.assert2XX(resp.status_code) self.assertEqual(resp.status_code, 204)
# reload user from DB # reload user from DB
user = User.objects.get(email=self.user.email) user = User.objects.get(email=self.user.email)
groups = [g.name for g in user.groups.all()] groups = [g.name for g in user.groups.all()]
...@@ -321,7 +321,7 @@ class UsersTestCase(CourseTestCase): ...@@ -321,7 +321,7 @@ class UsersTestCase(CourseTestCase):
self.ext_user.save() self.ext_user.save()
resp = self.client.delete(self.detail_url) resp = self.client.delete(self.detail_url)
self.assert4XX(resp.status_code) self.assertEqual(resp.status_code, 400)
result = json.loads(resp.content) result = json.loads(resp.content)
self.assertIn("error", result) self.assertIn("error", result)
# reload user from DB # reload user from DB
...@@ -347,7 +347,7 @@ class UsersTestCase(CourseTestCase): ...@@ -347,7 +347,7 @@ class UsersTestCase(CourseTestCase):
self.detail_url, self.detail_url,
HTTP_ACCEPT="application/json", HTTP_ACCEPT="application/json",
) )
self.assert2XX(resp.status_code) self.assertEqual(resp.status_code, 204)
self.assert_enrolled() self.assert_enrolled()
def test_staff_to_instructor_still_enrolled(self): def test_staff_to_instructor_still_enrolled(self):
...@@ -366,7 +366,7 @@ class UsersTestCase(CourseTestCase): ...@@ -366,7 +366,7 @@ class UsersTestCase(CourseTestCase):
content_type="application/json", content_type="application/json",
HTTP_ACCEPT="application/json", HTTP_ACCEPT="application/json",
) )
self.assert2XX(resp.status_code) self.assertEqual(resp.status_code, 204)
self.assert_enrolled() self.assert_enrolled()
def assert_not_enrolled(self): def assert_not_enrolled(self):
......
...@@ -8,19 +8,20 @@ from course_groups.models import CourseUserGroup ...@@ -8,19 +8,20 @@ from course_groups.models import CourseUserGroup
from course_groups.cohorts import (get_cohort, get_course_cohorts, from course_groups.cohorts import (get_cohort, get_course_cohorts,
is_commentable_cohorted, get_cohort_by_name) is_commentable_cohorted, get_cohort_by_name)
from xmodule.modulestore.django import modulestore, _MODULESTORES from xmodule.modulestore.django import modulestore, clear_existing_modulestores
from xmodule.modulestore.tests.django_utils import xml_store_config from xmodule.modulestore.tests.django_utils import mixed_store_config
# NOTE: running this with the lms.envs.test config works without # NOTE: running this with the lms.envs.test config works without
# manually overriding the modulestore. However, running with # manually overriding the modulestore. However, running with
# cms.envs.test doesn't. # cms.envs.test doesn't.
TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT
TEST_DATA_XML_MODULESTORE = xml_store_config(TEST_DATA_DIR) TEST_MAPPING = {'edX/toy/2012_Fall': 'xml'}
TEST_DATA_MIXED_MODULESTORE = mixed_store_config(TEST_DATA_DIR, TEST_MAPPING)
@override_settings(MODULESTORE=TEST_DATA_XML_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
class TestCohorts(django.test.TestCase): class TestCohorts(django.test.TestCase):
@staticmethod @staticmethod
...@@ -82,9 +83,7 @@ class TestCohorts(django.test.TestCase): ...@@ -82,9 +83,7 @@ class TestCohorts(django.test.TestCase):
""" """
Make sure that course is reloaded every time--clear out the modulestore. Make sure that course is reloaded every time--clear out the modulestore.
""" """
# don't like this, but don't know a better way to undo all changes made clear_existing_modulestores()
# to course. We don't have a course.clone() method.
_MODULESTORES.clear()
def test_get_cohort(self): def test_get_cohort(self):
""" """
......
...@@ -14,11 +14,9 @@ from django.contrib.auth.models import AnonymousUser, User ...@@ -14,11 +14,9 @@ from django.contrib.auth.models import AnonymousUser, User
from django.utils.importlib import import_module from django.utils.importlib import import_module
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, mixed_store_config
from xmodule.modulestore.inheritance import own_metadata from xmodule.modulestore.inheritance import own_metadata
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import editable_modulestore
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE
from external_auth.models import ExternalAuthMap from external_auth.models import ExternalAuthMap
from external_auth.views import shib_login, course_specific_login, course_specific_register from external_auth.views import shib_login, course_specific_login, course_specific_register
...@@ -27,6 +25,8 @@ from student.views import create_account, change_enrollment ...@@ -27,6 +25,8 @@ from student.views import create_account, change_enrollment
from student.models import UserProfile, Registration, CourseEnrollment from student.models import UserProfile, Registration, CourseEnrollment
from student.tests.factories import UserFactory from student.tests.factories import UserFactory
TEST_DATA_MIXED_MODULESTORE = mixed_store_config(settings.COMMON_TEST_DATA_ROOT, {})
# Shib is supposed to provide 'REMOTE_USER', 'givenName', 'sn', 'mail', 'Shib-Identity-Provider' # Shib is supposed to provide 'REMOTE_USER', 'givenName', 'sn', 'mail', 'Shib-Identity-Provider'
# attributes via request.META. We can count on 'Shib-Identity-Provider', and 'REMOTE_USER' being present # attributes via request.META. We can count on 'Shib-Identity-Provider', and 'REMOTE_USER' being present
# b/c of how mod_shib works but should test the behavior with the rest of the attributes present/missing # b/c of how mod_shib works but should test the behavior with the rest of the attributes present/missing
...@@ -64,7 +64,7 @@ def gen_all_identities(): ...@@ -64,7 +64,7 @@ def gen_all_identities():
yield _build_identity_dict(mail, given_name, surname) yield _build_identity_dict(mail, given_name, surname)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE, SESSION_ENGINE='django.contrib.sessions.backends.cache') @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE, SESSION_ENGINE='django.contrib.sessions.backends.cache')
class ShibSPTest(ModuleStoreTestCase): class ShibSPTest(ModuleStoreTestCase):
""" """
Tests for the Shibboleth SP, which communicates via request.META Tests for the Shibboleth SP, which communicates via request.META
...@@ -73,7 +73,7 @@ class ShibSPTest(ModuleStoreTestCase): ...@@ -73,7 +73,7 @@ class ShibSPTest(ModuleStoreTestCase):
request_factory = RequestFactory() request_factory = RequestFactory()
def setUp(self): def setUp(self):
self.store = modulestore() self.store = editable_modulestore()
@unittest.skipUnless(settings.MITX_FEATURES.get('AUTH_USE_SHIB'), True) @unittest.skipUnless(settings.MITX_FEATURES.get('AUTH_USE_SHIB'), True)
def test_exception_shib_login(self): def test_exception_shib_login(self):
......
...@@ -161,9 +161,10 @@ def reset_databases(scenario): ...@@ -161,9 +161,10 @@ def reset_databases(scenario):
mongo = MongoClient() mongo = MongoClient()
mongo.drop_database(settings.CONTENTSTORE['OPTIONS']['db']) mongo.drop_database(settings.CONTENTSTORE['OPTIONS']['db'])
_CONTENTSTORE.clear() _CONTENTSTORE.clear()
modulestore = xmodule.modulestore.django.modulestore()
modulestore = xmodule.modulestore.django.editable_modulestore()
modulestore.collection.drop() modulestore.collection.drop()
xmodule.modulestore.django._MODULESTORES.clear() xmodule.modulestore.django.clear_existing_modulestores()
# Uncomment below to trigger a screenshot on error # Uncomment below to trigger a screenshot on error
......
...@@ -10,7 +10,7 @@ from django.contrib.auth import authenticate, login ...@@ -10,7 +10,7 @@ from django.contrib.auth import authenticate, login
from django.contrib.auth.middleware import AuthenticationMiddleware from django.contrib.auth.middleware import AuthenticationMiddleware
from django.contrib.sessions.middleware import SessionMiddleware from django.contrib.sessions.middleware import SessionMiddleware
from student.models import CourseEnrollment from student.models import CourseEnrollment
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import editable_modulestore
from xmodule.contentstore.django import contentstore from xmodule.contentstore.django import contentstore
from urllib import quote_plus from urllib import quote_plus
...@@ -60,11 +60,9 @@ def register_by_course_id(course_id, is_staff=False): ...@@ -60,11 +60,9 @@ def register_by_course_id(course_id, is_staff=False):
@world.absorb @world.absorb
def clear_courses(): def clear_courses():
# Flush and initialize the module store # Flush and initialize the module store
# It needs the templates because it creates new records
# by cloning from the template.
# Note that if your test module gets in some weird state # Note that if your test module gets in some weird state
# (though it shouldn't), do this manually # (though it shouldn't), do this manually
# from the bash shell to drop it: # from the bash shell to drop it:
# $ mongo test_xmodule --eval "db.dropDatabase()" # $ mongo test_xmodule --eval "db.dropDatabase()"
modulestore().collection.drop() editable_modulestore().collection.drop()
contentstore().fs_files.drop() contentstore().fs_files.drop()
...@@ -55,6 +55,7 @@ def modulestore(name='default'): ...@@ -55,6 +55,7 @@ def modulestore(name='default'):
return _MODULESTORES[name] return _MODULESTORES[name]
_loc_singleton = None _loc_singleton = None
def loc_mapper(): def loc_mapper():
""" """
...@@ -69,3 +70,42 @@ def loc_mapper(): ...@@ -69,3 +70,42 @@ def loc_mapper():
_loc_singleton = LocMapperStore(settings.modulestore_options) _loc_singleton = LocMapperStore(settings.modulestore_options)
return _loc_singleton return _loc_singleton
def clear_existing_modulestores():
"""
Clear the existing modulestore instances, causing
them to be re-created when accessed again.
This is useful for flushing state between unit tests.
"""
_MODULESTORES.clear()
def editable_modulestore(name='default'):
"""
Retrieve a modulestore that we can modify.
This is useful for tests that need to insert test
data into the modulestore.
Currently, only Mongo-backed modulestores can be modified.
Returns `None` if no editable modulestore is available.
"""
# Try to retrieve the ModuleStore
# Depending on the settings, this may or may not
# be editable.
store = modulestore(name)
# If this is a `MixedModuleStore`, then we will need
# to retrieve the actual Mongo instance.
# We assume that the default is Mongo.
if hasattr(store, 'modulestores'):
store = store.modulestores['default']
# At this point, we either have the ability to create
# items in the store, or we do not.
if hasattr(store, 'create_xmodule'):
return store
else:
return None
"""
Modulestore configuration for test cases.
"""
import copy
from uuid import uuid4 from uuid import uuid4
from django.test import TestCase from django.test import TestCase
from xmodule.modulestore.django import editable_modulestore, \
clear_existing_modulestores
from django.conf import settings
import xmodule.modulestore.django def mixed_store_config(data_dir, mappings):
from unittest.util import safe_repr """
Return a `MixedModuleStore` configuration, which provides
access to both Mongo- and XML-backed courses.
`data_dir` is the directory from which to load XML-backed courses.
`mappings` is a dictionary mapping course IDs to modulestores, for example:
{
'MITx/2.01x/2013_Spring': 'xml',
'edx/999/2013_Spring': 'default'
}
where 'xml' and 'default' are the two options provided by this configuration,
mapping (respectively) to XML-backed and Mongo-backed modulestores..
"""
mongo_config = mongo_store_config(data_dir)
xml_config = xml_store_config(data_dir)
store = {
'default': {
'ENGINE': 'xmodule.modulestore.mixed.MixedModuleStore',
'OPTIONS': {
'mappings': mappings,
'stores': {
'default': mongo_config['default'],
'xml': xml_config['default']
}
}
}
}
store['direct'] = store['default']
return store
def mongo_store_config(data_dir): def mongo_store_config(data_dir):
...@@ -27,6 +62,7 @@ def mongo_store_config(data_dir): ...@@ -27,6 +62,7 @@ def mongo_store_config(data_dir):
} }
} }
} }
store['direct'] = store['default'] store['direct'] = store['default']
return store return store
...@@ -45,23 +81,22 @@ def draft_mongo_store_config(data_dir): ...@@ -45,23 +81,22 @@ def draft_mongo_store_config(data_dir):
'render_template': 'mitxmako.shortcuts.render_to_string' 'render_template': 'mitxmako.shortcuts.render_to_string'
} }
return { store = {
'default': { 'default': {
'ENGINE': 'xmodule.modulestore.mongo.draft.DraftModuleStore', 'ENGINE': 'xmodule.modulestore.mongo.draft.DraftModuleStore',
'OPTIONS': modulestore_options 'OPTIONS': modulestore_options
},
'direct': {
'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore',
'OPTIONS': modulestore_options
} }
} }
store['direct'] = store['default']
return store
def xml_store_config(data_dir): def xml_store_config(data_dir):
""" """
Defines default module store using XMLModuleStore. Defines default module store using XMLModuleStore.
""" """
return { store = {
'default': { 'default': {
'ENGINE': 'xmodule.modulestore.xml.XMLModuleStore', 'ENGINE': 'xmodule.modulestore.xml.XMLModuleStore',
'OPTIONS': { 'OPTIONS': {
...@@ -71,12 +106,48 @@ def xml_store_config(data_dir): ...@@ -71,12 +106,48 @@ def xml_store_config(data_dir):
} }
} }
store['direct'] = store['default']
return store
class ModuleStoreTestCase(TestCase): class ModuleStoreTestCase(TestCase):
""" Subclass for any test case that uses the mongodb """
module store. This populates a uniquely named modulestore Subclass for any test case that uses a ModuleStore.
collection with templates before running the TestCase Ensures that the ModuleStore is cleaned before/after each test.
and drops it they are finished. """
Usage:
1. Create a subclass of `ModuleStoreTestCase`
2. Use Django's @override_settings decorator to use
the desired modulestore configuration.
For example:
MIXED_CONFIG = mixed_store_config(data_dir, mappings)
@override_settings(MODULESTORE=MIXED_CONFIG)
class FooTest(ModuleStoreTestCase):
# ...
3. Use factories (e.g. `CourseFactory`, `ItemFactory`) to populate
the modulestore with test data.
NOTE:
* For Mongo-backed courses (created with `CourseFactory`),
the state of the course will be reset before/after each
test method executes.
* For XML-backed courses, the course state will NOT
reset between test methods (although it will reset
between test classes)
The reason is: XML courses are not editable, so to reset
a course you have to reload it from disk, which is slow.
If you do need to reset an XML course, use
`clear_existing_modulestores()` directly in
your `setUp()` method.
"""
@staticmethod @staticmethod
def update_course(course, data): def update_course(course, data):
...@@ -89,107 +160,68 @@ class ModuleStoreTestCase(TestCase): ...@@ -89,107 +160,68 @@ class ModuleStoreTestCase(TestCase):
'data' is a dictionary with an entry for each CourseField we want to update. 'data' is a dictionary with an entry for each CourseField we want to update.
""" """
store = xmodule.modulestore.django.modulestore() store = editable_modulestore('direct')
store.update_metadata(course.location, data) store.update_metadata(course.location, data)
updated_course = store.get_instance(course.id, course.location) updated_course = store.get_instance(course.id, course.location)
return updated_course return updated_course
@staticmethod @staticmethod
def flush_mongo_except_templates(): def drop_mongo_collection():
""" """
Delete everything in the module store except templates. If using a Mongo-backed modulestore, drop the collection.
""" """
modulestore = xmodule.modulestore.django.modulestore()
# This query means: every item in the collection # This will return the mongo-backed modulestore
# that is not a template # even if we're using a mixed modulestore
query = {"_id.course": {"$ne": "templates"}} store = editable_modulestore()
# Remove everything except templates if hasattr(store, 'collection'):
modulestore.collection.remove(query) store.collection.drop()
modulestore.collection.drop()
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
""" """
Flush the mongo store and set up templates. Delete the existing modulestores, causing them to be reloaded.
""" """
# Clear out any existing modulestores,
# Use a uuid to differentiate # which will cause them to be re-created
# the mongo collections on jenkins. # the next time they are accessed.
cls.orig_modulestore = copy.deepcopy(settings.MODULESTORE) clear_existing_modulestores()
if 'direct' not in settings.MODULESTORE:
settings.MODULESTORE['direct'] = settings.MODULESTORE['default']
settings.MODULESTORE['default']['OPTIONS']['collection'] = 'modulestore_%s' % uuid4().hex
settings.MODULESTORE['direct']['OPTIONS']['collection'] = 'modulestore_%s' % uuid4().hex
xmodule.modulestore.django._MODULESTORES.clear()
print settings.MODULESTORE
TestCase.setUpClass() TestCase.setUpClass()
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
""" """
Revert to the old modulestore settings. Drop the existing modulestores, causing them to be reloaded.
Clean up any data stored in Mongo.
""" """
# Clean up by flushing the Mongo modulestore
cls.drop_mongo_collection()
# Clean up by dropping the collection # Clear out the existing modulestores,
modulestore = xmodule.modulestore.django.modulestore() # which will cause them to be re-created
modulestore.collection.drop() # the next time they are accessed.
# We do this at *both* setup and teardown just to be safe.
clear_existing_modulestores()
xmodule.modulestore.django._MODULESTORES.clear() TestCase.tearDownClass()
# Restore the original modulestore settings
settings.MODULESTORE = cls.orig_modulestore
def _pre_setup(self): def _pre_setup(self):
""" """
Remove everything but the templates before each test. Flush the ModuleStore before each test.
""" """
# Flush anything that is not a template # Flush the Mongo modulestore
ModuleStoreTestCase.flush_mongo_except_templates() ModuleStoreTestCase.drop_mongo_collection()
# Call superclass implementation # Call superclass implementation
super(ModuleStoreTestCase, self)._pre_setup() super(ModuleStoreTestCase, self)._pre_setup()
def _post_teardown(self): def _post_teardown(self):
""" """
Flush everything we created except the templates. Flush the ModuleStore after each test.
""" """
# Flush anything that is not a template ModuleStoreTestCase.drop_mongo_collection()
ModuleStoreTestCase.flush_mongo_except_templates()
# Call superclass implementation # Call superclass implementation
super(ModuleStoreTestCase, self)._post_teardown() super(ModuleStoreTestCase, self)._post_teardown()
def assert2XX(self, status_code, msg=None):
"""
Assert that the given value is a success status (between 200 and 299)
"""
msg = self._formatMessage(msg, "%s is not a success status" % safe_repr(status_code))
self.assertTrue(status_code >= 200 and status_code < 300, msg=msg)
def assert3XX(self, status_code, msg=None):
"""
Assert that the given value is a redirection status (between 300 and 399)
"""
msg = self._formatMessage(msg, "%s is not a redirection status" % safe_repr(status_code))
self.assertTrue(status_code >= 300 and status_code < 400, msg=msg)
def assert4XX(self, status_code, msg=None):
"""
Assert that the given value is a client error status (between 400 and 499)
"""
msg = self._formatMessage(msg, "%s is not a client error status" % safe_repr(status_code))
self.assertTrue(status_code >= 400 and status_code < 500, msg=msg)
def assert5XX(self, status_code, msg=None):
"""
Assert that the given value is a server error status (between 500 and 599)
"""
msg = self._formatMessage(msg, "%s is not a server error status" % safe_repr(status_code))
self.assertTrue(status_code >= 500 and status_code < 600, msg=msg)
...@@ -5,11 +5,12 @@ from uuid import uuid4 ...@@ -5,11 +5,12 @@ from uuid import uuid4
from pytz import UTC from pytz import UTC
from xmodule.modulestore import Location from xmodule.modulestore import Location
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import editable_modulestore
from xmodule.course_module import CourseDescriptor from xmodule.course_module import CourseDescriptor
from xblock.core import Scope from xblock.core import Scope
from xmodule.x_module import XModuleDescriptor from xmodule.x_module import XModuleDescriptor
class XModuleCourseFactory(Factory): class XModuleCourseFactory(Factory):
""" """
Factory for XModule courses. Factory for XModule courses.
...@@ -25,10 +26,7 @@ class XModuleCourseFactory(Factory): ...@@ -25,10 +26,7 @@ class XModuleCourseFactory(Factory):
display_name = kwargs.pop('display_name', None) display_name = kwargs.pop('display_name', None)
location = Location('i4x', org, number, 'course', Location.clean(display_name)) location = Location('i4x', org, number, 'course', Location.clean(display_name))
try: store = editable_modulestore('direct')
store = modulestore('direct')
except KeyError:
store = modulestore()
# Write the data to the mongo datastore # Write the data to the mongo datastore
new_course = store.create_xmodule(location) new_course = store.create_xmodule(location)
...@@ -117,7 +115,7 @@ class XModuleItemFactory(Factory): ...@@ -117,7 +115,7 @@ class XModuleItemFactory(Factory):
if not isinstance(data, basestring): if not isinstance(data, basestring):
data.update(template.get('data')) data.update(template.get('data'))
store = modulestore('direct') store = editable_modulestore('direct')
# This code was based off that in cms/djangoapps/contentstore/views.py # This code was based off that in cms/djangoapps/contentstore/views.py
parent = store.get_item(parent_location) parent = store.get_item(parent_location)
......
...@@ -3,21 +3,18 @@ from django.test.utils import override_settings ...@@ -3,21 +3,18 @@ from django.test.utils import override_settings
import xmodule.modulestore.django import xmodule.modulestore.django
from courseware.tests.tests import LoginEnrollmentTestCase, TEST_DATA_XML_MODULESTORE from courseware.tests.tests import LoginEnrollmentTestCase
from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
@override_settings(MODULESTORE=TEST_DATA_XML_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
class WikiRedirectTestCase(LoginEnrollmentTestCase): class WikiRedirectTestCase(LoginEnrollmentTestCase):
def setUp(self):
xmodule.modulestore.django._MODULESTORES = {}
courses = modulestore().get_courses()
def find_course(name): def setUp(self):
"""Assumes the course is present"""
return [c for c in courses if c.location.course == name][0]
self.toy = find_course("toy") # Load the toy course
self.toy = modulestore().get_course('edX/toy/2012_Fall')
# Create two accounts # Create two accounts
self.student = 'view@test.com' self.student = 'view@test.com'
......
...@@ -12,7 +12,7 @@ from django.core.urlresolvers import reverse ...@@ -12,7 +12,7 @@ from django.core.urlresolvers import reverse
from django.test.client import Client from django.test.client import Client
from student.tests.factories import UserFactory, CourseEnrollmentFactory from student.tests.factories import UserFactory, CourseEnrollmentFactory
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE
from xmodule.tests import get_test_system from xmodule.tests import get_test_system
from xmodule.modulestore import Location from xmodule.modulestore import Location
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
...@@ -20,7 +20,7 @@ from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory ...@@ -20,7 +20,7 @@ from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
class BaseTestXmodule(ModuleStoreTestCase): class BaseTestXmodule(ModuleStoreTestCase):
"""Base class for testing Xmodules with mongo store. """Base class for testing Xmodules with mongo store.
......
from xmodule.modulestore.tests.django_utils import xml_store_config, mongo_store_config, draft_mongo_store_config """
Define test configuration for modulestores.
"""
from xmodule.modulestore.tests.django_utils import xml_store_config, \
mongo_store_config, draft_mongo_store_config,\
mixed_store_config
from django.conf import settings from django.conf import settings
...@@ -6,3 +12,15 @@ TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT ...@@ -6,3 +12,15 @@ TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT
TEST_DATA_XML_MODULESTORE = xml_store_config(TEST_DATA_DIR) TEST_DATA_XML_MODULESTORE = xml_store_config(TEST_DATA_DIR)
TEST_DATA_MONGO_MODULESTORE = mongo_store_config(TEST_DATA_DIR) TEST_DATA_MONGO_MODULESTORE = mongo_store_config(TEST_DATA_DIR)
TEST_DATA_DRAFT_MONGO_MODULESTORE = draft_mongo_store_config(TEST_DATA_DIR) TEST_DATA_DRAFT_MONGO_MODULESTORE = draft_mongo_store_config(TEST_DATA_DIR)
# Map all XML course fixtures so they are accessible through
# the MixedModuleStore
MAPPINGS = {
'edX/toy/2012_Fall': 'xml',
'edX/toy/TT_2012_Fall': 'xml',
'edX/test_end/2012_Fall': 'xml',
'edX/test_about_blob_end_date/2012_Fall': 'xml',
'edX/graded/2012_Fall': 'xml',
'edX/open_ended/2012_Fall': 'xml',
}
TEST_DATA_MIXED_MODULESTORE = mixed_store_config(TEST_DATA_DIR, MAPPINGS)
...@@ -15,23 +15,23 @@ from django.core.urlresolvers import reverse ...@@ -15,23 +15,23 @@ from django.core.urlresolvers import reverse
from django.contrib.auth.models import Group, User from django.contrib.auth.models import Group, User
from courseware.access import _course_staff_group_name from courseware.access import _course_staff_group_name
from courseware.tests.helpers import LoginEnrollmentTestCase from courseware.tests.helpers import LoginEnrollmentTestCase
from modulestore_config import TEST_DATA_XML_MODULESTORE from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE
from xmodule.modulestore.django import modulestore from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
import xmodule.modulestore.django from xmodule.modulestore.django import modulestore, clear_existing_modulestores
import json import json
@override_settings(MODULESTORE=TEST_DATA_XML_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
class TestStaffMasqueradeAsStudent(LoginEnrollmentTestCase): class TestStaffMasqueradeAsStudent(ModuleStoreTestCase, LoginEnrollmentTestCase):
''' """
Check for staff being able to masquerade as student Check for staff being able to masquerade as student.
''' """
def setUp(self): def setUp(self):
xmodule.modulestore.django._MODULESTORES = {}
#self.full = modulestore().get_course("edX/full/6.002_Spring_2012") # Clear out the modulestores, causing them to reload
#self.toy = modulestore().get_course("edX/toy/2012_Fall") clear_existing_modulestores()
self.graded_course = modulestore().get_course("edX/graded/2012_Fall") self.graded_course = modulestore().get_course("edX/graded/2012_Fall")
# Create staff account # Create staff account
...@@ -50,7 +50,6 @@ class TestStaffMasqueradeAsStudent(LoginEnrollmentTestCase): ...@@ -50,7 +50,6 @@ class TestStaffMasqueradeAsStudent(LoginEnrollmentTestCase):
self.logout() self.logout()
self.login(self.instructor, self.password) self.login(self.instructor, self.password)
self.enroll(self.graded_course) self.enroll(self.graded_course)
# self.factory = RequestFactory()
def get_cw_section(self): def get_cw_section(self):
url = reverse('courseware_section', url = reverse('courseware_section',
...@@ -70,9 +69,9 @@ class TestStaffMasqueradeAsStudent(LoginEnrollmentTestCase): ...@@ -70,9 +69,9 @@ class TestStaffMasqueradeAsStudent(LoginEnrollmentTestCase):
self.assertTrue(sdebug in resp.content) self.assertTrue(sdebug in resp.content)
def toggle_masquerade(self): def toggle_masquerade(self):
''' """
Toggle masquerade state Toggle masquerade state.
''' """
masq_url = reverse('masquerade-switch', kwargs={'marg': 'toggle'}) masq_url = reverse('masquerade-switch', kwargs={'marg': 'toggle'})
print "masq_url ", masq_url print "masq_url ", masq_url
resp = self.client.get(masq_url) resp = self.client.get(masq_url)
......
...@@ -15,22 +15,17 @@ from xmodule.modulestore.django import modulestore ...@@ -15,22 +15,17 @@ from xmodule.modulestore.django import modulestore
from xmodule.modulestore.tests.factories import ItemFactory, CourseFactory from xmodule.modulestore.tests.factories import ItemFactory, CourseFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
import courseware.module_render as render import courseware.module_render as render
from courseware.tests.tests import LoginEnrollmentTestCase, TEST_DATA_MONGO_MODULESTORE from courseware.tests.tests import LoginEnrollmentTestCase
from courseware.model_data import ModelDataCache from courseware.model_data import ModelDataCache
from modulestore_config import TEST_DATA_XML_MODULESTORE from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE
from courseware.courses import get_course_with_access, course_image_url, get_course_info_section from courseware.courses import get_course_with_access, course_image_url, get_course_info_section
from .factories import UserFactory from .factories import UserFactory
class Stub: @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
def __init__(self): class ModuleRenderTestCase(ModuleStoreTestCase, LoginEnrollmentTestCase):
pass
@override_settings(MODULESTORE=TEST_DATA_XML_MODULESTORE)
class ModuleRenderTestCase(LoginEnrollmentTestCase):
def setUp(self): def setUp(self):
self.location = ['i4x', 'edX', 'toy', 'chapter', 'Overview'] self.location = ['i4x', 'edX', 'toy', 'chapter', 'Overview']
self.course_id = 'edX/toy/2012_Fall' self.course_id = 'edX/toy/2012_Fall'
...@@ -96,7 +91,7 @@ class ModuleRenderTestCase(LoginEnrollmentTestCase): ...@@ -96,7 +91,7 @@ class ModuleRenderTestCase(LoginEnrollmentTestCase):
settings.MAX_FILEUPLOADS_PER_INPUT})) settings.MAX_FILEUPLOADS_PER_INPUT}))
mock_request_2 = MagicMock() mock_request_2 = MagicMock()
mock_request_2.FILES.keys.return_value = ['file_id'] mock_request_2.FILES.keys.return_value = ['file_id']
inputfile = Stub() inputfile = MagicMock()
inputfile.size = 1 + settings.STUDENT_FILEUPLOAD_MAX_SIZE inputfile.size = 1 + settings.STUDENT_FILEUPLOAD_MAX_SIZE
inputfile.name = 'name' inputfile.name = 'name'
filelist = [inputfile] filelist = [inputfile]
...@@ -109,7 +104,7 @@ class ModuleRenderTestCase(LoginEnrollmentTestCase): ...@@ -109,7 +104,7 @@ class ModuleRenderTestCase(LoginEnrollmentTestCase):
mock_request_3.POST.copy.return_value = {'position': 1} mock_request_3.POST.copy.return_value = {'position': 1}
mock_request_3.FILES = False mock_request_3.FILES = False
mock_request_3.user = self.mock_user mock_request_3.user = self.mock_user
inputfile_2 = Stub() inputfile_2 = MagicMock()
inputfile_2.size = 1 inputfile_2.size = 1
inputfile_2.name = 'name' inputfile_2.name = 'name'
self.assertIsInstance(render.modx_dispatch(mock_request_3, 'goto_position', self.assertIsInstance(render.modx_dispatch(mock_request_3, 'goto_position',
...@@ -200,7 +195,7 @@ class ModuleRenderTestCase(LoginEnrollmentTestCase): ...@@ -200,7 +195,7 @@ class ModuleRenderTestCase(LoginEnrollmentTestCase):
self.assertEquals(403, response.status_code) self.assertEquals(403, response.status_code)
@override_settings(MODULESTORE=TEST_DATA_XML_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
class TestTOC(TestCase): class TestTOC(TestCase):
"""Check the Table of Contents for a course""" """Check the Table of Contents for a course"""
def setUp(self): def setUp(self):
...@@ -266,7 +261,7 @@ class TestTOC(TestCase): ...@@ -266,7 +261,7 @@ class TestTOC(TestCase):
self.assertIn(toc_section, actual) self.assertIn(toc_section, actual)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
class TestHtmlModifiers(ModuleStoreTestCase): class TestHtmlModifiers(ModuleStoreTestCase):
""" """
Tests to verify that standard modifications to the output of XModule/XBlock Tests to verify that standard modifications to the output of XModule/XBlock
......
...@@ -6,10 +6,10 @@ from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory ...@@ -6,10 +6,10 @@ from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from helpers import LoginEnrollmentTestCase, check_for_get_code from helpers import LoginEnrollmentTestCase, check_for_get_code
from modulestore_config import TEST_DATA_MONGO_MODULESTORE from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
class TestNavigation(ModuleStoreTestCase, LoginEnrollmentTestCase): class TestNavigation(ModuleStoreTestCase, LoginEnrollmentTestCase):
""" """
Check that navigation state is saved properly. Check that navigation state is saved properly.
......
...@@ -13,17 +13,17 @@ from django.test.utils import override_settings ...@@ -13,17 +13,17 @@ from django.test.utils import override_settings
from courseware import grades from courseware import grades
from courseware.model_data import ModelDataCache from courseware.model_data import ModelDataCache
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore, editable_modulestore
#import factories and parent testcase modules #import factories and parent testcase modules
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from capa.tests.response_xml_factory import OptionResponseXMLFactory, CustomResponseXMLFactory, SchematicResponseXMLFactory from capa.tests.response_xml_factory import OptionResponseXMLFactory, CustomResponseXMLFactory, SchematicResponseXMLFactory
from courseware.tests.helpers import LoginEnrollmentTestCase from courseware.tests.helpers import LoginEnrollmentTestCase
from courseware.tests.modulestore_config import TEST_DATA_MONGO_MODULESTORE from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
class TestSubmittingProblems(ModuleStoreTestCase, LoginEnrollmentTestCase): class TestSubmittingProblems(ModuleStoreTestCase, LoginEnrollmentTestCase):
""" """
Check that a course gets graded properly. Check that a course gets graded properly.
...@@ -217,7 +217,8 @@ class TestCourseGrader(TestSubmittingProblems): ...@@ -217,7 +217,8 @@ class TestCourseGrader(TestSubmittingProblems):
""" """
course_data = {'grading_policy': grading_policy} course_data = {'grading_policy': grading_policy}
modulestore().update_item(self.course.location, course_data) store = editable_modulestore('direct')
store.update_item(self.course.location, course_data)
self.refresh_course() self.refresh_course()
def get_grade_summary(self): def get_grade_summary(self):
......
...@@ -7,9 +7,9 @@ import courseware.tabs as tabs ...@@ -7,9 +7,9 @@ import courseware.tabs as tabs
from django.test.utils import override_settings from django.test.utils import override_settings
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE
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
from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE
class ProgressTestCase(TestCase): class ProgressTestCase(TestCase):
...@@ -261,7 +261,7 @@ class ValidateTabsTestCase(TestCase): ...@@ -261,7 +261,7 @@ class ValidateTabsTestCase(TestCase):
self.assertRaises(tabs.InvalidTabsException, tabs.validate_tabs, self.courses[4]) self.assertRaises(tabs.InvalidTabsException, tabs.validate_tabs, self.courses[4])
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
class DiscussionLinkTestCase(ModuleStoreTestCase): class DiscussionLinkTestCase(ModuleStoreTestCase):
def setUp(self): def setUp(self):
......
...@@ -16,10 +16,10 @@ from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase ...@@ -16,10 +16,10 @@ from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from helpers import LoginEnrollmentTestCase, check_for_get_code from helpers import LoginEnrollmentTestCase, check_for_get_code
from modulestore_config import TEST_DATA_MONGO_MODULESTORE from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
class TestViewAuth(ModuleStoreTestCase, LoginEnrollmentTestCase): class TestViewAuth(ModuleStoreTestCase, LoginEnrollmentTestCase):
""" """
Check that view authentication works properly. Check that view authentication works properly.
......
...@@ -18,23 +18,21 @@ from xmodule.modulestore.django import modulestore ...@@ -18,23 +18,21 @@ from xmodule.modulestore.django import modulestore
import courseware.views as views import courseware.views as views
from xmodule.modulestore import Location from xmodule.modulestore import Location
from pytz import UTC from pytz import UTC
from modulestore_config import TEST_DATA_XML_MODULESTORE from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE
from course_modes.models import CourseMode from course_modes.models import CourseMode
class Stub(): @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
pass
@override_settings(MODULESTORE=TEST_DATA_XML_MODULESTORE)
class TestJumpTo(TestCase): class TestJumpTo(TestCase):
"""Check the jumpto link for a course""" """
Check the jumpto link for a course.
"""
def setUp(self): def setUp(self):
self._MODULESTORES = {}
# Toy courses should be loaded # Load toy course from XML
self.course_name = 'edX/toy/2012_Fall' self.course_name = 'edX/toy/2012_Fall'
self.toy_course = modulestore().get_course('edX/toy/2012_Fall') self.toy_course = modulestore().get_course(self.course_name)
def test_jumpto_invalid_location(self): def test_jumpto_invalid_location(self):
location = Location('i4x', 'edX', 'toy', 'NoSuchPlace', None) location = Location('i4x', 'edX', 'toy', 'NoSuchPlace', None)
...@@ -73,7 +71,7 @@ class ViewsTestCase(TestCase): ...@@ -73,7 +71,7 @@ class ViewsTestCase(TestCase):
self.enrollment.created = self.date self.enrollment.created = self.date
self.enrollment.save() self.enrollment.save()
self.location = ['tag', 'org', 'course', 'category', 'name'] self.location = ['tag', 'org', 'course', 'category', 'name']
self._MODULESTORES = {}
# This is a CourseDescriptor object # This is a CourseDescriptor object
self.toy_course = modulestore().get_course('edX/toy/2012_Fall') self.toy_course = modulestore().get_course('edX/toy/2012_Fall')
self.request_factory = RequestFactory() self.request_factory = RequestFactory()
...@@ -87,7 +85,7 @@ class ViewsTestCase(TestCase): ...@@ -87,7 +85,7 @@ class ViewsTestCase(TestCase):
self.assertEquals(views.user_groups(mock_user), []) self.assertEquals(views.user_groups(mock_user), [])
def test_get_current_child(self): def test_get_current_child(self):
self.assertIsNone(views.get_current_child(Stub())) self.assertIsNone(views.get_current_child(MagicMock()))
mock_xmodule = MagicMock() mock_xmodule = MagicMock()
mock_xmodule.position = -1 mock_xmodule.position = -1
mock_xmodule.get_display_items.return_value = ['one', 'two'] mock_xmodule.get_display_items.return_value = ['one', 'two']
......
''' """
Test for lms courseware app Test for LMS courseware app.
''' """
import random
from django.test import TestCase
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.test.utils import override_settings from django.test.utils import override_settings
import xmodule.modulestore.django
from xmodule.error_module import ErrorDescriptor from xmodule.error_module import ErrorDescriptor
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
from xmodule.modulestore import Location from xmodule.modulestore import Location
from xmodule.modulestore.xml_importer import import_from_xml from xmodule.modulestore.xml_importer import import_from_xml
from xmodule.modulestore.xml import XMLModuleStore from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from helpers import LoginEnrollmentTestCase from courseware.tests.helpers import LoginEnrollmentTestCase
from modulestore_config import TEST_DATA_DIR, \ from courseware.tests.modulestore_config import TEST_DATA_DIR, \
TEST_DATA_XML_MODULESTORE, \
TEST_DATA_MONGO_MODULESTORE, \ TEST_DATA_MONGO_MODULESTORE, \
TEST_DATA_DRAFT_MONGO_MODULESTORE TEST_DATA_DRAFT_MONGO_MODULESTORE, \
import xmodule TEST_DATA_MIXED_MODULESTORE
class ActivateLoginTest(LoginEnrollmentTestCase): class ActivateLoginTest(LoginEnrollmentTestCase):
...@@ -47,32 +42,38 @@ class PageLoaderTestCase(LoginEnrollmentTestCase): ...@@ -47,32 +42,38 @@ class PageLoaderTestCase(LoginEnrollmentTestCase):
Base class that adds a function to load all pages in a modulestore. Base class that adds a function to load all pages in a modulestore.
""" """
def check_random_page_loads(self, module_store): def check_all_pages_load(self, course_id):
""" """
Choose a page in the course randomly, and assert that it loads. Assert that all pages in the course load correctly.
`course_id` is the ID of the course to check.
""" """
# enroll in the course before trying to access pages
courses = module_store.get_courses() store = modulestore()
self.assertEqual(len(courses), 1)
course = courses[0] # Enroll in the course before trying to access pages
course = store.get_course(course_id)
self.enroll(course, True) self.enroll(course, True)
course_id = course.id
# Search for items in the course # Search for items in the course
# None is treated as a wildcard # None is treated as a wildcard
course_loc = course.location course_loc = course.location
location_query = Location(course_loc.tag, course_loc.org, location_query = Location(
course_loc.course, None, None, None) course_loc.tag, course_loc.org,
course_loc.course, None, None, None
)
items = module_store.get_items(location_query, course_id=course_id) items = store.get_items(
location_query,
course_id=course_id,
depth=2
)
if len(items) < 1: if len(items) < 1:
self.fail('Could not retrieve any items from course') self.fail('Could not retrieve any items from course')
else:
descriptor = random.choice(items)
# We have ancillary course information now as modules # Try to load each item in the course
# and we can't simply use 'jump_to' to view them for descriptor in items:
if descriptor.location.category == 'about': if descriptor.location.category == 'about':
self._assert_loads('about_course', self._assert_loads('about_course',
{'course_id': course_id}, {'course_id': course_id},
...@@ -87,9 +88,6 @@ class PageLoaderTestCase(LoginEnrollmentTestCase): ...@@ -87,9 +88,6 @@ class PageLoaderTestCase(LoginEnrollmentTestCase):
self._assert_loads('info', {'course_id': course_id}, self._assert_loads('info', {'course_id': course_id},
descriptor) descriptor)
elif descriptor.location.category == 'custom_tag_template':
pass
else: else:
kwargs = {'course_id': course_id, kwargs = {'course_id': course_id,
...@@ -124,54 +122,51 @@ class PageLoaderTestCase(LoginEnrollmentTestCase): ...@@ -124,54 +122,51 @@ class PageLoaderTestCase(LoginEnrollmentTestCase):
self.assertNotIsInstance(descriptor, ErrorDescriptor) self.assertNotIsInstance(descriptor, ErrorDescriptor)
@override_settings(MODULESTORE=TEST_DATA_XML_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
class TestCoursesLoadTestCase_XmlModulestore(PageLoaderTestCase): class TestXmlCoursesLoad(ModuleStoreTestCase, PageLoaderTestCase):
""" """
Check that all pages in test courses load properly from XML. Check that all pages in test courses load properly from XML.
""" """
def setUp(self): def setUp(self):
super(TestCoursesLoadTestCase_XmlModulestore, self).setUp() super(TestXmlCoursesLoad, self).setUp()
self.setup_user() self.setup_user()
xmodule.modulestore.django._MODULESTORES.clear()
def test_toy_course_loads(self): def test_toy_course_loads(self):
module_class = 'xmodule.hidden_module.HiddenDescriptor'
module_store = XMLModuleStore(TEST_DATA_DIR,
default_class=module_class,
course_dirs=['toy'],
load_error_modules=True)
self.check_random_page_loads(module_store) # Load one of the XML based courses
# Our test mapping rules allow the MixedModuleStore
# to load this course from XML, not Mongo.
self.check_all_pages_load('edX/toy/2012_Fall')
# Importing XML courses isn't possible with MixedModuleStore,
# so we use a Mongo modulestore directly (as we would in Studio)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE)
class TestCoursesLoadTestCase_MongoModulestore(PageLoaderTestCase): class TestMongoCoursesLoad(ModuleStoreTestCase, PageLoaderTestCase):
""" """
Check that all pages in test courses load properly from Mongo. Check that all pages in test courses load properly from Mongo.
""" """
def setUp(self): def setUp(self):
super(TestCoursesLoadTestCase_MongoModulestore, self).setUp() super(TestMongoCoursesLoad, self).setUp()
self.setup_user() self.setup_user()
xmodule.modulestore.django._MODULESTORES.clear()
modulestore().collection.drop() # Import the toy course into a Mongo-backed modulestore
self.store = modulestore()
import_from_xml(self.store, TEST_DATA_DIR, ['toy'])
def test_toy_course_loads(self): def test_toy_course_loads(self):
module_store = modulestore() self.check_all_pages_load('edX/toy/2012_Fall')
import_from_xml(module_store, TEST_DATA_DIR, ['toy'])
self.check_random_page_loads(module_store)
def test_toy_textbooks_loads(self): def test_toy_textbooks_loads(self):
module_store = modulestore() location = Location(['i4x', 'edX', 'toy', 'course', '2012_Fall', None])
import_from_xml(module_store, TEST_DATA_DIR, ['toy']) course = self.store.get_item(location)
course = module_store.get_item(Location(['i4x', 'edX', 'toy', 'course', '2012_Fall', None]))
self.assertGreater(len(course.textbooks), 0) self.assertGreater(len(course.textbooks), 0)
@override_settings(MODULESTORE=TEST_DATA_DRAFT_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_DRAFT_MONGO_MODULESTORE)
class TestDraftModuleStore(TestCase): class TestDraftModuleStore(ModuleStoreTestCase):
def test_get_items_with_course_items(self): def test_get_items_with_course_items(self):
store = modulestore() store = modulestore()
......
...@@ -10,14 +10,14 @@ from django.core.urlresolvers import reverse ...@@ -10,14 +10,14 @@ from django.core.urlresolvers import reverse
from django.core.management import call_command from django.core.management import call_command
from util.testing import UrlResetMixin from util.testing import UrlResetMixin
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE
from nose.tools import assert_true, assert_equal from nose.tools import assert_true, assert_equal
from mock import patch from mock import patch
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
@patch('comment_client.utils.requests.request') @patch('comment_client.utils.requests.request')
class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase): class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase):
......
...@@ -6,7 +6,7 @@ from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase ...@@ -6,7 +6,7 @@ from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from util.testing import UrlResetMixin from util.testing import UrlResetMixin
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE
from nose.tools import assert_true from nose.tools import assert_true
from mock import patch, Mock from mock import patch, Mock
...@@ -15,7 +15,7 @@ import logging ...@@ -15,7 +15,7 @@ import logging
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
class ViewsExceptionTestCase(UrlResetMixin, ModuleStoreTestCase): class ViewsExceptionTestCase(UrlResetMixin, ModuleStoreTestCase):
@patch.dict("django.conf.settings.MITX_FEATURES", {"ENABLE_DISCUSSION_SERVICE": True}) @patch.dict("django.conf.settings.MITX_FEATURES", {"ENABLE_DISCUSSION_SERVICE": True})
......
...@@ -9,7 +9,7 @@ from xmodule.modulestore.tests.factories import CourseFactory ...@@ -9,7 +9,7 @@ from xmodule.modulestore.tests.factories import CourseFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from django.test.utils import override_settings from django.test.utils import override_settings
from courseware.tests.modulestore_config import TEST_DATA_MONGO_MODULESTORE from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE
from courseware.access import get_access_group_name from courseware.access import get_access_group_name
from django_comment_common.models import (Role, from django_comment_common.models import (Role,
...@@ -20,7 +20,7 @@ from instructor.access import (allow_access, ...@@ -20,7 +20,7 @@ from instructor.access import (allow_access,
update_forum_role_membership) update_forum_role_membership)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
class TestInstructorAccessList(ModuleStoreTestCase): class TestInstructorAccessList(ModuleStoreTestCase):
""" Test access listings. """ """ Test access listings. """
def setUp(self): def setUp(self):
...@@ -42,7 +42,7 @@ class TestInstructorAccessList(ModuleStoreTestCase): ...@@ -42,7 +42,7 @@ class TestInstructorAccessList(ModuleStoreTestCase):
self.assertEqual(set(beta_testers), set(self.beta_testers)) self.assertEqual(set(beta_testers), set(self.beta_testers))
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
class TestInstructorAccessAllow(ModuleStoreTestCase): class TestInstructorAccessAllow(ModuleStoreTestCase):
""" Test access allow. """ """ Test access allow. """
def setUp(self): def setUp(self):
...@@ -85,7 +85,8 @@ class TestInstructorAccessAllow(ModuleStoreTestCase): ...@@ -85,7 +85,8 @@ class TestInstructorAccessAllow(ModuleStoreTestCase):
group = Group.objects.get(name=get_access_group_name(self.course, 'staff')) group = Group.objects.get(name=get_access_group_name(self.course, 'staff'))
self.assertIn(user, group.user_set.all()) self.assertIn(user, group.user_set.all())
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE)
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
class TestInstructorAccessRevoke(ModuleStoreTestCase): class TestInstructorAccessRevoke(ModuleStoreTestCase):
""" Test access revoke. """ """ Test access revoke. """
def setUp(self): def setUp(self):
...@@ -129,7 +130,7 @@ class TestInstructorAccessRevoke(ModuleStoreTestCase): ...@@ -129,7 +130,7 @@ class TestInstructorAccessRevoke(ModuleStoreTestCase):
self.assertNotIn(user, group.user_set.all()) self.assertNotIn(user, group.user_set.all())
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
class TestInstructorAccessForum(ModuleStoreTestCase): class TestInstructorAccessForum(ModuleStoreTestCase):
""" """
Test forum access control. Test forum access control.
......
...@@ -14,7 +14,7 @@ from django.core.urlresolvers import reverse ...@@ -14,7 +14,7 @@ from django.core.urlresolvers import reverse
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse
from django.contrib.auth.models import User from django.contrib.auth.models import User
from courseware.tests.modulestore_config import TEST_DATA_MONGO_MODULESTORE from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from courseware.tests.helpers import LoginEnrollmentTestCase from courseware.tests.helpers import LoginEnrollmentTestCase
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
...@@ -90,7 +90,7 @@ class TestCommonExceptions400(unittest.TestCase): ...@@ -90,7 +90,7 @@ class TestCommonExceptions400(unittest.TestCase):
self.assertIn("Task is already running", result["error"]) self.assertIn("Task is already running", result["error"])
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
class TestInstructorAPIDenyLevels(ModuleStoreTestCase, LoginEnrollmentTestCase): class TestInstructorAPIDenyLevels(ModuleStoreTestCase, LoginEnrollmentTestCase):
""" """
Ensure that users cannot access endpoints they shouldn't be able to. Ensure that users cannot access endpoints they shouldn't be able to.
...@@ -147,7 +147,7 @@ class TestInstructorAPIDenyLevels(ModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -147,7 +147,7 @@ class TestInstructorAPIDenyLevels(ModuleStoreTestCase, LoginEnrollmentTestCase):
self.assertEqual(response.status_code, 403) self.assertEqual(response.status_code, 403)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
class TestInstructorAPIEnrollment(ModuleStoreTestCase, LoginEnrollmentTestCase): class TestInstructorAPIEnrollment(ModuleStoreTestCase, LoginEnrollmentTestCase):
""" """
Test enrollment modification endpoint. Test enrollment modification endpoint.
...@@ -270,7 +270,7 @@ class TestInstructorAPIEnrollment(ModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -270,7 +270,7 @@ class TestInstructorAPIEnrollment(ModuleStoreTestCase, LoginEnrollmentTestCase):
self.assertEqual(res_json, expected) self.assertEqual(res_json, expected)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
class TestInstructorAPILevelsAccess(ModuleStoreTestCase, LoginEnrollmentTestCase): class TestInstructorAPILevelsAccess(ModuleStoreTestCase, LoginEnrollmentTestCase):
""" """
Test endpoints whereby instructors can change permissions Test endpoints whereby instructors can change permissions
...@@ -414,7 +414,7 @@ class TestInstructorAPILevelsAccess(ModuleStoreTestCase, LoginEnrollmentTestCase ...@@ -414,7 +414,7 @@ class TestInstructorAPILevelsAccess(ModuleStoreTestCase, LoginEnrollmentTestCase
self.assertEqual(res_json, expected) self.assertEqual(res_json, expected)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
class TestInstructorAPILevelsDataDump(ModuleStoreTestCase, LoginEnrollmentTestCase): class TestInstructorAPILevelsDataDump(ModuleStoreTestCase, LoginEnrollmentTestCase):
""" """
Test endpoints that show data without side effects. Test endpoints that show data without side effects.
...@@ -521,7 +521,7 @@ class TestInstructorAPILevelsDataDump(ModuleStoreTestCase, LoginEnrollmentTestCa ...@@ -521,7 +521,7 @@ class TestInstructorAPILevelsDataDump(ModuleStoreTestCase, LoginEnrollmentTestCa
self.assertEqual(response.status_code, 400) self.assertEqual(response.status_code, 400)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
class TestInstructorAPIRegradeTask(ModuleStoreTestCase, LoginEnrollmentTestCase): class TestInstructorAPIRegradeTask(ModuleStoreTestCase, LoginEnrollmentTestCase):
""" """
Test endpoints whereby instructors can change student grades. Test endpoints whereby instructors can change student grades.
...@@ -655,7 +655,7 @@ class TestInstructorAPIRegradeTask(ModuleStoreTestCase, LoginEnrollmentTestCase) ...@@ -655,7 +655,7 @@ class TestInstructorAPIRegradeTask(ModuleStoreTestCase, LoginEnrollmentTestCase)
self.assertTrue(act.called) self.assertTrue(act.called)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
class TestInstructorAPITaskLists(ModuleStoreTestCase, LoginEnrollmentTestCase): class TestInstructorAPITaskLists(ModuleStoreTestCase, LoginEnrollmentTestCase):
""" """
Test instructor task list endpoint. Test instructor task list endpoint.
...@@ -745,7 +745,7 @@ class TestInstructorAPITaskLists(ModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -745,7 +745,7 @@ class TestInstructorAPITaskLists(ModuleStoreTestCase, LoginEnrollmentTestCase):
self.assertEqual(json.loads(response.content), expected_res) self.assertEqual(json.loads(response.content), expected_res)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
@override_settings(ANALYTICS_SERVER_URL="http://robotanalyticsserver.netbot:900/") @override_settings(ANALYTICS_SERVER_URL="http://robotanalyticsserver.netbot:900/")
@override_settings(ANALYTICS_API_KEY="robot_api_key") @override_settings(ANALYTICS_API_KEY="robot_api_key")
class TestInstructorAPIAnalyticsProxy(ModuleStoreTestCase, LoginEnrollmentTestCase): class TestInstructorAPIAnalyticsProxy(ModuleStoreTestCase, LoginEnrollmentTestCase):
......
...@@ -5,14 +5,14 @@ from django.test.utils import override_settings ...@@ -5,14 +5,14 @@ from django.test.utils import override_settings
from courseware.models import XModuleContentField from courseware.models import XModuleContentField
from courseware.tests.factories import ContentFactory from courseware.tests.factories import ContentFactory
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE
import instructor.hint_manager as view import instructor.hint_manager as view
from student.tests.factories import UserFactory from student.tests.factories import UserFactory
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
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
class HintManagerTest(ModuleStoreTestCase): class HintManagerTest(ModuleStoreTestCase):
def setUp(self): def setUp(self):
......
...@@ -17,21 +17,20 @@ from django.core.urlresolvers import reverse ...@@ -17,21 +17,20 @@ from django.core.urlresolvers import reverse
from courseware.access import _course_staff_group_name from courseware.access import _course_staff_group_name
from courseware.tests.helpers import LoginEnrollmentTestCase from courseware.tests.helpers import LoginEnrollmentTestCase
from courseware.tests.modulestore_config import TEST_DATA_XML_MODULESTORE from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE
from xmodule.modulestore.django import modulestore from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.django import modulestore, clear_existing_modulestores
import xmodule.modulestore.django import xmodule.modulestore.django
@override_settings(MODULESTORE=TEST_DATA_XML_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
class TestInstructorDashboardGradeDownloadCSV(LoginEnrollmentTestCase): class TestInstructorDashboardGradeDownloadCSV(ModuleStoreTestCase, LoginEnrollmentTestCase):
''' '''
Check for download of csv Check for download of csv
''' '''
def setUp(self): def setUp(self):
xmodule.modulestore.django._MODULESTORES = {} clear_existing_modulestores()
self.full = modulestore().get_course("edX/full/6.002_Spring_2012")
self.toy = modulestore().get_course("edX/toy/2012_Fall") self.toy = modulestore().get_course("edX/toy/2012_Fall")
# Create two accounts # Create two accounts
......
...@@ -7,7 +7,7 @@ from django.test.utils import override_settings ...@@ -7,7 +7,7 @@ from django.test.utils import override_settings
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from courseware.tests.helpers import LoginEnrollmentTestCase from courseware.tests.helpers import LoginEnrollmentTestCase
from courseware.tests.modulestore_config import TEST_DATA_MONGO_MODULESTORE from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
from student.tests.factories import UserFactory, CourseEnrollmentFactory, AdminFactory from student.tests.factories import UserFactory, CourseEnrollmentFactory, AdminFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
...@@ -18,7 +18,7 @@ from django.core import mail ...@@ -18,7 +18,7 @@ from django.core import mail
USER_COUNT = 4 USER_COUNT = 4
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
class TestInstructorEnrollsStudent(ModuleStoreTestCase, LoginEnrollmentTestCase): class TestInstructorEnrollsStudent(ModuleStoreTestCase, LoginEnrollmentTestCase):
""" """
Check Enrollment/Unenrollment with/without auto-enrollment on activation and with/without email notification Check Enrollment/Unenrollment with/without auto-enrollment on activation and with/without email notification
......
...@@ -15,9 +15,9 @@ from django_comment_client.utils import has_forum_access ...@@ -15,9 +15,9 @@ from django_comment_client.utils import has_forum_access
from courseware.access import _course_staff_group_name from courseware.access import _course_staff_group_name
from courseware.tests.helpers import LoginEnrollmentTestCase from courseware.tests.helpers import LoginEnrollmentTestCase
from courseware.tests.modulestore_config import TEST_DATA_XML_MODULESTORE from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore, clear_existing_modulestores
import xmodule.modulestore.django from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
FORUM_ROLES = [FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_MODERATOR, FORUM_ROLE_COMMUNITY_TA] FORUM_ROLES = [FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_MODERATOR, FORUM_ROLE_COMMUNITY_TA]
...@@ -32,14 +32,14 @@ def action_name(operation, rolename): ...@@ -32,14 +32,14 @@ def action_name(operation, rolename):
return '{0} forum {1}'.format(operation, FORUM_ADMIN_ACTION_SUFFIX[rolename]) return '{0} forum {1}'.format(operation, FORUM_ADMIN_ACTION_SUFFIX[rolename])
@override_settings(MODULESTORE=TEST_DATA_XML_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
class TestInstructorDashboardForumAdmin(LoginEnrollmentTestCase): class TestInstructorDashboardForumAdmin(ModuleStoreTestCase, LoginEnrollmentTestCase):
''' '''
Check for change in forum admin role memberships Check for change in forum admin role memberships
''' '''
def setUp(self): def setUp(self):
xmodule.modulestore.django._MODULESTORES = {} clear_existing_modulestores()
courses = modulestore().get_courses() courses = modulestore().get_courses()
self.course_id = "edX/toy/2012_Fall" self.course_id = "edX/toy/2012_Fall"
......
...@@ -7,7 +7,7 @@ from django.core.urlresolvers import reverse ...@@ -7,7 +7,7 @@ from django.core.urlresolvers import reverse
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from student.tests.factories import UserFactory, CourseEnrollmentFactory, AdminFactory from student.tests.factories import UserFactory, CourseEnrollmentFactory, AdminFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE from courseware.tests.tests import TEST_DATA_MIXED_MODULESTORE
from capa.tests.response_xml_factory import StringResponseXMLFactory from capa.tests.response_xml_factory import StringResponseXMLFactory
from courseware.tests.factories import StudentModuleFactory from courseware.tests.factories import StudentModuleFactory
from xmodule.modulestore import Location from xmodule.modulestore import Location
...@@ -17,7 +17,7 @@ from xmodule.modulestore.django import modulestore ...@@ -17,7 +17,7 @@ from xmodule.modulestore.django import modulestore
USER_COUNT = 11 USER_COUNT = 11
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
class TestGradebook(ModuleStoreTestCase): class TestGradebook(ModuleStoreTestCase):
grading_policy = None grading_policy = None
......
...@@ -7,14 +7,15 @@ from django.test.client import RequestFactory ...@@ -7,14 +7,15 @@ from django.test.client import RequestFactory
from django.test.utils import override_settings from django.test.utils import override_settings
from markupsafe import escape from markupsafe import escape
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE from courseware.tests.tests import TEST_DATA_MIXED_MODULESTORE
from student.tests.factories import UserFactory, CourseEnrollmentFactory from student.tests.factories import UserFactory, CourseEnrollmentFactory
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
from instructor.views import legacy from instructor.views import legacy
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE)
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
class TestXss(ModuleStoreTestCase): class TestXss(ModuleStoreTestCase):
def setUp(self): def setUp(self):
self._request_factory = RequestFactory() self._request_factory = RequestFactory()
......
...@@ -13,13 +13,13 @@ from django.contrib.auth.models import User ...@@ -13,13 +13,13 @@ from django.contrib.auth.models import User
from django.test.utils import override_settings from django.test.utils import override_settings
from capa.tests.response_xml_factory import OptionResponseXMLFactory from capa.tests.response_xml_factory import OptionResponseXMLFactory
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import editable_modulestore
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from student.tests.factories import CourseEnrollmentFactory, UserFactory from student.tests.factories import CourseEnrollmentFactory, UserFactory
from courseware.model_data import StudentModule from courseware.model_data import StudentModule
from courseware.tests.tests import LoginEnrollmentTestCase, TEST_DATA_MONGO_MODULESTORE from courseware.tests.tests import LoginEnrollmentTestCase, TEST_DATA_MIXED_MODULESTORE
from instructor_task.api_helper import encode_problem_and_student_input from instructor_task.api_helper import encode_problem_and_student_input
from instructor_task.models import PROGRESS, QUEUING from instructor_task.models import PROGRESS, QUEUING
...@@ -95,7 +95,7 @@ class InstructorTaskTestCase(TestCase): ...@@ -95,7 +95,7 @@ class InstructorTaskTestCase(TestCase):
return self._create_entry(task_state=task_state, task_output=progress, student=student) return self._create_entry(task_state=task_state, task_output=progress, student=student)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
class InstructorTaskModuleTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase): class InstructorTaskModuleTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase):
""" """
Base test class for InstructorTask-related tests that require Base test class for InstructorTask-related tests that require
...@@ -106,7 +106,7 @@ class InstructorTaskModuleTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase) ...@@ -106,7 +106,7 @@ class InstructorTaskModuleTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase)
def initialize_course(self): def initialize_course(self):
"""Create a course in the store, with a chapter and section.""" """Create a course in the store, with a chapter and section."""
self.module_store = modulestore() self.module_store = editable_modulestore()
# Create the course # Create the course
self.course = CourseFactory.create(org=TEST_COURSE_ORG, self.course = CourseFactory.create(org=TEST_COURSE_ORG,
......
...@@ -14,7 +14,7 @@ from django.core.management import call_command ...@@ -14,7 +14,7 @@ from django.core.management import call_command
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from nose.tools import assert_true from nose.tools import assert_true
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE
from licenses.models import CourseSoftware, UserLicense from licenses.models import CourseSoftware, UserLicense
from student.tests.factories import UserFactory from student.tests.factories import UserFactory
...@@ -143,7 +143,7 @@ class LicenseTestCase(TestCase): ...@@ -143,7 +143,7 @@ class LicenseTestCase(TestCase):
self.assertEqual(302, response.status_code) self.assertEqual(302, response.status_code)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
class CommandTest(ModuleStoreTestCase): class CommandTest(ModuleStoreTestCase):
'''Test management command for importing serial numbers''' '''Test management command for importing serial numbers'''
def setUp(self): def setUp(self):
......
...@@ -27,14 +27,15 @@ log = logging.getLogger(__name__) ...@@ -27,14 +27,15 @@ log = logging.getLogger(__name__)
from django.test.utils import override_settings from django.test.utils import override_settings
from xmodule.tests import test_util_open_ended from xmodule.tests import test_util_open_ended
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from courseware.tests import factories from courseware.tests import factories
from courseware.tests.modulestore_config import TEST_DATA_XML_MODULESTORE from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE
from courseware.tests.helpers import LoginEnrollmentTestCase, check_for_get_code, check_for_post_code from courseware.tests.helpers import LoginEnrollmentTestCase, check_for_get_code, check_for_post_code
@override_settings(MODULESTORE=TEST_DATA_XML_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
class TestStaffGradingService(LoginEnrollmentTestCase): class TestStaffGradingService(ModuleStoreTestCase, LoginEnrollmentTestCase):
''' '''
Check that staff grading service proxy works. Basically just checking the Check that staff grading service proxy works. Basically just checking the
access control and error handling logic -- all the actual work is on the access control and error handling logic -- all the actual work is on the
...@@ -42,8 +43,6 @@ class TestStaffGradingService(LoginEnrollmentTestCase): ...@@ -42,8 +43,6 @@ class TestStaffGradingService(LoginEnrollmentTestCase):
''' '''
def setUp(self): def setUp(self):
xmodule.modulestore.django._MODULESTORES = {}
self.student = 'view@test.com' self.student = 'view@test.com'
self.instructor = 'view2@test.com' self.instructor = 'view2@test.com'
self.password = 'foo' self.password = 'foo'
...@@ -138,8 +137,8 @@ class TestStaffGradingService(LoginEnrollmentTestCase): ...@@ -138,8 +137,8 @@ class TestStaffGradingService(LoginEnrollmentTestCase):
self.assertIsNotNone(content['problem_list']) self.assertIsNotNone(content['problem_list'])
@override_settings(MODULESTORE=TEST_DATA_XML_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
class TestPeerGradingService(LoginEnrollmentTestCase): class TestPeerGradingService(ModuleStoreTestCase, LoginEnrollmentTestCase):
''' '''
Check that staff grading service proxy works. Basically just checking the Check that staff grading service proxy works. Basically just checking the
access control and error handling logic -- all the actual work is on the access control and error handling logic -- all the actual work is on the
...@@ -147,8 +146,6 @@ class TestPeerGradingService(LoginEnrollmentTestCase): ...@@ -147,8 +146,6 @@ class TestPeerGradingService(LoginEnrollmentTestCase):
''' '''
def setUp(self): def setUp(self):
xmodule.modulestore.django._MODULESTORES = {}
self.student = 'view@test.com' self.student = 'view@test.com'
self.instructor = 'view2@test.com' self.instructor = 'view2@test.com'
self.password = 'foo' self.password = 'foo'
...@@ -293,8 +290,8 @@ class TestPeerGradingService(LoginEnrollmentTestCase): ...@@ -293,8 +290,8 @@ class TestPeerGradingService(LoginEnrollmentTestCase):
self.assertFalse('actual_score' in response) self.assertFalse('actual_score' in response)
@override_settings(MODULESTORE=TEST_DATA_XML_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
class TestPanel(LoginEnrollmentTestCase): class TestPanel(ModuleStoreTestCase, LoginEnrollmentTestCase):
""" """
Run tests on the open ended panel Run tests on the open ended panel
""" """
......
...@@ -10,7 +10,7 @@ import requests ...@@ -10,7 +10,7 @@ import requests
from django.test.utils import override_settings from django.test.utils import override_settings
from django.core.urlresolvers import reverse, NoReverseMatch from django.core.urlresolvers import reverse, NoReverseMatch
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE
from student.tests.factories import UserFactory, CourseEnrollmentFactory from student.tests.factories import UserFactory, CourseEnrollmentFactory
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
...@@ -36,7 +36,8 @@ HTML_BOOK = { ...@@ -36,7 +36,8 @@ HTML_BOOK = {
], ],
} }
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE)
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
class StaticBookTest(ModuleStoreTestCase): class StaticBookTest(ModuleStoreTestCase):
""" """
Helpers for the static book tests. Helpers for the static book tests.
......
...@@ -36,15 +36,21 @@ modulestore_options = { ...@@ -36,15 +36,21 @@ modulestore_options = {
MODULESTORE = { MODULESTORE = {
'default': { 'default': {
'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore', 'ENGINE': 'xmodule.modulestore.mixed.MixedModuleStore',
'OPTIONS': modulestore_options 'OPTIONS': {
}, 'mappings': {},
'direct': { 'stores': {
'default': {
'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore', 'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore',
'OPTIONS': modulestore_options 'OPTIONS': modulestore_options
} }
}
}
}
} }
MODULESTORE['direct'] = MODULESTORE['default']
CONTENTSTORE = { CONTENTSTORE = {
'ENGINE': 'xmodule.contentstore.mongo.MongoContentStore', 'ENGINE': 'xmodule.contentstore.mongo.MongoContentStore',
'OPTIONS': { 'OPTIONS': {
......
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