Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
77bbd303
Commit
77bbd303
authored
Dec 05, 2014
by
Jesse Zoldak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not create a modulestore unnecessarily in tests
parent
789a9dc9
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
5 deletions
+23
-5
cms/djangoapps/contentstore/tests/test_crud.py
+16
-3
common/lib/xmodule/xmodule/modulestore/tests/django_utils.py
+7
-2
No files found.
cms/djangoapps/contentstore/tests/test_crud.py
View file @
77bbd303
import
unittest
from
opaque_keys.edx.locator
import
LocalId
from
xmodule
import
templates
from
xmodule.modulestore
import
ModuleStoreEnum
from
xmodule.modulestore.tests
import
persistent_factories
...
...
@@ -7,10 +9,9 @@ from xmodule.course_module import CourseDescriptor
from
xmodule.modulestore.django
import
modulestore
,
clear_existing_modulestores
from
xmodule.seq_module
import
SequenceDescriptor
from
xmodule.capa_module
import
CapaDescriptor
from
opaque_keys.edx.locator
import
BlockUsageLocator
,
LocalId
from
xmodule.contentstore.django
import
_CONTENTSTORE
from
xmodule.modulestore.exceptions
import
ItemNotFoundError
,
DuplicateCourseError
from
xmodule.html_module
import
HtmlDescriptor
from
xmodule.modulestore.tests.django_utils
import
ModuleStoreTestCase
class
TemplateTests
(
unittest
.
TestCase
):
...
...
@@ -20,10 +21,22 @@ class TemplateTests(unittest.TestCase):
def
setUp
(
self
):
clear_existing_modulestores
()
# redundant w/ cleanup but someone was getting errors
self
.
addCleanup
(
ModuleStoreTestCase
.
drop_mongo_collections
)
self
.
addCleanup
(
self
.
_
drop_mongo_collections
)
self
.
addCleanup
(
clear_existing_modulestores
)
self
.
split_store
=
modulestore
()
.
_get_modulestore_by_type
(
ModuleStoreEnum
.
Type
.
split
)
@staticmethod
def
_drop_mongo_collections
():
"""
If using a Mongo-backed modulestore & contentstore, drop the collections.
"""
module_store
=
modulestore
()
if
hasattr
(
module_store
,
'_drop_database'
):
module_store
.
_drop_database
()
# pylint: disable=protected-access
_CONTENTSTORE
.
clear
()
if
hasattr
(
module_store
,
'close_connections'
):
module_store
.
close_connections
()
def
test_get_templates
(
self
):
found
=
templates
.
all_templates
()
self
.
assertIsNotNone
(
found
.
get
(
'course'
))
...
...
common/lib/xmodule/xmodule/modulestore/tests/django_utils.py
View file @
77bbd303
...
...
@@ -7,6 +7,8 @@ import pytz
from
tempfile
import
mkdtemp
from
uuid
import
uuid4
from
mock
import
patch
from
django.conf
import
settings
from
django.contrib.auth.models
import
User
from
django.test
import
TestCase
...
...
@@ -276,10 +278,14 @@ class ModuleStoreTestCase(TestCase):
return
updated_course
@staticmethod
def
drop_mongo_collections
():
@patch
(
'xmodule.modulestore.django.create_modulestore_instance'
)
def
drop_mongo_collections
(
mock_create
):
"""
If using a Mongo-backed modulestore & contentstore, drop the collections.
"""
# Do not create the modulestore if it does not exist.
mock_create
.
return_value
=
None
module_store
=
modulestore
()
if
hasattr
(
module_store
,
'_drop_database'
):
module_store
.
_drop_database
()
# pylint: disable=protected-access
...
...
@@ -302,7 +308,6 @@ class ModuleStoreTestCase(TestCase):
"""
Flush the ModuleStore.
"""
# Flush the Mongo modulestore
self
.
drop_mongo_collections
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment