Download this file

test_datastore.py    39 lines (30 with data), 1.2 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from unittest import TestCase, main
import ming
from ming import Session, Field, Document
from ming import datastore as DS
from ming import schema as S
class TestDatastore(TestCase):
def setUp(self):
class TestDoc(Document):
class __mongometa__:
name='test_doc'
session = Session.by_name('main')
_id=Field(S.ObjectId, if_missing=None)
a=Field(S.Int, if_missing=None)
b=Field(S.Object, dict(a=S.Int(if_missing=None)))
config = {
'ming.main.master':'mongo://localhost:27017/test_db' }
ming.configure(**config)
self.session = TestDoc.__mongometa__.session
def test_basic(self):
self.assert_(repr(self.session.bind), 'DataStore(master=[{')
self.session.bind.conn
def test_master_slave(self):
ms = DS.DataStore(master='mongo://localhost:23/test_db',
slave='mongo://localhost:27017/test_db')
ms.conn # should failover to slave-only
ms.db
ms_fail = DS.DataStore(master='mongo://localhost:23/test_db')
self.assert_(ms_fail.conn is None)
if __name__ == '__main__':
main()