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
ad331238
Commit
ad331238
authored
Oct 03, 2013
by
Carlos Andrés Rocha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup mongodb authentication
Authenticate to the database before getting a reference to the collection.
parent
b30d46f8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
3 deletions
+8
-3
eventtracking/backends/mongodb.py
+7
-2
eventtracking/backends/tests/test_mongodb.py
+1
-1
No files found.
eventtracking/backends/mongodb.py
View file @
ad331238
...
@@ -62,10 +62,12 @@ class MongoBackend(object):
...
@@ -62,10 +62,12 @@ class MongoBackend(object):
**
extra
**
extra
)
)
self
.
collection
=
self
.
connection
[
db_name
][
collection
_name
]
self
.
database
=
self
.
connection
[
db
_name
]
if
user
or
password
:
if
user
or
password
:
self
.
collection
.
database
.
authenticate
(
user
,
password
)
self
.
database
.
authenticate
(
user
,
password
)
self
.
collection
=
self
.
database
[
collection_name
]
self
.
_create_indexes
()
self
.
_create_indexes
()
...
@@ -86,5 +88,8 @@ class MongoBackend(object):
...
@@ -86,5 +88,8 @@ class MongoBackend(object):
try
:
try
:
self
.
collection
.
insert
(
event
,
manipulate
=
False
)
self
.
collection
.
insert
(
event
,
manipulate
=
False
)
except
PyMongoError
:
except
PyMongoError
:
# The event will be lost in case of a connection error.
# pymongo will re-connect/re-authenticate automatically
# during the next event.
msg
=
'Error inserting to MongoDB event tracker backend'
msg
=
'Error inserting to MongoDB event tracker backend'
log
.
exception
(
msg
)
log
.
exception
(
msg
)
eventtracking/backends/tests/test_mongodb.py
View file @
ad331238
...
@@ -45,7 +45,7 @@ class TestMongoBackend(TestCase):
...
@@ -45,7 +45,7 @@ class TestMongoBackend(TestCase):
def
test_authentication_settings
(
self
):
def
test_authentication_settings
(
self
):
backend
=
MongoBackend
(
user
=
sentinel
.
user
,
password
=
sentinel
.
password
)
backend
=
MongoBackend
(
user
=
sentinel
.
user
,
password
=
sentinel
.
password
)
backend
.
collection
.
database
.
authenticate
.
assert_called_once_with
(
sentinel
.
user
,
sentinel
.
password
)
backend
.
database
.
authenticate
.
assert_called_once_with
(
sentinel
.
user
,
sentinel
.
password
)
def
test_mongo_insertion_error
(
self
):
def
test_mongo_insertion_error
(
self
):
self
.
backend
.
collection
.
insert
.
side_effect
=
PyMongoError
self
.
backend
.
collection
.
insert
.
side_effect
=
PyMongoError
...
...
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