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
abd4859f
Commit
abd4859f
authored
Nov 20, 2017
by
Matjaz Gregoric
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert test to DDT and test for primary, nearest modes.
parent
e4a3a30c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
6 deletions
+16
-6
common/lib/xmodule/xmodule/tests/test_mongo_utils.py
+16
-6
No files found.
common/lib/xmodule/xmodule/tests/test_mongo_utils.py
View file @
abd4859f
"""Tests for methods defined in mongo_utils.py"""
"""
Tests for methods defined in mongo_utils.py
"""
import
ddt
import
os
import
os
from
unittest
import
TestCase
from
unittest
import
TestCase
from
uuid
import
uuid4
from
uuid
import
uuid4
...
@@ -10,19 +13,26 @@ from django.conf import settings
...
@@ -10,19 +13,26 @@ from django.conf import settings
from
xmodule.mongo_utils
import
connect_to_mongodb
from
xmodule.mongo_utils
import
connect_to_mongodb
@ddt.ddt
class
MongoUtilsTests
(
TestCase
):
class
MongoUtilsTests
(
TestCase
):
"""
"""
Tests for methods exposed in mongo_utils
Tests for methods exposed in mongo_utils
"""
"""
def
test_connect_to_mongo_read_preference
(
self
):
@ddt.data
(
(
'PRIMARY'
,
'primary'
,
ReadPreference
.
PRIMARY
),
(
'SECONDARY_PREFERRED'
,
'secondaryPreferred'
,
ReadPreference
.
SECONDARY_PREFERRED
),
(
'NEAREST'
,
'nearest'
,
ReadPreference
.
NEAREST
),
)
@ddt.unpack
def
test_connect_to_mongo_read_preference
(
self
,
enum_name
,
mongos_name
,
expected_read_preference
):
"""
"""
Test that read_preference parameter gets converted to a valid pymongo read preference.
Test that read_preference parameter gets converted to a valid pymongo read preference.
"""
"""
host
=
'edx.devstack.mongo'
if
'BOK_CHOY_HOSTNAME'
in
os
.
environ
else
'localhost'
host
=
'edx.devstack.mongo'
if
'BOK_CHOY_HOSTNAME'
in
os
.
environ
else
'localhost'
db
=
'test_read_preference_
%
s'
%
uuid4
()
.
hex
db
=
'test_read_preference_
%
s'
%
uuid4
()
.
hex
# Support for read_preference given in constant name form (ie. PRIMARY, SECONDARY_PREFERRED)
# Support for read_preference given in constant name form (ie. PRIMARY, SECONDARY_PREFERRED)
connection
=
connect_to_mongodb
(
db
,
host
,
read_preference
=
'SECONDARY_PREFERRED'
)
connection
=
connect_to_mongodb
(
db
,
host
,
read_preference
=
enum_name
)
self
.
assertEqual
(
connection
.
client
.
read_preference
,
ReadPreference
.
SECONDARY_PREFERRED
)
self
.
assertEqual
(
connection
.
client
.
read_preference
,
expected_read_preference
)
# Support for read_preference given as mongos name.
# Support for read_preference given as mongos name.
connection
=
connect_to_mongodb
(
db
,
host
,
read_preference
=
'secondaryPreferred'
)
connection
=
connect_to_mongodb
(
db
,
host
,
read_preference
=
mongos_name
)
self
.
assertEqual
(
connection
.
client
.
read_preference
,
ReadPreference
.
SECONDARY_PREFERRED
)
self
.
assertEqual
(
connection
.
client
.
read_preference
,
expected_read_preference
)
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