Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBenjamin Saller <bcsaller@objectrealms.net>2007-07-30 16:48:06 (GMT)
committer Benjamin Saller <bcsaller@objectrealms.net>2007-07-30 16:48:06 (GMT)
commitb56dfd73ba5aeae93c9375cf97452e80fbe66e84 (patch)
tree960a4f64a8491e120bccf26e436ad64349e94f81 /tests
parentdfefc1f8623611f5ce2615a62679f349f7428f75 (diff)
wip on versioning
Diffstat (limited to 'tests')
-rw-r--r--tests/runalltests.py2
-rw-r--r--tests/simple_versions.txt107
-rw-r--r--tests/testutils.py10
3 files changed, 118 insertions, 1 deletions
diff --git a/tests/runalltests.py b/tests/runalltests.py
index 8fee87e..a152156 100644
--- a/tests/runalltests.py
+++ b/tests/runalltests.py
@@ -27,7 +27,7 @@ doctests = [
resource_filename(__name__, "mountpoints.txt"),
resource_filename(__name__, "properties.txt"),
resource_filename(__name__, "dateranges.txt"),
-
+ resource_filename(__name__, "simple_versions.txt"),
]
doctest_options = doctest.ELLIPSIS
diff --git a/tests/simple_versions.txt b/tests/simple_versions.txt
new file mode 100644
index 0000000..9bf61d3
--- /dev/null
+++ b/tests/simple_versions.txt
@@ -0,0 +1,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
+
+
+
+
+
diff --git a/tests/testutils.py b/tests/testutils.py
index fc667db..e81b22c 100644
--- a/tests/testutils.py
+++ b/tests/testutils.py
@@ -8,3 +8,13 @@ def tmpData(data):
os.close(fd)
return fn
+# Search result set handlers
+def expect(r, count=None):
+ if count: assert r[1] == count
+ return list(r[0])
+def expect_single(r):
+ assert r[1] == 1
+ return r[0].next()
+def expect_none(r):
+ assert r[1] == 0
+ assert list(r[0]) == []