Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tests/properties.txt
blob: 6c3c91bf7ba2429c97d0ba29b1f22f53b2064e7d (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
44
45
46
47
This document shows off the range of features available for attaching
properties to content and managing them.

(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, model
>>> from testutils import tmpData
>>> import dbus

Set up two mount points.

>>> ds = DataStore()
>>> ds.registerBackend(backingstore.FileBackingStore)

Extend the model to retain a 'year' property used below.

Mount a couple of stores.

>>> mp1 = ds.mount("/tmp/store1", {'title' : "Primary Storage",})
>>> mp2 = ds.mount("/tmp/store2", {'title' : "Secondary Storage"})

Create some content on each.

>>> u1 = ds.create({'title' : "Alpha doc", 'author' : "Ben", 'year:int' : 2000}, tmpData("""Document 1"""))
>>> u2 = ds.create({'title' : "Beta doc", 'author' : "Ben", 'year:int' : 2001} , tmpData("""Document 2""")) 

>>> u3 = ds.create({'title' : "Delta doc", 'author' :"HAL", 'year:int' : 2000, 'mountpoint' : mp2}, tmpData("""Document 3"""))
>>> u4 = ds.create({'title' : "Gamma doc", 'author' : "HAL", 'year:int' : 2001, 'mountpoint' : mp2}, tmpData("""Document 4""")) 

Now we should be able to discover things about the system properties.
>>> ds.complete_indexing()

Here we test that we can extract the unique values for certain properties.
>>> assert set(ds.get_uniquevaluesfor('author')) == set(['Ben', 'HAL'])

Here we try to gather the values for the property year.

>>> assert set(ds.get_uniquevaluesfor('year')) == set([2000, 2001]) 



>>> ds.stop(); del ds