2016-08-16 17:21:09 -04:00
|
|
|
from unittest import TestCase
|
|
|
|
from pymongo import MongoClient
|
|
|
|
|
2016-08-24 15:52:07 -04:00
|
|
|
from metrik.conf import get_config
|
2016-08-19 22:02:19 -04:00
|
|
|
from metrik.targets.mongo import MongoTarget
|
2016-08-16 17:21:09 -04:00
|
|
|
|
|
|
|
|
|
|
|
class MongoTest(TestCase):
|
2016-08-23 22:23:35 -04:00
|
|
|
def setUp(self):
|
2016-08-24 15:52:07 -04:00
|
|
|
config = get_config()
|
|
|
|
self.client = MongoClient(
|
|
|
|
host=config.get('metrik', 'mongo_host'),
|
|
|
|
port=config.getint('metrik', 'mongo_port'))
|
|
|
|
self.db = self.client[config.get('metrik', 'mongo_database')]
|
2016-08-23 22:23:35 -04:00
|
|
|
|
2016-08-16 17:21:09 -04:00
|
|
|
def tearDown(self):
|
|
|
|
super(MongoTest, self).tearDown()
|
2016-08-24 15:52:07 -04:00
|
|
|
config = get_config()
|
|
|
|
self.client.drop_database(config.get('metrik', 'mongo_database'))
|
2016-08-16 17:21:09 -04:00
|
|
|
|
|
|
|
|
|
|
|
class MongoTestTest(MongoTest):
|
|
|
|
# Test that the database is dropped correctly after each test
|
|
|
|
def test_round1(self):
|
|
|
|
t = MongoTarget('consistent_collection', 'consistent_id')
|
|
|
|
assert not t.exists()
|
|
|
|
t.persist({'a': 'b'})
|
|
|
|
|
|
|
|
def test_round2(self):
|
|
|
|
t = MongoTarget('consistent_collection', 'consistent_id')
|
|
|
|
assert not t.exists()
|
|
|
|
t.persist({'a': 'b'})
|