-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunit_test.py
66 lines (61 loc) · 2.65 KB
/
unit_test.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import os
from metadb_api import MetaDB
print
print "Testing find/insert/find_one/remove basic"
print "=============================================="
mdb = MetaDB()
mdb.database.remove({})
print "Empty after remove.....", mdb.database.find({}) == []
mdb.database.insert({'a':'b'})
mdb.database.insert({'a':'c'})
mdb.database.insert({'a':'d'})
print "After inserting 3 values.....",sorted(mdb.database.find({})) == sorted([{'a':'d'}, {'a':'c'}, {'a':'b'}])
print "Find with filter.....", mdb.database.find({'a':'d'}) == [{'a':'d'}]
print
print "Testing find/insert/find_one/remove advanced"
print "=============================================="
mdb = MetaDB()
mdb.database.remove({})
print "Empty after remove.....",mdb.database.find({})==[]
mdb.database.insert({'a':'b'})
mdb.database.insert({'a':'b'})
mdb.database.insert({'a':'b'})
mdb.database.insert({'a':'b'})
mdb.database.insert({'a':'c'})
mdb.database.insert({'a':'d'})
print "Find with filter replications.....", mdb.database.find({'a':'b'}) == [{'a':'b'},{'a':'b'},{'a':'b'},{'a':'b'},]
mdb.database.remove({'a':'b'})
print "After deleting by felter 4 similar values.....",sorted(mdb.database.find({})) == sorted([{'a':'d'}, {'a':'c'}])
mdb.database.remove({})
print "Empty after remove.....",mdb.database.find({})==[]
print
print "Testing update/find_one"
print "=============================================="
mdb = MetaDB()
mdb.database.remove({})
print "Empty after remove.....", mdb.database.find({}) == []
mdb.database.insert({'a':'b'})
mdb.database.update({'a':'b'},{'a':'b2', 'c':'d'})
print "Find filter with new value.....", mdb.database.find({'a':'b2'}) == [{'a':'b2', 'c':'d'}]
print "Find filter with old value.....", mdb.database.find({'a':'b'}) == []
mdb.database.insert({'a':'b'})
mdb.database.update({'a':'b'},{'a':'b', 'k':'l'})
mdb.database.insert({'a':'b'})
print "After deleting by felter 4 similar values.....",sorted(mdb.database.find({'a':'b'})) == sorted([{'a':'b'}, {'a':'b', 'k':'l'}])
print "find_one_1", mdb.database.find_one({'a':'b'}) == {'a':'b', 'k':'l'}
print "find_one_1", mdb.database.find_one({'k':'l'}) == {'a':'b', 'k':'l'}
print
print "Testing find empty"
print "=============================================="
mdb = MetaDB()
mdb.database.remove({})
print "Empty after remove.....", mdb.database.find({}) == []
print "Empty after remove.....", mdb.database.find_one({'a','b'}) == None
mdb.database.insert({'a':'b'})
mdb.database.insert({'a':'b'})
mdb.database.insert({'a':'b'})
mdb.database.insert({'a':'b'})
mdb.database.insert({'a':'c'})
mdb.database.insert({'a':'d'})
mdb.database.update({}, {'a2':'d2'}, upsert=True)
print "Find update all.....", mdb.database.find({}), mdb.database.find({}) == [{'a2':'d2'}]