~ubuntu-branches/ubuntu/saucy/telepathy-mission-control-5/saucy

« back to all changes in this revision

Viewing changes to tests/twisted/account-manager/avatar.py

  • Committer: Package Import Robot
  • Author(s): Robert Ancell
  • Date: 2013-01-10 11:07:51 UTC
  • mfrom: (0.13.5)
  • Revision ID: package-import@ubuntu.com-20130110110751-fzge1h4wgrwqu1zi
Tags: 1:5.14.0-0ubuntu1
* New upstream release
* debian/control:
  - Use standards version 3.9.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17
17
# 02110-1301 USA
18
18
 
19
 
import dbus
 
19
import os
 
20
 
20
21
import dbus
21
22
import dbus.service
22
23
 
33
34
    account_iface = dbus.Interface(account, cs.ACCOUNT)
34
35
    account_props = dbus.Interface(account, cs.PROPERTIES_IFACE)
35
36
 
 
37
    assertEquals(cs.ACCOUNT_PATH_PREFIX,
 
38
            account.object_path[:len(cs.ACCOUNT_PATH_PREFIX)])
 
39
    avatar_filename = account.object_path[len(cs.ACCOUNT_PATH_PREFIX):]
 
40
    avatar_filename = avatar_filename.replace('/', '-') + '.avatar'
 
41
    avatar_filename = (os.environ['XDG_DATA_HOME'] +
 
42
        '/telepathy/mission-control/' + avatar_filename)
 
43
 
36
44
    call_async(q, account_props, 'Set', cs.ACCOUNT_IFACE_AVATAR, 'Avatar',
37
45
            dbus.Struct((dbus.ByteArray('AAAA'), 'image/jpeg')))
38
46
    q.expect_many(
46
54
    assert account_props.Get(cs.ACCOUNT_IFACE_AVATAR, 'Avatar',
47
55
            byte_arrays=True) == ('AAAA', 'image/jpeg')
48
56
 
 
57
    assertEquals('AAAA', ''.join(open(avatar_filename, 'r').readlines()))
 
58
    # We aren't storing in the old location
 
59
    assert not os.path.exists(os.environ['MC_ACCOUNT_DIR'] + '/fakecm')
 
60
 
49
61
    # OK, let's go online. The avatar is set regardless of the CM
50
62
    conn, e = enable_fakecm_account(q, bus, mc, account, params,
51
63
            has_avatars=True, avatars_persist=True,
72
84
    assert account_props.Get(cs.ACCOUNT_IFACE_AVATAR, 'Avatar',
73
85
            byte_arrays=True) == ('BBBB', 'image/png')
74
86
 
 
87
    assertEquals('BBBB', ''.join(open(avatar_filename, 'r').readlines()))
 
88
    assert not os.path.exists(os.environ['MC_ACCOUNT_DIR'] + '/fakecm')
 
89
 
75
90
    someone_else = conn.ensure_handle(cs.HT_CONTACT, 'alberto@example.com')
76
91
 
77
92
    # Another contact changes their avatar: ignored
97
112
    assert account_props.Get(cs.ACCOUNT_IFACE_AVATAR, 'Avatar',
98
113
            byte_arrays=True) == ('CCCC', 'image/svg')
99
114
 
 
115
    assertEquals('CCCC', ''.join(open(avatar_filename, 'r').readlines()))
 
116
 
100
117
    # empty avatar tests
101
118
    conn.forget_avatar()
102
119
    q.dbus_emit(conn.object_path, cs.CONN_IFACE_AVATARS, 'AvatarUpdated',
108
125
    assertEquals(account_props.Get(cs.ACCOUNT_IFACE_AVATAR, 'Avatar',
109
126
                                   byte_arrays=False), ([], ''))
110
127
 
 
128
    # empty avatars are represented by an empty file, not no file,
 
129
    # to get the right precedence over XDG_DATA_DIRS
 
130
    assertEquals('', ''.join(open(avatar_filename, 'r').readlines()))
 
131
 
111
132
if __name__ == '__main__':
112
133
    exec_test(test, {})