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
6a64b404
Commit
6a64b404
authored
Sep 11, 2013
by
Carlos Andrés Rocha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Mock mongo event tracking backend during tests
parent
049aa3bb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
24 deletions
+21
-24
common/djangoapps/track/backends/tests/test_mongodb.py
+21
-24
No files found.
common/djangoapps/track/backends/tests/test_mongodb.py
View file @
6a64b404
...
...
@@ -2,7 +2,7 @@ from __future__ import absolute_import
from
uuid
import
uuid4
import
pymongo
from
mock
import
patch
from
django.test
import
TestCase
...
...
@@ -11,33 +11,30 @@ from track.backends.mongodb import MongoBackend
class
TestMongoBackend
(
TestCase
):
def
setUp
(
self
):
# Use a random database name to prevent problems with tests running
# simultenousely against the same mongo instance
database
=
'_track_backends_mongodb_{0}'
.
format
(
uuid4
()
.
hex
)
collection
=
'_test'
self
.
mongo_patcher
=
patch
(
'track.backends.mongodb.MongoClient'
)
self
.
addCleanup
(
self
.
mongo_patcher
.
stop
)
self
.
mongo_patcher
.
start
()
self
.
connection
=
pymongo
.
MongoClient
()
self
.
database
=
self
.
connection
[
database
]
self
.
collection
=
self
.
database
[
collection
]
self
.
backend
=
MongoBackend
()
# During tests, wait until mongo acknowledged the write
write_concern
=
1
def
test_mongo_backend
(
self
):
events
=
[{
'test'
:
1
},
{
'test'
:
2
}]
self
.
backend
=
MongoBackend
(
database
=
database
,
collection
=
collection
,
w
=
write_concern
)
self
.
backend
.
send
(
events
[
0
])
self
.
backend
.
send
(
events
[
1
])
def
test_mongo_backend
(
self
):
self
.
backend
.
send
({
'test'
:
1
})
self
.
backend
.
send
({
'test'
:
2
})
# Check if we inserted events into the database
calls
=
self
.
backend
.
collection
.
insert
.
mock_calls
self
.
assertEqual
(
len
(
calls
),
2
)
#
Get all the objects in the db ignoring _i
d
results
=
list
(
self
.
collection
.
find
({},
{
'_id'
:
False
}))
#
Unpack the arguments and check if the events were use
d
# as the first argument to collection.insert
self
.
assertEqual
(
len
(
results
),
2
)
self
.
assertEqual
(
results
,
[{
'test'
:
1
},
{
'test'
:
2
}])
def
first_argument
(
call
):
_
,
args
,
_
=
call
return
args
[
0
]
def
tearDown
(
self
):
self
.
connection
.
drop_database
(
self
.
database
)
self
.
assertEqual
(
events
[
0
],
first_argument
(
calls
[
0
]))
self
.
assertEqual
(
events
[
1
],
first_argument
(
calls
[
1
])
)
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