[telepathy-mission-control/master] Add a regression test for accounts that "want to connect" doing so when they become valid
Simon McVittie
simon.mcvittie at collabora.co.uk
Thu Jun 25 07:52:12 PDT 2009
---
test/twisted/Makefile.am | 1 +
test/twisted/account-manager/make-valid.py | 182 ++++++++++++++++++++++++++++
2 files changed, 183 insertions(+), 0 deletions(-)
create mode 100644 test/twisted/account-manager/make-valid.py
diff --git a/test/twisted/Makefile.am b/test/twisted/Makefile.am
index 4997b58..4043b21 100644
--- a/test/twisted/Makefile.am
+++ b/test/twisted/Makefile.am
@@ -49,6 +49,7 @@ TWISTED_SEPARATE_TESTS = \
account-manager/auto-connect.py \
account-manager/avatar-persist.py \
account-manager/avatar-refresh.py \
+ account-manager/make-valid.py \
crash-recovery/crash-recovery.py \
dispatcher/create-at-startup.py
diff --git a/test/twisted/account-manager/make-valid.py b/test/twisted/account-manager/make-valid.py
new file mode 100644
index 0000000..94c3242
--- /dev/null
+++ b/test/twisted/account-manager/make-valid.py
@@ -0,0 +1,182 @@
+"""Feature test for accounts becoming valid.
+"""
+
+import os
+
+import dbus
+import dbus.service
+
+from servicetest import EventPattern, tp_name_prefix, tp_path_prefix, \
+ call_async, sync_dbus
+from mctest import exec_test, SimulatedConnection, create_fakecm_account, \
+ make_mc
+import constants as cs
+
+cm_name_ref = dbus.service.BusName(
+ cs.tp_name_prefix + '.ConnectionManager.fakecm', bus=dbus.SessionBus())
+
+account1_id = 'fakecm/fakeprotocol/jc_2edenton_40unatco_2eint'
+account2_id = 'fakecm/fakeprotocol/jc_2edenton_40example_2ecom'
+
+def preseed():
+
+ accounts_dir = os.environ['MC_ACCOUNT_DIR']
+
+ # The passwords are missing, so the accounts can't connect yet.
+ accounts_cfg = open(accounts_dir + '/accounts.cfg', 'w')
+ accounts_cfg.write("""# Telepathy accounts
+[%s]
+manager=fakecm
+protocol=fakeprotocol
+DisplayName=Work account
+NormalizedName=jc.denton at unatco.int
+param-account=jc.denton at unatco.int
+Enabled=1
+ConnectAutomatically=1
+AutomaticPresenceType=2
+AutomaticPresenceStatus=available
+AutomaticPresenceMessage=My vision is augmented
+Nickname=JC
+AvatarMime=image/jpeg
+
+[%s]
+manager=fakecm
+protocol=fakeprotocol
+DisplayName=Personal account
+NormalizedName=jc.denton at example.com
+param-account=jc.denton at example.com
+Enabled=1
+ConnectAutomatically=0
+AutomaticPresenceType=2
+AutomaticPresenceStatus=available
+AutomaticPresenceMessage=My vision is augmented
+Nickname=JC
+AvatarMime=image/jpeg
+""" % (account1_id, account2_id))
+ accounts_cfg.close()
+
+ os.makedirs(accounts_dir + '/' + account1_id)
+ avatar_bin = open(accounts_dir + '/' + account1_id + '/avatar.bin', 'w')
+ avatar_bin.write('Deus Ex')
+ avatar_bin.close()
+
+ os.makedirs(accounts_dir + '/' + account2_id)
+ avatar_bin = open(accounts_dir + '/' + account2_id + '/avatar.bin', 'w')
+ avatar_bin.write('Invisible War')
+ avatar_bin.close()
+
+ account_connections_file = open(accounts_dir + '/.mc_connections', 'w')
+ account_connections_file.write("")
+ account_connections_file.close()
+
+def test(q, bus, unused):
+ # make sure RequestConnection doesn't get called yet
+ events = [EventPattern('dbus-method-call', method='RequestConnection')]
+ q.forbid_events(events)
+
+ # Wait for MC to load
+ mc = make_mc(bus, q.append)
+
+ q.expect_many(
+ EventPattern('dbus-signal', signal='NameOwnerChanged',
+ predicate=lambda e: e.args[0] == cs.AM),
+ EventPattern('dbus-signal', signal='NameOwnerChanged',
+ predicate=lambda e: e.args[0] == cs.CD),
+ )
+
+ # Make account 1 valid: it should connect automatically
+
+ account_path = (cs.tp_path_prefix + '/Account/' + account1_id)
+ account = bus.get_object(cs.MC, account_path)
+
+ sync_dbus(bus, q, mc)
+ q.unforbid_events(events)
+
+ call_async(q, account, 'UpdateParameters', {'password': 'nanotech'}, [],
+ dbus_interface=cs.ACCOUNT)
+
+ expected_params = {'password': 'nanotech',
+ 'account': 'jc.denton at unatco.int'}
+
+ e = q.expect('dbus-method-call', method='RequestConnection',
+ args=['fakeprotocol', expected_params],
+ destination=cs.tp_name_prefix + '.ConnectionManager.fakecm',
+ path=cs.tp_path_prefix + '/ConnectionManager/fakecm',
+ interface=cs.tp_name_prefix + '.ConnectionManager',
+ handled=False)
+
+ conn = SimulatedConnection(q, bus, 'fakecm', 'fakeprotocol', '_',
+ 'myself', has_presence=True)
+
+ q.dbus_return(e.message, conn.bus_name, conn.object_path, signature='so')
+
+ q.expect('dbus-method-call', method='Connect',
+ path=conn.object_path, handled=True, interface=cs.CONN)
+ conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CONN_STATUS_REASON_NONE)
+
+ set_presence = q.expect('dbus-method-call', path=conn.object_path,
+ interface=cs.CONN_IFACE_SIMPLE_PRESENCE, method='SetPresence',
+ handled=True)
+
+ e = q.expect('dbus-signal', signal='AccountPropertyChanged',
+ path=account_path, interface=cs.ACCOUNT,
+ predicate=lambda e: 'CurrentPresence' in e.args[0]
+ and e.args[0]['CurrentPresence'][2] != '')
+
+ assert e.args[0]['CurrentPresence'] == (cs.PRESENCE_TYPE_AVAILABLE,
+ 'available', 'My vision is augmented')
+
+ # Request an online presence on account 2, then make it valid
+
+ q.forbid_events(events)
+
+ account_path = (cs.tp_path_prefix + '/Account/' + account2_id)
+ account = bus.get_object(cs.MC, account_path)
+
+ requested_presence = dbus.Struct((dbus.UInt32(cs.PRESENCE_TYPE_BUSY),
+ 'busy', 'Talking to Illuminati'))
+ account.Set(cs.ACCOUNT, 'RequestedPresence',
+ dbus.Struct(requested_presence, variant_level=1),
+ dbus_interface=cs.PROPERTIES_IFACE)
+
+ sync_dbus(bus, q, mc)
+ q.unforbid_events(events)
+
+ # Make the account valid
+ call_async(q, account, 'UpdateParameters', {'password': 'nanotech'}, [],
+ dbus_interface=cs.ACCOUNT)
+
+ expected_params = {'password': 'nanotech',
+ 'account': 'jc.denton at example.com'}
+
+ e = q.expect('dbus-method-call', method='RequestConnection',
+ args=['fakeprotocol', expected_params],
+ destination=cs.tp_name_prefix + '.ConnectionManager.fakecm',
+ path=cs.tp_path_prefix + '/ConnectionManager/fakecm',
+ interface=cs.tp_name_prefix + '.ConnectionManager',
+ handled=False)
+
+ conn = SimulatedConnection(q, bus, 'fakecm', 'fakeprotocol', '_',
+ 'myself', has_presence=True)
+
+ q.dbus_return(e.message, conn.bus_name, conn.object_path, signature='so')
+
+ q.expect('dbus-method-call', method='Connect',
+ path=conn.object_path, handled=True, interface=cs.CONN)
+ conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CONN_STATUS_REASON_NONE)
+
+ set_presence = q.expect('dbus-method-call', path=conn.object_path,
+ interface=cs.CONN_IFACE_SIMPLE_PRESENCE, method='SetPresence',
+ handled=True)
+
+ e = q.expect('dbus-signal', signal='AccountPropertyChanged',
+ path=account_path, interface=cs.ACCOUNT,
+ predicate=lambda e: 'CurrentPresence' in e.args[0]
+ and e.args[0]['CurrentPresence'][1] == 'busy')
+
+ assert e.args[0]['CurrentPresence'] == (cs.PRESENCE_TYPE_BUSY,
+ 'busy', 'Talking to Illuminati')
+
+if __name__ == '__main__':
+ preseed()
+ exec_test(test, {})
--
1.5.6.5
More information about the telepathy-commits
mailing list