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-06-25 00:33:51 (GMT)
committer Benjamin Saller <bcsaller@objectrealms.net>2007-06-25 00:33:51 (GMT)
commit1d830942cadba3053150727c66de555f371c42a7 (patch)
tree345df75ac46f1ae39d3fa2f02866931e7db1ccdd /tests
parent69c7de7c5fce0ca4fe13ae46aa3372dab9b460f0 (diff)
mount point filtering, high level api and tests
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile2
-rw-r--r--tests/milestone_1.txt3
-rw-r--r--tests/mountpoints.txt79
-rw-r--r--tests/query.txt8
-rw-r--r--tests/runalltests.py3
-rw-r--r--tests/sugar_demo_may17.txt4
6 files changed, 89 insertions, 10 deletions
diff --git a/tests/Makefile b/tests/Makefile
index 53ee0b3..7961b02 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -1,6 +1,6 @@
# howto inherit this properly from above?
# its not an option to configure
-PYTHON=python2.4
+PYTHON=python
all: test
diff --git a/tests/milestone_1.txt b/tests/milestone_1.txt
index 87e627a..bde3720 100644
--- a/tests/milestone_1.txt
+++ b/tests/milestone_1.txt
@@ -17,8 +17,7 @@ First, create and connect the store.
>>> from olpc.datastore import backingstore
>>> ds = DataStore()
>>> ds.registerBackend(backingstore.FileBackingStore)
->>> ds.mount("/tmp/test_ds")
-True
+>>> assert ds.mount("/tmp/test_ds")
Because there is newly created we are going to quickly populate the
datastore with some content.
diff --git a/tests/mountpoints.txt b/tests/mountpoints.txt
new file mode 100644
index 0000000..666f51f
--- /dev/null
+++ b/tests/mountpoints.txt
@@ -0,0 +1,79 @@
+Mountpoints are very much like traditional *NIX filesystem mounts. The
+intention is to allow more than one backingstore (stable storage
+device) to become part of a datastore at runtime. This is done by
+mounting a backingstore on the datastore.
+
+(clean up)
+>>> import os
+>>> assert os.system('rm -rf /tmp/store1/') == 0
+>>> assert os.system('rm -rf /tmp/store2/') == 0
+
+
+>>> from olpc.datastore import DataStore
+>>> from olpc.datastore import backingstore
+>>> from testutils import tmpData
+
+
+Here we create a datastore, and mount a backingstore on tmp. By
+default this will create a new directory in /tmp which will then be
+used for storage.
+
+>>> ds = DataStore()
+>>> ds.registerBackend(backingstore.FileBackingStore)
+>>> mp1 = ds.mount("/tmp/store1", dict(title="Primary Storage"))
+
+This will list all the mount points. It returns a list of dicts with
+the minumum keyset of 'id', 'uri', and 'title'. Title is the Human
+readable name of the mount. 'Id' is the most important property this
+can be used to control the storage target or to filter results.
+
+>>> mps = ds.mounts()
+>>> mountpoint = mps[0]['id']
+
+
+Now lets create some content
+
+>>> u1 = ds.create(dict(title="Document 1"), tmpData("""document one"""))
+>>> u2 = ds.create(dict(title="Document 2"), tmpData("""document two"""))
+
+We can now, if we wish verify which mount point this content came
+from.
+
+
+>>> c1 = ds.get(u1)
+>>> assert c1.backingstore.id == mountpoint
+
+However this interface isn't available over DBus and objects are
+normally located and inspected using the find() method.
+
+>>> c1a = ds.find(dict(title="Document 1"))[0][0]
+>>> assert c1a['mountpoint'] == mountpoint
+
+We can see that the mountpoint property was mapped on the object and
+refers to the proper storage.
+
+Now lets add another mount point.
+
+>>> mp2 = ds.mount("/tmp/store2", dict(title="Secondary Storage"))
+
+Now lets create a new content item.
+>>> u3 = ds.create(dict(title="Document 3", mountpoint=mp2), tmpData("""document three"""))
+
+We explictly passed a mount point here. Lets examine the properties of
+the object and verify this.
+>>> c3 = ds.find(dict(title="Document 3"))[0][0]
+>>> assert c3['mountpoint'] == mp2
+
+Now lets filter a find call to only selected mountpoints.
+
+>>> results, count = ds.find(dict(mountpoints=[mp1]))
+>>> assert count == 2
+
+>>> results, count = ds.find(dict(mountpoints=[mp2]))
+>>> assert count == 1
+
+>>> results, count = ds.find({})
+>>> assert count == 3
+
+
+>>> ds.stop(); del ds
diff --git a/tests/query.txt b/tests/query.txt
index e0217a2..151db74 100644
--- a/tests/query.txt
+++ b/tests/query.txt
@@ -38,14 +38,14 @@ Find will now return this object.
We can examine the Properties of this object.
>>> a.properties
-[... <Property title:'New Content' of <Content id:...>>, ...]
+[... <Property title:'New Content' of...>, ...]
This returned a list of all properties on the Content object in which
case we can find the property by enumeration. The other option is
using the get_properties call on Content
>>> a.get_properties(key='title')
-[<Property title:'New Content' of <Content id:...>>]
+[<Property title:'New Content' of ...>]
Using the query manager API we are able to update the
properties. Using this form automatically synchronizes with the
@@ -55,11 +55,11 @@ that this works lets attach another property.
A request for title still returns only the title property.
>>> a.get_properties(key='title')
-[<Property title:'New Content' of <Content id:...>>]
+[<Property title:'New Content' of ...>]
And a request for author works as expected.
>>> a.get_properties(key='author')
-[<Property author:'Benjamin' of <Content id:...>>]
+[<Property author:'Benjamin' of ...>]
>>> qm.update(a, dict(foo='bar'))
>>> set([p.key for p in a.properties]) == set(['title', 'mtime', 'ctime', 'language', 'mime_type', 'author', 'foo'])
diff --git a/tests/runalltests.py b/tests/runalltests.py
index e0a73e3..0c9c9e1 100644
--- a/tests/runalltests.py
+++ b/tests/runalltests.py
@@ -20,7 +20,8 @@ doctests = [
resource_filename(__name__, "query.txt"),
resource_filename(__name__, "milestone_1.txt"),
resource_filename(__name__, "sugar_demo_may17.txt"),
- resource_filename(__name__, "milestone_2.txt")
+ resource_filename(__name__, "milestone_2.txt"),
+ resource_filename(__name__, "mountpoints.txt")
]
diff --git a/tests/sugar_demo_may17.txt b/tests/sugar_demo_may17.txt
index cfeefdf..c899799 100644
--- a/tests/sugar_demo_may17.txt
+++ b/tests/sugar_demo_may17.txt
@@ -4,8 +4,8 @@ How Sugar will interact with the DS for the May 17th demo in Argentina:
>>> from olpc.datastore import backingstore
>>> ds = DataStore()
>>> ds.registerBackend(backingstore.FileBackingStore)
->>> ds.mount("/tmp/test_ds")
-True
+>>> assert ds.mount("/tmp/test_ds")
+
Create an entry without data:
>>> uid = ds.create(dict(title="New entry"), '')