blob: 145f5d89a1c0d78e952fefbeddce987a0824c491 (
plain)
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
|
import unittest
from testutils import tmpData
from olpc.datastore import DataStore
from olpc.datastore import model, backingstore
import datetime
import os
DEFAULT_STORE = '/tmp/test_ds'
class Test(unittest.TestCase):
def setUp(self): os.system('rm -rf %s' % DEFAULT_STORE)
def tearDown(self): os.system('rm -rf %s' % DEFAULT_STORE)
def test_dateproperty(self):
n = datetime.datetime.now()
# we have to kill the microseconds as
# time.strptime which we must use in 2.4 doesn't parse it
n = n.replace(microsecond=0)
p = model.Property('ctime', n.isoformat(), 'date')
assert p.key == "ctime"
assert p.value == n.isoformat()
p.value = p.value
assert p.value == n.isoformat()
def test_binaryproperty(self):
ds = DataStore()
ds.registerBackend(backingstore.FileBackingStore)
#add a custom field to the model
dm = model.defaultModel.copy().addField('thumbnail', 'binary')
ds.mount(DEFAULT_STORE, {'indexmanager.model' : dm})
n = datetime.datetime.now()
data = open('test.jpg', 'r').read()
# binary data with \0's in it can cause dbus errors here
fn = tmpData("with image\0\0 prop")
# The key types are looked up in the model now
uid = ds.create({'title' : "Document 1", 'thumbnail' : data, 'ctime' : n.isoformat()}, fn)
ds.complete_indexing()
c = ds.get(uid)
assert c.get_property('thumbnail') == data
# I don't care about the microsecond issue now, the typelib
# patch later can fix that
assert c.get_property('ctime')[:19] == n.isoformat()[:19]
ds.stop()
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(Test))
return suite
if __name__ == "__main__":
unittest.main()
|