Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/bin/test-inplace.py
blob: 2d0b1af5149236d1c9aabd629fde257f682e6b7e (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/python

import dbus
import dbus.glib
import os
import time

import tempfile

def tmpData(data):
    """Put data into a temporary file returning the filename """
    fd, fn = tempfile.mkstemp()
    os.write(fd, data)
    os.close(fd)
    return fn



DS_DBUS_SERVICE = "org.laptop.sugar.DataStore"
DS_DBUS_INTERFACE = "org.laptop.sugar.DataStore"
DS_DBUS_PATH = "/org/laptop/sugar/DataStore"


# clean up any old tests
assert os.system('rm -rf /tmp/store1') == 0

_bus = dbus.SessionBus()
_data_store = dbus.Interface(_bus.get_object(DS_DBUS_SERVICE, DS_DBUS_PATH), DS_DBUS_INTERFACE)

mount_id = _data_store.mount('inplace:/tmp/store1', dict(title='pen drive'))

props = {'activity_id': dbus.String(u'461c7467f9ef6478b205a687579843fc36a98e7a'),
         'title_set_by_user': '0', 
         'ctime': '2007-07-28T11:57:57.909689',
         'title': 'Google News',
         'mtime': '2007-07-28T11:58:22.460331',
         'keep': '0',
         'icon-color': '#00EA11,#00588C',
         'activity': 'org.laptop.WebActivity',
         'mime_type': 'text/plain'}

jsonData = '''{"history":[{"url":"http://www.google.com/","title":"Google"},
              {"url":"http://news.google.com/nwshp?tab=wn","title":"Google News"}]}'''

uid = _data_store.create(props, '')
file_name = os.path.join('/tmp', str(time.time()))
fn = tmpData(jsonData)

_data_store.update(uid, props, fn)




props = _data_store.get_properties(uid)
file_name = _data_store.get_filename(uid)
props['mountpoint'] = mount_id
# suggest a filename
props['filename'] = "history.json"
uid2 = _data_store.create(props, file_name)

# the file name related to the new copy.
fn2 = _data_store.get_filename(uid2)

assert fn2

contents = open(fn2, 'r').read()
assert contents == jsonData

# Now unmount the store, remount it and read the file

_data_store.unmount(mount_id)


mount_id = _data_store.mount('inplace:/tmp/store1', dict(title='pen drive'))

fn2 = _data_store.get_filename(uid2)

assert fn2

contents = open(fn2, 'r').read()
assert contents == jsonData

print "ALL GOOD"

print "Trying with Abidoc"

props = {'mountpoint' : mount_id,
         'title' : 'Abidoc',

         }

uid = _data_store.create(props, '')
# now update it with the document
fn = os.path.abspath("tests/test.odt")
abidoc = open(fn, 'r').read()


props['filename'] =  'test.odt'
_data_store.update(uid, props, fn)

fn2 = _data_store.get_filename(uid)

contents = open(fn2, 'r').read()
assert contents == abidoc

print "Abiword ok"