mirror of
https://github.com/bspeice/metrik
synced 2025-07-01 05:46:22 -04:00
Guard against improper drops
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)
This commit is contained in:
@ -7,7 +7,7 @@ from metrik.targets.mongo import MongoTarget
|
||||
|
||||
class MongoTest(TestCase):
|
||||
def setUp(self):
|
||||
config = get_config()
|
||||
config = get_config(is_test=True)
|
||||
self.client = MongoClient(
|
||||
host=config.get('metrik', 'mongo_host'),
|
||||
port=config.getint('metrik', 'mongo_port'))
|
||||
@ -15,7 +15,7 @@ class MongoTest(TestCase):
|
||||
|
||||
def tearDown(self):
|
||||
super(MongoTest, self).tearDown()
|
||||
config = get_config()
|
||||
config = get_config(is_test=True)
|
||||
self.client.drop_database(config.get('metrik', 'mongo_database'))
|
||||
|
||||
|
||||
|
@ -7,4 +7,14 @@ class ConfigurationTest(TestCase):
|
||||
|
||||
def test_config_returns_values(self):
|
||||
config = get_config([])
|
||||
assert config is not None
|
||||
assert config is not None
|
||||
|
||||
def test_config_manual_test_instruction(self):
|
||||
config = get_config()
|
||||
self.assertEqual(config.get('metrik', 'mongo_database'), 'metrik')
|
||||
|
||||
config = get_config(is_test=False)
|
||||
self.assertEqual(config.get('metrik', 'mongo_database'), 'metrik')
|
||||
|
||||
config = get_config(is_test=True)
|
||||
self.assertEqual(config.get('metrik', 'mongo_database'), 'metrik-test')
|
@ -33,3 +33,14 @@ class MergeTest(MongoTest):
|
||||
assert item_retrieved is not None
|
||||
assert item_retrieved['string'] == item_string
|
||||
|
||||
def test_merge_is_nondestructive(self):
|
||||
item1_id = self.db2[self.collection_name].save({})
|
||||
item2_id = self.db[self.collection_name].save({})
|
||||
|
||||
assert len(list(self.db[self.collection_name].find())) == 1
|
||||
assert len(list(self.db2[self.collection_name].find())) == 1
|
||||
|
||||
merge(self.client, self.client,
|
||||
self.db.name, self.db2.name)
|
||||
assert len(list(self.db[self.collection_name].find())) == 0
|
||||
assert len(list(self.db2[self.collection_name].find())) == 2
|
Reference in New Issue
Block a user