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
e118682d
Commit
e118682d
authored
May 13, 2015
by
Diana Huang
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #32 from edx/diana/catch-more-errors
Catch BSON errors as well as PyMongo errors.
parents
3efbae60
af9a16b5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
3 deletions
+12
-3
eventtracking/backends/mongodb.py
+4
-2
eventtracking/backends/tests/test_mongodb.py
+8
-1
No files found.
eventtracking/backends/mongodb.py
View file @
e118682d
...
...
@@ -7,6 +7,7 @@ import logging
import
pymongo
from
pymongo
import
MongoClient
from
pymongo.errors
import
PyMongoError
from
bson.errors
import
BSONError
log
=
logging
.
getLogger
(
__name__
)
...
...
@@ -87,8 +88,9 @@ class MongoBackend(object):
"""Insert the event in to the Mongo collection"""
try
:
self
.
collection
.
insert
(
event
,
manipulate
=
False
)
except
PyMongoError
:
# The event will be lost in case of a connection error.
except
(
PyMongoError
,
BSONError
):
# The event will be lost in case of a connection error or any error
# that occurs when trying to insert the event into Mongo.
# pymongo will re-connect/re-authenticate automatically
# during the next event.
msg
=
'Error inserting to MongoDB event tracker backend'
...
...
eventtracking/backends/tests/test_mongodb.py
View file @
e118682d
...
...
@@ -6,6 +6,7 @@ from mock import patch
from
mock
import
sentinel
from
pymongo.errors
import
PyMongoError
from
bson.errors
import
BSONError
from
eventtracking.backends.mongodb
import
MongoBackend
...
...
@@ -47,8 +48,14 @@ class TestMongoBackend(TestCase):
backend
=
MongoBackend
(
user
=
sentinel
.
user
,
password
=
sentinel
.
password
)
backend
.
database
.
authenticate
.
assert_called_once_with
(
sentinel
.
user
,
sentinel
.
password
)
def
test_mongo_insertion_error
(
self
):
def
test_mongo_
pymongo_
insertion_error
(
self
):
self
.
backend
.
collection
.
insert
.
side_effect
=
PyMongoError
self
.
backend
.
send
({
'test'
:
1
})
# Ensure this error is caught
def
test_mongo_bson_insertion_error
(
self
):
self
.
backend
.
collection
.
insert
.
side_effect
=
BSONError
self
.
backend
.
send
({
'test'
:
1
})
# Ensure this error is caught
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