Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tests/simple_versions.txt
blob: 9bf61d34e33d1901407542d9c623ea31ab4c6a7f (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
The Datastore supports versioning of content objects and
metadata. Inorder to support this we introduce new API calls and a
higher level set of semantic operations around versioning.

Let's create a simple datastore and add some content.

>>> import os
>>> assert os.system('rm -rf /tmp/store1/') == 0

>>> from olpc.datastore import DataStore
>>> from olpc.datastore import backingstore
>>> from testutils import *

>>> ds = DataStore()
>>> ds.registerBackend(backingstore.FileBackingStore)
>>> mp1 = ds.mount("/tmp/store1", dict(title="Primary Storage"))


The checkin operation will create new content or update existing
content and increment the version all in a single operation. It takes
the arguments of a properties dictionary and an optional filename of
the content to store with this revision.

>>> fn = tmpData("Part 1 -- it begins")
>>> uid, vid = ds.checkin({'title' : 'A day in the life'}, fn)

This operation returns the uid of the object and its current version
id. 

From the datastore we can now verify that this object exists and is
indexed. To ensure this for testing we first allow the indexer to
complete all its pending operations

>>> ds.complete_indexing()

>>> results, count = ds.find("A day")
>>> assert count == 1
>>> assert results[0]['uid'] == uid

We can also search on its content directly.

>>> results, count = ds.find("Part 1")
>>> assert count == 1
>>> assert results[0]['uid'] == uid


To get a copy of this file out that we can manipulate we can use the
checkout command. By default checkout will check out the HEAD revsion
(the most recent) of a document. It returns the properties dictionary
and the filename of the checkout which is ours to manipulate.

>>> props, fn = ds.checkout(uid)

>>> assert props['title'] == "A day in the life"
>>> assert props['vid'] == vid

>>> contents = open(fn, 'r').read()
>>> assert contents.startswith("Part 1")

Lets make a revision to this content.

>>> fn2 = tmpData("Part Two -- the second helping")

We are going to check in the new file using the props dict of the last
call after making our modifications and supplying our new file.

(note that we changed the case of 'life' here)

>>> props['title'] = "A day in the Life" 
>>> ds.checkin(props, fn2)
>>> ds.complete_indexing()


Verify that the contents of the old version isn't returned in the
search. By default old versions are not included.

>>> r, c = ds.find("begins"))
>>> assert c == 0

Verify that the HEAD revision of the content is searchable by default.

>>> r, c = ds.find("second")
>>> assert c == 1
>>> assert r[0]['uid'] == uid

Lets check out the head version of this document now.

>>> props, rev2 = ds.checkout(uid)

Check that the id is the same and the version id isn't.

>>> assert props['id'] == uid
>>> assert props['vid'] != vid

Verify the contents of the file is as expected.

>>> contents = open(rev2, 'r').read()
>>> assert contents.startswith("Part Two")



>>> ds.stop(); del ds