Commit b5ca901f by Gabe Mulley

modify ported mongodb backend

parent 1c29d33a
...@@ -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
...@@ -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.
......
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
# 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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment