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
05b34098
Commit
05b34098
authored
Aug 19, 2013
by
Will Daly
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored ModuleStoreTestCase to use modulestore interface
for clearing _MODULESTORES
parent
06977c19
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
9 deletions
+18
-9
common/lib/xmodule/xmodule/modulestore/django.py
+9
-0
common/lib/xmodule/xmodule/modulestore/tests/django_utils.py
+9
-9
No files found.
common/lib/xmodule/xmodule/modulestore/django.py
View file @
05b34098
...
@@ -53,3 +53,12 @@ def modulestore(name='default'):
...
@@ -53,3 +53,12 @@ def modulestore(name='default'):
settings
.
MODULESTORE
[
name
][
'OPTIONS'
])
settings
.
MODULESTORE
[
name
][
'OPTIONS'
])
return
_MODULESTORES
[
name
]
return
_MODULESTORES
[
name
]
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
()
common/lib/xmodule/xmodule/modulestore/tests/django_utils.py
View file @
05b34098
...
@@ -3,7 +3,7 @@ from uuid import uuid4
...
@@ -3,7 +3,7 @@ from uuid import uuid4
from
django.test
import
TestCase
from
django.test
import
TestCase
from
django.conf
import
settings
from
django.conf
import
settings
import
xmodule.modulestore.django
from
xmodule.modulestore.django
import
modulestore
,
clear_existing_modulestores
from
unittest.util
import
safe_repr
from
unittest.util
import
safe_repr
...
@@ -126,7 +126,7 @@ class ModuleStoreTestCase(TestCase):
...
@@ -126,7 +126,7 @@ 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
=
modulestore
()
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
...
@@ -136,15 +136,15 @@ class ModuleStoreTestCase(TestCase):
...
@@ -136,15 +136,15 @@ class ModuleStoreTestCase(TestCase):
"""
"""
Delete everything in the module store except templates.
Delete everything in the module store except templates.
"""
"""
modulestore
=
xmodule
.
modulestore
.
django
.
modulestore
()
store
=
modulestore
()
# This query means: every item in the collection
# This query means: every item in the collection
# that is not a template
# that is not a template
query
=
{
"_id.course"
:
{
"$ne"
:
"templates"
}}
query
=
{
"_id.course"
:
{
"$ne"
:
"templates"
}}
# Remove everything except templates
# Remove everything except templates
module
store
.
collection
.
remove
(
query
)
store
.
collection
.
remove
(
query
)
module
store
.
collection
.
drop
()
store
.
collection
.
drop
()
@classmethod
@classmethod
def
setUpClass
(
cls
):
def
setUpClass
(
cls
):
...
@@ -160,7 +160,7 @@ class ModuleStoreTestCase(TestCase):
...
@@ -160,7 +160,7 @@ class ModuleStoreTestCase(TestCase):
settings
.
MODULESTORE
[
'default'
][
'OPTIONS'
][
'collection'
]
=
'modulestore_
%
s'
%
uuid4
()
.
hex
settings
.
MODULESTORE
[
'default'
][
'OPTIONS'
][
'collection'
]
=
'modulestore_
%
s'
%
uuid4
()
.
hex
settings
.
MODULESTORE
[
'direct'
][
'OPTIONS'
][
'collection'
]
=
'modulestore_
%
s'
%
uuid4
()
.
hex
settings
.
MODULESTORE
[
'direct'
][
'OPTIONS'
][
'collection'
]
=
'modulestore_
%
s'
%
uuid4
()
.
hex
xmodule
.
modulestore
.
django
.
_MODULESTORES
.
clear
()
clear_existing_modulestores
()
print
settings
.
MODULESTORE
print
settings
.
MODULESTORE
...
@@ -173,10 +173,10 @@ class ModuleStoreTestCase(TestCase):
...
@@ -173,10 +173,10 @@ class ModuleStoreTestCase(TestCase):
"""
"""
# Clean up by dropping the collection
# Clean up by dropping the collection
modulestore
=
xmodule
.
modulestore
.
django
.
modulestore
()
store
=
modulestore
()
module
store
.
collection
.
drop
()
store
.
collection
.
drop
()
xmodule
.
modulestore
.
django
.
_MODULESTORES
.
clear
()
clear_existing_modulestores
()
# Restore the original modulestore settings
# Restore the original modulestore settings
settings
.
MODULESTORE
=
cls
.
orig_modulestore
settings
.
MODULESTORE
=
cls
.
orig_modulestore
...
...
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