Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tests/sugar_demo_may17.txt
blob: 64d49e509d13182b464120831ee18e8800a0d12e (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
66
67
68
69
70
71
72
How Sugar will interact with the DS for the May 17th demo in Argentina:

>>> from olpc.datastore import DataStore
>>> from olpc.datastore import backingstore
>>> ds = DataStore()
>>> ds.registerBackend(backingstore.FileBackingStore)
>>> assert ds.mount("/tmp/test_ds")


Create an entry without data:
>>> uid = ds.create(dict(title="New entry"), '')
>>> ds.complete_indexing()

>>> ds.get_filename(uid)
''

Update an entry without data:
>>> ds.update(uid, dict(title="New entry still without content"), '')

>>> ds.complete_indexing()

>>> ds.get_filename(uid)
''

Add some data to the same entry:
>>> fp = open('/tmp/sugar_ds_test', 'w')
>>> print >>fp, "some content"
>>> fp.close()
>>> ds.update(uid, dict(title="Same entry now with some content"), fp.name)
>>> ds.complete_indexing()

Retrieve that data:
>>> fn = ds.get_filename(uid)
>>> fp = open(fn, 'r')
>>> fp.read()
'some content\n'
>>> fp.close()

Update again:
>>> fp = open('/tmp/sugar_ds_test2', 'w')
>>> print >>fp, "some other content"
>>> fp.close()
>>> ds.update(uid, dict(title="Same entry with some other content"), fp.name)
>>> ds.complete_indexing()

And retrieve again:
>>> fn = ds.get_filename(uid)
>>> fp = open(fn, 'r')
>>> fp.read()
'some other content\n'
>>> fp.close()

Get all entries (only have one):
>>> results, count = ds.find({})
>>> results[0]['title']
'Same entry with some other content'

Check content:
>>> fn = ds.get_filename(uid)
>>> fp = open(fn, 'r')
>>> fp.read()
'some other content\n'
>>> fp.close()

Set content as pdf:
>>> ds.update(uid, dict(title="Same entry with some content in pdf"), 'test.pdf')
>>> ds.update(uid, dict(title="Same entry with some content in doc"), 'test.doc')
>>> ds.update(uid, dict(title="Same entry with some content in odt"), 'test.odt')
>>> ds.complete_indexing()

>>> ds.stop()
>>> del ds