Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tests/test_backingstore.py
blob: 41382193553dd60ba545cb263730626f3e365d6a (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
import unittest
from testutils import tmpData

from olpc.datastore import backingstore
import os

DEFAULT_STORE = '/tmp/_bs_test'

class Test(unittest.TestCase):
    def setUp(self):
        if os.path.exists(DEFAULT_STORE):
            os.system("rm -rf %s" % DEFAULT_STORE)

    def tearDown(self):
        if os.path.exists(DEFAULT_STORE):
            os.system("rm -rf %s" % DEFAULT_STORE)
            
    def test_fsstore(self):
        bs = backingstore.FileBackingStore(DEFAULT_STORE)
        bs.initialize_and_load()
        bs.create_descriptor()
        desc = bs.descriptor()
        assert 'id' in desc
        assert 'uri' in desc
        assert 'title' in desc
        assert desc['title'] is not None

        d = """This is a test"""
        d2 = "Different"
        
        uid = bs.create(dict(title="A"), tmpData(d))

        bs.complete_indexing()
        
        obj = bs.get(uid)

        assert obj.get_property('title') == "A"
        got = obj.file.read()
        assert got == d

        bs.update(uid, dict(title="B"), tmpData(d2))

        bs.complete_indexing()
        
        obj = bs.get(uid)
        assert obj.get_property('title') == "B"
        got = obj.file.read()
        assert got == d2

        bs.delete(uid)
        bs.complete_indexing()
        self.failUnlessRaises(KeyError, bs.get, uid)
        
def test_suite():
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(Test))
    return suite

if __name__ == "__main__":
    unittest.main()