Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tests/test_model.py
blob: 87ed94f63f8a33518c64815750fe98a8ef3e2b4c (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
64
65
import unittest
from testutils import tmpData, waitforindex

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"
        # XXX: the 'date()' is a work around for a missing secore
        # feature right now
        assert p.value == n.date().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")
        # XXX: We should be able to remove:binary now
        uid = ds.create({'title' : "Document 1", 'thumbnail:binary' :
        data, 'ctime:date' : n.isoformat()}, fn)
        
        waitforindex(ds)

        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()