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
328ed927
Commit
328ed927
authored
Jun 17, 2015
by
Kyle McCormick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new testing decorator check_mongo_calls_range
parent
3dafdd2f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
10 deletions
+25
-10
common/lib/xmodule/xmodule/modulestore/tests/factories.py
+25
-10
No files found.
common/lib/xmodule/xmodule/modulestore/tests/factories.py
View file @
328ed927
...
...
@@ -381,35 +381,50 @@ def mongo_uses_error_check(store):
@contextmanager
def
check_mongo_calls
(
num_finds
=
0
,
num
_sends
=
None
):
def
check_mongo_calls
_range
(
max_finds
=
float
(
"inf"
),
min_finds
=
0
,
max_sends
=
None
,
min
_sends
=
None
):
"""
Instruments the given store to count the number of calls to find (incl find_one) and the number
of calls to send_message which is for insert, update, and remove (if you provide num_sends). At the
end of the with statement, it compares the counts to the
num_finds and num_send
s.
end of the with statement, it compares the counts to the
bounds provided in the argument
s.
:param num_finds: the exact number of find calls expected
:param num_sends: If none, don't instrument the send calls. If non-none, count and compare to
the given int value.
:param max_finds: the maximum number of find calls expected
:param min_finds: the minimum number of find calls expected
:param max_sends: If non-none, make sure number of send calls are <=max_sends
:param min_sends: If non-none, make sure number of send calls are >=min_sends
"""
with
check_sum_of_calls
(
pymongo
.
message
,
[
'query'
,
'get_more'
],
num
_finds
,
num_finds
max
_finds
,
min_finds
,
):
if
num
_sends
is
not
None
:
if
max_sends
is
not
None
or
min
_sends
is
not
None
:
with
check_sum_of_calls
(
pymongo
.
message
,
# mongo < 2.6 uses insert, update, delete and _do_batched_insert. >= 2.6 _do_batched_write
[
'insert'
,
'update'
,
'delete'
,
'_do_batched_write_command'
,
'_do_batched_insert'
,
],
num_sends
,
num_sends
max_sends
if
max_sends
is
not
None
else
float
(
"inf"
)
,
min_sends
if
min_sends
is
not
None
else
0
,
):
yield
else
:
yield
@contextmanager
def
check_mongo_calls
(
num_finds
=
0
,
num_sends
=
None
):
"""
Instruments the given store to count the number of calls to find (incl find_one) and the number
of calls to send_message which is for insert, update, and remove (if you provide num_sends). At the
end of the with statement, it compares the counts to the num_finds and num_sends.
:param num_finds: the exact number of find calls expected
:param num_sends: If none, don't instrument the send calls. If non-none, count and compare to
the given int value.
"""
with
check_mongo_calls_range
(
num_finds
,
num_finds
,
num_sends
,
num_sends
):
yield
# This dict represents the attribute keys for a course's 'about' info.
# Note: The 'video' attribute is intentionally excluded as it must be
# handled separately; its value maps to an alternate key name.
...
...
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