1
0
mirror of https://github.com/bspeice/metrik synced 2024-11-23 15:48:10 -05:00
metrik/test/targets/test_mongo_target.py

33 lines
822 B
Python
Raw Normal View History

from pymongo import MongoClient
from random import randint
2016-08-19 22:02:19 -04:00
from metrik.targets.mongo import MongoTarget
2016-08-24 16:09:54 -04:00
from metrik.conf import get_config
from test.mongo_test import MongoTest
class MongoTargetTest(MongoTest):
def test_exists(self):
collection = 'test_collection'
id = 1234
t = MongoTarget(collection, id)
assert not t.exists()
t.persist({'a': 'b'})
assert t.exists()
2016-08-24 16:09:54 -04:00
db_collection = self.db[collection]
db_collection.remove(id)
assert not t.exists()
def test_persist_retrieve(self):
collection = 'test_collection'
id = 1234
t = MongoTarget(collection, id)
d = {str(k): randint(0, 9999) for k in range(20)}
t.persist(d)
u = MongoTarget(collection, id)
assert u.retrieve() == d