Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
event-tracking
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
event-tracking
Commits
b5ca901f
Commit
b5ca901f
authored
Sep 18, 2013
by
Gabe Mulley
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify ported mongodb backend
parent
1c29d33a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
10 deletions
+23
-10
eventtracking/backends/__init__.py
+1
-1
eventtracking/backends/mongodb.py
+4
-3
eventtracking/backends/tests/test_mongodb.py
+17
-6
requirements.txt
+1
-0
No files found.
eventtracking/backends/__init__.py
View file @
b5ca901f
...
@@ -23,6 +23,6 @@ class BaseBackend(object):
...
@@ -23,6 +23,6 @@ class BaseBackend(object):
pass
pass
@abc.abstractmethod
@abc.abstractmethod
def
send
(
self
,
event
):
def
send
(
self
,
event
):
# pragma: no cover
"""Send event to tracker."""
"""Send event to tracker."""
pass
pass
eventtracking/backends/mongodb.py
View file @
b5ca901f
...
@@ -8,10 +8,10 @@ import pymongo
...
@@ -8,10 +8,10 @@ import pymongo
from
pymongo
import
MongoClient
from
pymongo
import
MongoClient
from
pymongo.errors
import
PyMongoError
from
pymongo.errors
import
PyMongoError
from
track
.backends
import
BaseBackend
from
eventtracking
.backends
import
BaseBackend
log
=
logging
.
getLogger
(
'track.backends.mongodb'
)
log
=
logging
.
getLogger
(
__name__
)
class
MongoBackend
(
BaseBackend
):
class
MongoBackend
(
BaseBackend
):
...
@@ -43,7 +43,7 @@ class MongoBackend(BaseBackend):
...
@@ -43,7 +43,7 @@ class MongoBackend(BaseBackend):
user
=
kwargs
.
get
(
'user'
,
''
)
user
=
kwargs
.
get
(
'user'
,
''
)
password
=
kwargs
.
get
(
'password'
,
''
)
password
=
kwargs
.
get
(
'password'
,
''
)
db_name
=
kwargs
.
get
(
'database'
,
'
track
'
)
db_name
=
kwargs
.
get
(
'database'
,
'
eventtracking
'
)
collection_name
=
kwargs
.
get
(
'collection'
,
'events'
)
collection_name
=
kwargs
.
get
(
'collection'
,
'events'
)
# Other mongo connection arguments
# Other mongo connection arguments
...
@@ -72,6 +72,7 @@ class MongoBackend(BaseBackend):
...
@@ -72,6 +72,7 @@ class MongoBackend(BaseBackend):
self
.
_create_indexes
()
self
.
_create_indexes
()
def
_create_indexes
(
self
):
def
_create_indexes
(
self
):
"""Ensures the proper fields are indexed"""
# WARNING: The collection will be locked during the index
# WARNING: The collection will be locked during the index
# creation. If the collection has a large number of
# creation. If the collection has a large number of
# documents in it, the operation can take a long time.
# documents in it, the operation can take a long time.
...
...
eventtracking/backends/tests/test_mongodb.py
View file @
b5ca901f
from
__future__
import
absolute_import
from
__future__
import
absolute_import
from
uuid
import
uuid4
from
unittest
import
TestCase
from
mock
import
patch
from
mock
import
patch
from
mock
import
sentinel
from
pymongo.errors
import
PyMongoError
from
django.test
import
TestCase
from
eventtracking.backends.mongodb
import
MongoBackend
from
track.backends.mongodb
import
MongoBackend
class
TestMongoBackend
(
TestCase
):
# pylint: disable=missing-docstring
class
TestMongoBackend
(
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
mongo_patcher
=
patch
(
'
track
.backends.mongodb.MongoClient'
)
self
.
mongo_patcher
=
patch
(
'
eventtracking
.backends.mongodb.MongoClient'
)
self
.
addCleanup
(
self
.
mongo_patcher
.
stop
)
self
.
addCleanup
(
self
.
mongo_patcher
.
stop
)
self
.
mongo_patcher
.
start
()
self
.
mongo_patcher
.
start
()
...
@@ -38,3 +39,13 @@ class TestMongoBackend(TestCase):
...
@@ -38,3 +39,13 @@ class TestMongoBackend(TestCase):
self
.
assertEqual
(
events
[
0
],
first_argument
(
calls
[
0
]))
self
.
assertEqual
(
events
[
0
],
first_argument
(
calls
[
0
]))
self
.
assertEqual
(
events
[
1
],
first_argument
(
calls
[
1
]))
self
.
assertEqual
(
events
[
1
],
first_argument
(
calls
[
1
]))
def
test_authentication_settings
(
self
):
backend
=
MongoBackend
(
user
=
sentinel
.
user
,
password
=
sentinel
.
password
)
backend
.
collection
.
database
.
authenticate
.
assert_called_once_with
(
sentinel
.
user
,
sentinel
.
password
)
def
test_mongo_insertion_error
(
self
):
self
.
backend
.
collection
.
insert
.
side_effect
=
PyMongoError
self
.
backend
.
send
({
'test'
:
1
})
# Ensure this error is caught
requirements.txt
View file @
b5ca901f
# 3rd-party needs
# 3rd-party needs
Django
>= 1.4, < 1.5
Django
>= 1.4, < 1.5
pymongo
==2.4.1
# For Tests
# For Tests
mock
mock
...
...
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