The existing pattern of using `override_settings(MODULESTORE=...)` prevented
us from having more than one layer of subclassing in modulestore tests.
In a structure like:
@override_settings(MODULESTORE=store_a)
class BaseTestCase(ModuleStoreTestCase):
def setUp(self):
# use store
@override_settings(MODULESTORE=store_b)
class ChildTestCase(BaseTestCase):
def setUp(self):
# use store
In this case, the store actions performed in `BaseTestCase` on behalf of
`ChildTestCase` would still use `store_a`, even though the `ChildTestCase`
had specified to use `store_b`. This is because the `override_settings`
decorator would be the innermost wrapper around the `BaseTestCase.setUp` method,
no matter what `ChildTestCase` does.
To remedy this, we move the call to `override_settings` into the
`ModuleStoreTestCase.setUp` method, and use a cleanup to remove the override.
Subclasses can just defined the `MODULESTORE` class attribute to specify which
modulestore to use _for the entire `setUp` chain_.
[PLAT-419]
23 lines
801 B
Python
23 lines
801 B
Python
from django.test import TestCase
|
|
from django.test.utils import override_settings
|
|
|
|
from xmodule.modulestore.django import modulestore
|
|
from opaque_keys.edx.locations import SlashSeparatedCourseKey
|
|
|
|
from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
|
|
|
|
|
|
class TestDraftModuleStore(TestCase):
|
|
"""
|
|
Test the draft modulestore
|
|
"""
|
|
def test_get_items_with_course_items(self):
|
|
store = modulestore()
|
|
|
|
# fix was to allow get_items() to take the course_id parameter
|
|
store.get_items(SlashSeparatedCourseKey('a', 'b', 'c'), qualifiers={'category': 'vertical'})
|
|
|
|
# test success is just getting through the above statement.
|
|
# The bug was that 'course_id' argument was
|
|
# not allowed to be passed in (i.e. was throwing exception)
|