Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tests/milestone_1.txt
blob: 35e8fb6017215859bc74e50872699c3903591be1 (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
The initial requirements are as follows:

* Get the unique ids of all the objects in the store.
* Get an object from the store given his uid.
* Get the object metadata.
* Get the object file.
* Push the changes made to the file back to the store.
* Update the metadata of an object.

Below I enumerate each point showing how this is performed on a local
datastore.


First, create and connect the store.
>>> import os
>>> assert os.system('rm -rf /tmp/test_ds') == 0


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

Because there is newly created we are going to quickly populate the
datastore with some content.

>>> from testutils import tmpData

>>> assert ds.create(dict(title="Document 1"), tmpData("""this is the first document"""))
>>> assert ds.create(dict(title="Document 2"), tmpData("""this is the second document"""))

We can also create an object w/o any associated file data
>>> assert ds.create(dict(title="Web Session", url="http://google.com"))

Note that we retain no reference to the created documents. 

Now we should be able to test the first requirement.
* Get the unique ids of all the objects in the store.

>>> ds.complete_indexing()

>>> results, count = ds.find()

A find command with out any parameters will return everything in the store.

* Get an object from the store given its uid.

Here we manually cycle through the results looking for the title we
want.
>>> for item in results:
...     if item['title'] == 'Document 1':
...           first_uid = item['uid']
...           break
>>> c1 = ds.get(first_uid)

* Get the object metadata.
>>> c1.properties
{...}

* Get the object file.
>>> c1.filename
'/tmp/...'

>>> c1.contents
'this is the first document'
>>> c1.file
<open file ...>



Now we can modify that file and then 
* Push the changes made to the file back to the store.
* Update the metadata of an object.

>>> fn = c1.filename
>>> fp = open(fn, 'a')
>>> print >>fp, "more content"
>>> fp.close()
>>> ds.update(first_uid, dict(title="Newish Content"), fn)


We can also remove the file from the repository.
>>> ds.delete(first_uid)

This is the basis of milestone 1.

>>> ds.stop()
>>> assert os.system('rm -rf /tmp/test_ds') == 0