Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/bin/sample-client.py
blob: 12c55146fe144a94d4433d0aee1b6941141916e5 (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python
import dbus
import os

def main():
    bus = dbus.SessionBus()
    datastore = bus.get_object("org.laptop.sugar.DataStore",
                               "/org/laptop/sugar/DataStore")

    uid = datastore.create(dict(title="from dbus", author="Benjamin"), os.path.abspath('tests/test.pdf'))
    print "created uid", uid, "with binary content"
    
    datastore.complete_indexing()

    res, count = datastore.find(dict(fulltext="peek"))
    assert count == 1, "failed to index content"
    assert res[0]['uid'] == uid, "returned incorrect results"
    print "found inside binary file :: PDF"
    
    assert datastore.find(dict(fulltext="kfdshaksjd"))[1] == 0
    print "successfully ignored bad searches"
    
    # try the other mimetypes
    datastore.update(uid, dict(title="updated title",
                               mime_type="application/msword"),
                     os.path.abspath('tests/test.doc'))

    datastore.complete_indexing()

    assert datastore.find(dict(fulltext="inside"))[0][0]['uid'] == uid
    print "found in binary file :: WORD"
    
    datastore.update(uid, dict(title="another updated title",
                               mime_type="application/vnd.oasis.opendocument.text"),
                     os.path.abspath('tests/test.odt'))
    datastore.complete_indexing()
    
    assert datastore.find(dict(fulltext="amazed"))[0][0]['uid'] == uid
    print "found in binary file :: ODT"

    datastore.get_properties(uid)

    assert datastore.find(dict(title="another"))[0][0]['uid'] == uid
    print "found title using dict params", 

    assert datastore.find("another")[0][0]['uid'] == uid
    print "found title in search of all fields (as text)"


    assert datastore.find('title:"another"')[0][0]['uid'] == uid
    print "field in query  field:'value' "

    datastore.delete(uid)
    datastore.complete_indexing()

    print "deleted", uid
    try: datastore.get_properties(uid)
    except: pass
    else:
        print "Found deleted value... oops"
        raise  KeyError(uid)


    uid2 = datastore.create(dict(title="cows",
                          mime_type="application/vnd.oasis.opendocument.text"),
                          os.path.abspath('tests/funkyabi.odt'))

    datastore.complete_indexing()
    
    assert datastore.find(dict(fulltext="vaca"))[0][0]['uid'] == uid2
    print "found in binary file :: ODT"

    datastore.delete(uid2)
    datastore.complete_indexing()

    print "ALL GOOD"
    
if __name__ == '__main__':
    #from ore.main import Application
    #a = Application("client", main)
    #a.plugins.append('ore.main.profile_support.ProfileSupport')
    #a()
    main()