mirror of
https://github.com/bspeice/metrik
synced 2024-11-05 06:58:12 -05:00
529375e10b
I have destroyed a good bit of data so far because unit tests (correctly) dropped databases when they were done, but the config told it to drop the live database (incorrectly)
32 lines
1.0 KiB
Python
32 lines
1.0 KiB
Python
from unittest import TestCase
|
|
from pymongo import MongoClient
|
|
|
|
from metrik.conf import get_config
|
|
from metrik.targets.mongo import MongoTarget
|
|
|
|
|
|
class MongoTest(TestCase):
|
|
def setUp(self):
|
|
config = get_config(is_test=True)
|
|
self.client = MongoClient(
|
|
host=config.get('metrik', 'mongo_host'),
|
|
port=config.getint('metrik', 'mongo_port'))
|
|
self.db = self.client[config.get('metrik', 'mongo_database')]
|
|
|
|
def tearDown(self):
|
|
super(MongoTest, self).tearDown()
|
|
config = get_config(is_test=True)
|
|
self.client.drop_database(config.get('metrik', 'mongo_database'))
|
|
|
|
|
|
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'}) |