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-08-16 07:32:18 (GMT)
committer Benjamin Saller <bcsaller@objectrealms.net>2007-08-16 07:32:18 (GMT)
commit993b69294686830639299a62b844e2e9319b54b8 (patch)
tree9c9200600eab03e813fd5f8632b73dbf1263cc81 /tests
parent1c11e80f7d7ad68d62a29452fa71571ed838c6e9 (diff)
wip
Diffstat (limited to 'tests')
-rw-r--r--tests/mountpoints.txt5
-rw-r--r--tests/simple_versions.txt20
-rw-r--r--tests/test_hgrepo.py114
-rw-r--r--tests/testutils.py8
-rw-r--r--tests/xapianindex.txt2
5 files changed, 136 insertions, 13 deletions
diff --git a/tests/mountpoints.txt b/tests/mountpoints.txt
index 45a359a..0f736be 100644
--- a/tests/mountpoints.txt
+++ b/tests/mountpoints.txt
@@ -147,12 +147,13 @@ primary store.
>>> props['mountpoint'] = mountpoint
>>> fn = ds.get_filename(uid)
+>>> del props['uid']
>>> copyuid = ds.create(props, fn)
>>> ds.complete_indexing()
->>> result, count = ds.find(dict(fulltext="four"))
+>>> result, count = ds.find(dict(query="four"))
>>> assert count == 2
We also need to test that we can copy from a normal store to an
@@ -177,7 +178,7 @@ We also need to be sure that delete commands work on inplace
mounts. We will delete the object from the datastore and then verify
that the file is missing.
->>> ds.delete(pen_copy)
+>>> ds.delete(pen_copy, mountpoint=mp3)
>>> ds.complete_indexing()
>>> os.path.exists('/tmp/store3/one.txt')
diff --git a/tests/simple_versions.txt b/tests/simple_versions.txt
index 9bf61d3..9be62bd 100644
--- a/tests/simple_versions.txt
+++ b/tests/simple_versions.txt
@@ -9,11 +9,12 @@ Let's create a simple datastore and add some content.
>>> from olpc.datastore import DataStore
>>> from olpc.datastore import backingstore
+>>> from olpc.datastore import hg_backingstore
>>> from testutils import *
>>> ds = DataStore()
->>> ds.registerBackend(backingstore.FileBackingStore)
->>> mp1 = ds.mount("/tmp/store1", dict(title="Primary Storage"))
+>>> ds.registerBackend(hg_backingstore.HgBackingStore)
+>>> mp1 = ds.mount("hg:/tmp/store1", dict(title="Primary Storage"))
The checkin operation will create new content or update existing
@@ -48,11 +49,10 @@ 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
+>>> assert props['vid'] == str(vid)
>>> contents = open(fn, 'r').read()
>>> assert contents.startswith("Part 1")
@@ -67,15 +67,14 @@ 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)
+>>> uid, vid = 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.
+Old versions of content are still available.
->>> r, c = ds.find("begins"))
->>> assert c == 0
+>>> r, c = ds.find("begins")
+>>> assert c == 1
Verify that the HEAD revision of the content is searchable by default.
@@ -89,7 +88,7 @@ Lets check out the head version of this document now.
Check that the id is the same and the version id isn't.
->>> assert props['id'] == uid
+>>> assert props['uid'] == uid
>>> assert props['vid'] != vid
Verify the contents of the file is as expected.
@@ -98,7 +97,6 @@ Verify the contents of the file is as expected.
>>> assert contents.startswith("Part Two")
-
>>> ds.stop(); del ds
diff --git a/tests/test_hgrepo.py b/tests/test_hgrepo.py
new file mode 100644
index 0000000..c67c506
--- /dev/null
+++ b/tests/test_hgrepo.py
@@ -0,0 +1,114 @@
+import unittest
+from testutils import blit, tmpData
+
+from olpc.datastore import hg_backingstore
+import os
+
+DEFAULT_STORE = '/tmp/hgtest'
+DATA_1 = '/tmp/data1'
+DATA_2 = '/tmp/data2'
+
+class Test(unittest.TestCase):
+ def setUp(self):
+ os.system("rm -rf %s" % DEFAULT_STORE)
+ os.system("rm -rf %s" % DATA_1)
+ os.system("rm -rf %s" % DATA_2)
+
+ os.makedirs(DATA_1)
+ os.makedirs(DATA_2)
+
+ def tearDown(self):
+ os.system("rm -rf %s" % DEFAULT_STORE)
+ os.system("rm -rf %s" % DATA_1)
+ os.system("rm -rf %s" % DATA_2)
+
+ def test_hgrepo(self):
+ repo = hg_backingstore.FileRepo(DEFAULT_STORE)
+
+ # create a test file in DATA_1
+ TEXT_1= "this is a test"
+ fn1 = blit(TEXT_1, os.path.join(DATA_1, "s1"))
+ # and the version we will use later in DATA_2
+ # we do this to test tracking from different source dirs
+ TEXT_2 = "another test"
+ fn2 = blit(TEXT_2, os.path.join(DATA_2, "s2"))
+
+ # this should add foo to the repo with TEXT_1 data
+ repo.put("foo", fn1, text="initial")
+
+ # now commit fn2 to the same path, will create another
+ # revision
+ # of the existing data
+ repo.put("foo", fn2, text="updated")
+
+ # now verify access to both revisions and their data
+ # we check things out into DATA_1
+ co1 = os.path.join(DATA_1, "co1")
+ co2 = os.path.join(DATA_1, "co2")
+
+ repo.dump("foo", 0, co1)
+ repo.dump("foo", 1, co2)
+
+ assert open(co1, 'r').read() == TEXT_1
+ assert open(co2, 'r').read() == TEXT_2
+
+ def test_hgbs(self):
+ bs = hg_backingstore.HgBackingStore("hg:%s" % 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, rev = bs.checkin(dict(title="A", filename="a.txt"), tmpData(d))
+
+ bs.complete_indexing()
+
+ props, fn = bs.checkout(uid)
+
+ assert props.get('title') == "A"
+ got = open(fn, 'r').read()
+ assert got == d
+
+ uid, rev = bs.checkin(dict(uid=uid, title="B"), tmpData(d2))
+
+ bs.complete_indexing()
+
+ props, fn = bs.checkout(uid)
+ assert props.get('title') == "B"
+ got = open(fn, 'r').read()
+ assert got == d2
+
+ # go back and check out the first version
+ props, fn = bs.checkout(uid, 1)
+ assert props.get('title') == "A"
+ got = open(fn, 'r').read()
+ assert got == d
+
+ bs.delete(uid, props['vid'])
+ bs.complete_indexing()
+
+ # There is no more revision 2
+ self.failUnlessRaises(KeyError, bs.get, uid, 1)
+
+## props, fn = bs.checkout(uid)
+
+## import pdb;pdb.set_trace()
+## assert props.get('title') == "A"
+## got = open(fn, 'r').read()
+## assert got == d
+
+
+def test_suite():
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(Test))
+ return suite
+
+if __name__ == "__main__":
+ unittest.main()
+
diff --git a/tests/testutils.py b/tests/testutils.py
index e81b22c..2f3e7ff 100644
--- a/tests/testutils.py
+++ b/tests/testutils.py
@@ -8,6 +8,14 @@ def tmpData(data):
os.close(fd)
return fn
+def blit(data, path=None):
+ if not path: return tmpData(data)
+ fp = open(path, 'w')
+ fp.write(data)
+ fp.close()
+ return path
+
+
# Search result set handlers
def expect(r, count=None):
if count: assert r[1] == count
diff --git a/tests/xapianindex.txt b/tests/xapianindex.txt
index 22aa05d..b28ac90 100644
--- a/tests/xapianindex.txt
+++ b/tests/xapianindex.txt
@@ -81,6 +81,8 @@ But an OR query for missing values still return nothing.
... 'audio/ogg'])))
+Partial search...
+>>> assert expect_single(im.search(r'''pee*''')).id == uid