Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tests/milestone_2.txt
blob: 73fd43a2a85cd79885b4c1a983ac018265b923df (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
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, model
>>> ds = DataStore()
>>> ds.registerBackend(backingstore.FileBackingStore)
>>> dm = model.defaultModel.copy().addField('year', 'int').addField('month', 'string')

>>> assert ds.mount("/tmp/test_ds", {'indexmanager.model' : dm})

>>> 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]]

>>> ds.complete_indexing()

>>> 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
>>> assert os.system('rm -rf /tmp/test_ds/') == 0