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 09:48:12 (GMT)
committer Benjamin Saller <bcsaller@objectrealms.net>2007-06-25 09:48:12 (GMT)
commit594a13dcb0d81192104fccbbdb3fd9b331fc9af1 (patch)
tree1f1fef6cf8251b55b2bf0a58fa3240c1a8286995 /tests
parent8d86b994df8e66b4589b4d20796d4343ca7dd185 (diff)
I can't believe this wasn't pushed
Diffstat (limited to 'tests')
-rw-r--r--tests/milestone_2.txt37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/milestone_2.txt b/tests/milestone_2.txt
new file mode 100644
index 0000000..516d497
--- /dev/null
+++ b/tests/milestone_2.txt
@@ -0,0 +1,37 @@
+Once the datastore is running its important to be able to sort the
+results along the lines of various criteria. Lets create a sample
+datastore.
+
+First clean up from any other tests.
+>>> 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")
+
+>>> a = ds.create(dict(title="Content A", author="Bob", year=1999, month="Jan"), '')
+>>> b = ds.create(dict(title="Content B", author="Alice", year=2000, month="Jan"), '')
+
+Find should return both
+>>> def find2uids(results): return [i['uid'] for i in results[0]]
+>>> assert set(find2uids(ds.find({}))) == set([a,b])
+
+
+But what if we want the results ordered?
+>>> assert find2uids(ds.find(order_by=['title'])) == [a, b]
+>>> assert find2uids(ds.find(order_by=['author'])) == [b, a]
+
+By more than one key?
+
+>>> assert find2uids(ds.find(order_by=['month', 'year'])) == [a, b]
+
+and if we want to reverse order it?
+
+>>> assert find2uids(ds.find(order_by=['-title'])) == [b, a]
+>>> assert find2uids(ds.find(order_by=['-author'])) == [a, b]
+
+>>> ds.stop()
+>>> del ds