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
0684f6a4
Commit
0684f6a4
authored
Dec 06, 2013
by
Don Mitchell
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1878 from edx/dhm/pymongo_client
Upgrade pymongo usage from deprecated connection to client
parents
f7ffc1d2
298e7a23
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
46 additions
and
28 deletions
+46
-28
cms/djangoapps/contentstore/tests/test_contentstore.py
+1
-1
common/lib/xmodule/xmodule/contentstore/mongo.py
+9
-3
common/lib/xmodule/xmodule/modulestore/mongo/base.py
+13
-9
common/lib/xmodule/xmodule/modulestore/tests/django_utils.py
+3
-3
common/lib/xmodule/xmodule/modulestore/tests/test_location_mapper.py
+1
-1
common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py
+6
-2
common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py
+9
-5
common/lib/xmodule/xmodule/modulestore/tests/test_orphan.py
+1
-1
common/lib/xmodule/xmodule/modulestore/tests/test_publish.py
+1
-1
common/lib/xmodule/xmodule/modulestore/tests/test_split_migrator.py
+1
-1
common/lib/xmodule/xmodule/modulestore/tests/test_split_modulestore.py
+1
-1
No files found.
cms/djangoapps/contentstore/tests/test_contentstore.py
View file @
0684f6a4
...
...
@@ -1604,7 +1604,7 @@ class ContentStoreTest(ModuleStoreTestCase):
data
=
parse_json
(
resp
)
self
.
assertRegexpMatches
(
data
[
'locator'
],
r"^MITx.999.Robot_Super_Course/branch/draft/block/chapter([0-9]|[a-f]){3}$"
r"^MITx.999.Robot_Super_Course/branch/draft/block/chapter([0-9]|[a-f]){3
,
}$"
)
def
test_capa_module
(
self
):
...
...
common/lib/xmodule/xmodule/contentstore/mongo.py
View file @
0684f6a4
from
pymongo
import
Connection
import
pymongo
import
gridfs
from
gridfs.errors
import
NoFile
...
...
@@ -24,8 +24,14 @@ class MongoContentStore(ContentStore):
:param collection: ignores but provided for consistency w/ other doc_store_config patterns
"""
logging
.
debug
(
'Using MongoDB for static content serving at host={0} db={1}'
.
format
(
host
,
db
))
_db
=
Connection
(
host
=
host
,
port
=
port
,
**
kwargs
)[
db
]
_db
=
pymongo
.
database
.
Database
(
pymongo
.
MongoClient
(
host
=
host
,
port
=
port
,
**
kwargs
),
db
)
if
user
is
not
None
and
password
is
not
None
:
_db
.
authenticate
(
user
,
password
)
...
...
common/lib/xmodule/xmodule/modulestore/mongo/base.py
View file @
0684f6a4
...
...
@@ -274,25 +274,29 @@ class MongoModuleStore(ModuleStoreWriteBase):
"""
Create & open the connection, authenticate, and provide pointers to the collection
"""
self
.
collection
=
pymongo
.
connection
.
Connection
(
host
=
host
,
port
=
port
,
tz_aware
=
tz_aware
,
**
kwargs
)[
db
][
collection
]
self
.
database
=
pymongo
.
database
.
Database
(
pymongo
.
MongoClient
(
host
=
host
,
port
=
port
,
tz_aware
=
tz_aware
,
**
kwargs
),
db
)
self
.
collection
=
self
.
database
[
collection
]
if
user
is
not
None
and
password
is
not
None
:
self
.
collection
.
database
.
authenticate
(
user
,
password
)
self
.
database
.
authenticate
(
user
,
password
)
do_connection
(
**
doc_store_config
)
# Force mongo to report errors, at the expense of performance
self
.
collection
.
safe
=
True
self
.
collection
.
write_concern
=
{
'w'
:
1
}
# Force mongo to maintain an index over _id.* that is in the same order
# that is used when querying by a location
self
.
collection
.
ensure_index
(
zip
((
'_id.'
+
field
for
field
in
Location
.
_fields
),
repeat
(
1
))
zip
((
'_id.'
+
field
for
field
in
Location
.
_fields
),
repeat
(
1
))
,
)
if
default_class
is
not
None
:
...
...
common/lib/xmodule/xmodule/modulestore/tests/django_utils.py
View file @
0684f6a4
...
...
@@ -55,7 +55,7 @@ def mongo_store_config(data_dir):
'DOC_STORE_CONFIG'
:
{
'host'
:
'localhost'
,
'db'
:
'test_xmodule'
,
'collection'
:
'modulestore
_
%
s'
%
uuid4
()
.
hex
,
'collection'
:
'modulestore
{0}'
.
format
(
uuid4
()
.
hex
[:
5
])
,
},
'OPTIONS'
:
{
'default_class'
:
'xmodule.raw_module.RawDescriptor'
,
...
...
@@ -86,7 +86,7 @@ def draft_mongo_store_config(data_dir):
'DOC_STORE_CONFIG'
:
{
'host'
:
'localhost'
,
'db'
:
'test_xmodule'
,
'collection'
:
'modulestore
_
%
s'
%
uuid4
()
.
hex
,
'collection'
:
'modulestore
{0}'
.
format
(
uuid4
()
.
hex
[:
5
])
,
},
'OPTIONS'
:
modulestore_options
}
...
...
@@ -121,7 +121,7 @@ def studio_store_config(data_dir):
store_config
=
{
'host'
:
'localhost'
,
'db'
:
'test_xmodule'
,
'collection'
:
'modulestore
_
%
s'
%
uuid4
()
.
hex
,
'collection'
:
'modulestore
{0}'
.
format
(
uuid4
()
.
hex
[:
5
])
,
}
options
=
{
'default_class'
:
'xmodule.raw_module.RawDescriptor'
,
...
...
common/lib/xmodule/xmodule/modulestore/tests/test_location_mapper.py
View file @
0684f6a4
...
...
@@ -20,7 +20,7 @@ class TestLocationMapper(unittest.TestCase):
modulestore_options
=
{
'host'
:
'localhost'
,
'db'
:
'test_xmodule'
,
'collection'
:
'modulestore{0}'
.
format
(
uuid
.
uuid4
()
.
hex
),
'collection'
:
'modulestore{0}'
.
format
(
uuid
.
uuid4
()
.
hex
[:
5
]
),
}
# pylint: disable=W0142
...
...
common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py
View file @
0684f6a4
...
...
@@ -21,7 +21,7 @@ from xmodule.modulestore.mixed import MixedModuleStore
HOST
=
'localhost'
PORT
=
27017
DB
=
'test_mongo_
%
s'
%
uuid4
()
.
hex
DB
=
'test_mongo_
%
s'
%
uuid4
()
.
hex
[:
5
]
COLLECTION
=
'modulestore'
FS_ROOT
=
DATA_DIR
DEFAULT_CLASS
=
'xmodule.raw_module.RawDescriptor'
...
...
@@ -69,7 +69,11 @@ class TestMixedModuleStore(object):
"""
Set up the database for testing
"""
cls
.
connection
=
pymongo
.
connection
.
Connection
(
HOST
,
PORT
)
cls
.
connection
=
pymongo
.
MongoClient
(
host
=
HOST
,
port
=
PORT
,
tz_aware
=
True
,
)
cls
.
connection
.
drop_database
(
DB
)
cls
.
fake_location
=
Location
([
'i4x'
,
'foo'
,
'bar'
,
'vertical'
,
'baz'
])
cls
.
import_org
,
cls
.
import_course
,
cls
.
import_run
=
IMPORT_COURSEID
.
split
(
'/'
)
...
...
common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py
View file @
0684f6a4
...
...
@@ -20,7 +20,7 @@ from xmodule.modulestore.xml_importer import import_from_xml, perform_xlint
from
xmodule.contentstore.mongo
import
MongoContentStore
from
xmodule.modulestore.tests.test_modulestore
import
check_path_to_location
from
IPython.testing.nose_assert_methods
import
assert_in
,
assert_not_in
from
IPython.testing.nose_assert_methods
import
assert_in
from
xmodule.exceptions
import
NotFoundError
from
xmodule.modulestore.exceptions
import
InsufficientSpecificationError
...
...
@@ -28,7 +28,7 @@ log = logging.getLogger(__name__)
HOST
=
'localhost'
PORT
=
27017
DB
=
'test_mongo_
%
s'
%
uuid4
()
.
hex
DB
=
'test_mongo_
%
s'
%
uuid4
()
.
hex
[:
5
]
COLLECTION
=
'modulestore'
FS_ROOT
=
DATA_DIR
# TODO (vshnayder): will need a real fs_root for testing load_item
DEFAULT_CLASS
=
'xmodule.raw_module.RawDescriptor'
...
...
@@ -39,7 +39,11 @@ class TestMongoModuleStore(object):
'''Tests!'''
@classmethod
def
setupClass
(
cls
):
cls
.
connection
=
pymongo
.
connection
.
Connection
(
HOST
,
PORT
)
cls
.
connection
=
pymongo
.
MongoClient
(
host
=
HOST
,
port
=
PORT
,
tz_aware
=
True
,
)
cls
.
connection
.
drop_database
(
DB
)
# NOTE: Creating a single db for all the tests to save time. This
...
...
@@ -50,8 +54,8 @@ class TestMongoModuleStore(object):
@classmethod
def
teardownClass
(
cls
):
cls
.
connection
=
pymongo
.
connection
.
Connection
(
HOST
,
PORT
)
cls
.
connection
.
drop_database
(
DB
)
if
cls
.
connection
:
cls
.
connection
.
drop_database
(
DB
)
@staticmethod
def
initdb
():
...
...
common/lib/xmodule/xmodule/modulestore/tests/test_orphan.py
View file @
0684f6a4
...
...
@@ -33,7 +33,7 @@ class TestOrphan(unittest.TestCase):
split_course_id
=
'test_org.test_course.runid'
def
setUp
(
self
):
self
.
db_config
[
'collection'
]
=
'modulestore{0}'
.
format
(
uuid
.
uuid4
()
.
hex
)
self
.
db_config
[
'collection'
]
=
'modulestore{0}'
.
format
(
uuid
.
uuid4
()
.
hex
[:
5
]
)
self
.
userid
=
random
.
getrandbits
(
32
)
super
(
TestOrphan
,
self
)
.
setUp
()
...
...
common/lib/xmodule/xmodule/modulestore/tests/test_publish.py
View file @
0684f6a4
...
...
@@ -34,7 +34,7 @@ class TestPublish(unittest.TestCase):
}
def
setUp
(
self
):
self
.
db_config
[
'collection'
]
=
'modulestore{0}'
.
format
(
uuid
.
uuid4
()
.
hex
)
self
.
db_config
[
'collection'
]
=
'modulestore{0}'
.
format
(
uuid
.
uuid4
()
.
hex
[:
5
]
)
self
.
old_mongo
=
MongoModuleStore
(
self
.
db_config
,
**
self
.
modulestore_options
)
self
.
draft_mongo
=
DraftMongoModuleStore
(
self
.
db_config
,
**
self
.
modulestore_options
)
...
...
common/lib/xmodule/xmodule/modulestore/tests/test_split_migrator.py
View file @
0684f6a4
...
...
@@ -31,7 +31,7 @@ class TestMigration(unittest.TestCase):
db_config
=
{
'host'
:
'localhost'
,
'db'
:
'test_xmodule'
,
'collection'
:
'modulestore{0}'
.
format
(
uuid
.
uuid4
()
.
hex
),
'collection'
:
'modulestore{0}'
.
format
(
uuid
.
uuid4
()
.
hex
[:
5
]
),
}
modulestore_options
=
{
...
...
common/lib/xmodule/xmodule/modulestore/tests/test_split_modulestore.py
View file @
0684f6a4
...
...
@@ -32,7 +32,7 @@ class SplitModuleTest(unittest.TestCase):
DOC_STORE_CONFIG
=
{
'host'
:
'localhost'
,
'db'
:
'test_xmodule'
,
'collection'
:
'modulestore{0}'
.
format
(
uuid
.
uuid4
()
.
hex
),
'collection'
:
'modulestore{0}'
.
format
(
uuid
.
uuid4
()
.
hex
[:
5
]
),
}
modulestore_options
=
{
'default_class'
:
'xmodule.raw_module.RawDescriptor'
,
...
...
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