diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2012-09-10 15:57:02 +0100 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2012-09-12 14:24:11 +0100 |
commit | 4efea11d2ed33a92f6ef05a954acfb180083531d (patch) | |
tree | 078d91daa66eac2eff5d807647ace8a5145900b5 | |
parent | d6c23d2fc528b3cff92ec78c706a78cd561a2a9b (diff) | |
download | telepathy-mission-control-4efea11d2ed33a92f6ef05a954acfb180083531d.tar.gz |
Preload accounts via fake accounts service when required
The only tests left using real account storage are the three tests for
specific plugins: default keyfile/keyring, diverted keyfile and
libaccounts.
-rw-r--r-- | tests/twisted/account-manager/auto-connect.py | 48 | ||||
-rw-r--r-- | tests/twisted/account-manager/avatar-persist.py | 47 | ||||
-rw-r--r-- | tests/twisted/account-manager/avatar-refresh.py | 47 | ||||
-rw-r--r-- | tests/twisted/account-manager/make-valid.py | 76 | ||||
-rw-r--r-- | tests/twisted/account-manager/update-parameters.py | 29 | ||||
-rw-r--r-- | tests/twisted/crash-recovery/crash-recovery.py | 38 | ||||
-rw-r--r-- | tests/twisted/dispatcher/create-at-startup.py | 44 |
7 files changed, 166 insertions, 163 deletions
diff --git a/tests/twisted/account-manager/auto-connect.py b/tests/twisted/account-manager/auto-connect.py index a789c03b..d6269835 100644 --- a/tests/twisted/account-manager/auto-connect.py +++ b/tests/twisted/account-manager/auto-connect.py @@ -35,7 +35,7 @@ cm_name_ref = dbus.service.BusName( account_id = 'fakecm/fakeprotocol/jc_2edenton_40unatco_2eint' -def preseed(): +def preseed(q, bus, fake_accounts_service): accounts_dir = os.environ['MC_ACCOUNT_DIR'] @@ -44,28 +44,28 @@ def preseed(): except OSError: pass - accounts_cfg = open(accounts_dir + '/accounts.cfg', 'w') + fake_accounts_service.update_attributes(account_id, changed={ + 'manager': 'fakecm', + 'protocol': 'fakeprotocol', + 'DisplayName': 'Work account', + 'NormalizedName': 'jc.denton@unatco.int', + 'Enabled': True, + 'ConnectAutomatically': True, + 'AutomaticPresenceType': dbus.UInt32(2), + 'AutomaticPresenceStatus': 'available', + 'AutomaticPresenceMessage': 'My vision is augmented', + 'Nickname': 'JC', + 'AvatarMime': 'image/jpeg', + }) # As a regression test for part of fd.o #28557, the password starts and # ends with a double backslash, which is represented in the file as a - # quadruple backslash. - accounts_cfg.write(r"""# Telepathy accounts -[%s] -manager=fakecm -protocol=fakeprotocol -DisplayName=Work account -NormalizedName=jc.denton@unatco.int -param-account=jc.denton@unatco.int -param-password=\\\\ionstorm\\\\ -Enabled=1 -ConnectAutomatically=1 -AutomaticPresenceType=2 -AutomaticPresenceStatus=available -AutomaticPresenceMessage=My vision is augmented -Nickname=JC -AvatarMime=image/jpeg -""" % account_id) - accounts_cfg.close() + # quadruple backslash. We use the untyped-parameters dict in order to + # exercise that. + fake_accounts_service.update_parameters(account_id, untyped={ + 'account': 'jc.denton@unatco.int', + 'password': r'\\\\ionstorm\\\\', + }) os.makedirs(accounts_dir + '/' + account_id) avatar_bin = open(accounts_dir + '/' + account_id + '/avatar.bin', 'w') @@ -76,7 +76,9 @@ AvatarMime=image/jpeg account_connections_file.write("") account_connections_file.close() -def test(q, bus, unused): +def test(q, bus, unused, **kwargs): + fake_accounts_service = kwargs['fake_accounts_service'] + preseed(q, bus, fake_accounts_service) expected_params = { 'account': 'jc.denton@unatco.int', @@ -173,5 +175,5 @@ def test(q, bus, unused): q.dbus_return(set_aliases.message, signature='') if __name__ == '__main__': - preseed() - exec_test(test, {}, preload_mc=False, use_fake_accounts_service=False) + exec_test(test, {}, preload_mc=False, use_fake_accounts_service=True, + pass_kwargs=True) diff --git a/tests/twisted/account-manager/avatar-persist.py b/tests/twisted/account-manager/avatar-persist.py index 12d5b36f..f9c28c76 100644 --- a/tests/twisted/account-manager/avatar-persist.py +++ b/tests/twisted/account-manager/avatar-persist.py @@ -36,7 +36,7 @@ cm_name_ref = dbus.service.BusName( account_id = 'fakecm/fakeprotocol/jc_2edenton_40unatco_2eint' -def preseed(): +def preseed(q, bus, fake_accounts_service): accounts_dir = os.environ['MC_ACCOUNT_DIR'] @@ -45,25 +45,24 @@ def preseed(): except OSError: pass - accounts_cfg = open(accounts_dir + '/accounts.cfg', 'w') - accounts_cfg.write("""# Telepathy accounts -[%s] -manager=fakecm -protocol=fakeprotocol -DisplayName=Work account -NormalizedName=jc.denton@unatco.int -param-account=jc.denton@unatco.int -param-password=ionstorm -Enabled=1 -ConnectAutomatically=1 -AutomaticPresenceType=2 -AutomaticPresenceStatus=available -AutomaticPresenceMessage=My vision is augmented -Nickname=JC -AvatarMime=image/jpeg -avatar_token=Deus Ex -""" % account_id) - accounts_cfg.close() + fake_accounts_service.update_attributes(account_id, changed={ + 'manager': 'fakecm', + 'protocol': 'fakeprotocol', + 'DisplayName': 'Work account', + 'NormalizedName': 'jc.denton@unatco.int', + 'Enabled': True, + 'ConnectAutomatically': True, + 'AutomaticPresenceType': dbus.UInt32(2), + 'AutomaticPresenceStatus': 'available', + 'AutomaticPresenceMessage': 'My vision is augmented', + 'Nickname': 'JC', + 'AvatarMime': 'image/jpeg', + 'avatar_token': 'Deus Ex', + }) + fake_accounts_service.update_parameters(account_id, untyped={ + 'account': 'jc.denton@unatco.int', + 'password': 'ionstorm', + }) datadirs = os.environ['XDG_DATA_DIRS'].split(':') @@ -78,7 +77,9 @@ avatar_token=Deus Ex account_connections_file.write("") account_connections_file.close() -def test(q, bus, unused): +def test(q, bus, unused, **kwargs): + fake_accounts_service = kwargs['fake_accounts_service'] + preseed(q, bus, fake_accounts_service) expected_params = { 'account': 'jc.denton@unatco.int', @@ -181,5 +182,5 @@ def test(q, bus, unused): assertEquals('Deus Ex', ''.join(open(low_prio_filename, 'r').readlines())) if __name__ == '__main__': - preseed() - exec_test(test, {}, preload_mc=False, use_fake_accounts_service=False) + exec_test(test, {}, preload_mc=False, use_fake_accounts_service=True, + pass_kwargs=True) diff --git a/tests/twisted/account-manager/avatar-refresh.py b/tests/twisted/account-manager/avatar-refresh.py index 8e196506..a6cb9e18 100644 --- a/tests/twisted/account-manager/avatar-refresh.py +++ b/tests/twisted/account-manager/avatar-refresh.py @@ -36,7 +36,7 @@ cm_name_ref = dbus.service.BusName( account_id = 'fakecm/fakeprotocol/jc_2edenton_40unatco_2eint' -def preseed(): +def preseed(q, bus, fake_accounts_service): accounts_dir = os.environ['MC_ACCOUNT_DIR'] @@ -45,25 +45,24 @@ def preseed(): except OSError: pass - accounts_cfg = open(accounts_dir + '/accounts.cfg', 'w') - accounts_cfg.write("""# Telepathy accounts -[%s] -manager=fakecm -protocol=fakeprotocol -DisplayName=Work account -NormalizedName=jc.denton@unatco.int -param-account=jc.denton@unatco.int -param-password=ionstorm -Enabled=1 -ConnectAutomatically=1 -AutomaticPresenceType=2 -AutomaticPresenceStatus=available -AutomaticPresenceMessage=My vision is augmented -Nickname=JC -AvatarMime=image/jpeg -avatar_token=Deus Ex -""" % account_id) - accounts_cfg.close() + fake_accounts_service.update_attributes(account_id, changed={ + 'manager': 'fakecm', + 'protocol': 'fakeprotocol', + 'DisplayName': 'Work account', + 'NormalizedName': 'jc.denton@unatco.int', + 'Enabled': True, + 'ConnectAutomatically': True, + 'AutomaticPresenceType': dbus.UInt32(2), + 'AutomaticPresenceStatus': 'available', + 'AutomaticPresenceMessage': 'My vision is augmented', + 'Nickname': 'JC', + 'AvatarMime': 'image/jpeg', + 'avatar_token': 'Deus Ex', + }) + fake_accounts_service.update_parameters(account_id, untyped={ + 'account': 'jc.denton@unatco.int', + 'password': 'ionstorm', + }) os.makedirs(accounts_dir + '/' + account_id) avatar_bin = open(accounts_dir + '/' + account_id + '/avatar.bin', 'w') @@ -74,7 +73,9 @@ avatar_token=Deus Ex account_connections_file.write("") account_connections_file.close() -def test(q, bus, unused): +def test(q, bus, unused, **kwargs): + fake_accounts_service = kwargs['fake_accounts_service'] + preseed(q, bus, fake_accounts_service) expected_params = { 'account': 'jc.denton@unatco.int', @@ -130,5 +131,5 @@ def test(q, bus, unused): assertEquals('Deus Ex', ''.join(open(avatar_filename, 'r').readlines())) if __name__ == '__main__': - preseed() - exec_test(test, {}, preload_mc=False, use_fake_accounts_service=False) + exec_test(test, {}, preload_mc=False, use_fake_accounts_service=True, + pass_kwargs=True) diff --git a/tests/twisted/account-manager/make-valid.py b/tests/twisted/account-manager/make-valid.py index 1dde935a..73f2760e 100644 --- a/tests/twisted/account-manager/make-valid.py +++ b/tests/twisted/account-manager/make-valid.py @@ -36,7 +36,7 @@ cm_name_ref = dbus.service.BusName( account1_id = 'fakecm/fakeprotocol/jc_2edenton_40unatco_2eint' account2_id = 'fakecm/fakeprotocol/jc_2edenton_40example_2ecom' -def preseed(): +def preseed(q, bus, fake_accounts_service): accounts_dir = os.environ['MC_ACCOUNT_DIR'] @@ -45,38 +45,40 @@ def preseed(): except OSError: pass + fake_accounts_service.update_attributes(account1_id, changed={ + 'manager': 'fakecm', + 'protocol': 'fakeprotocol', + 'DisplayName': 'Work account', + 'NormalizedName': 'jc.denton@unatco.int', + 'Enabled': True, + 'ConnectAutomatically': True, + 'AutomaticPresenceType': dbus.UInt32(2), + 'AutomaticPresenceStatus': 'available', + 'AutomaticPresenceMessage': 'My vision is augmented', + 'Nickname': 'JC', + 'AvatarMime': 'image/jpeg', + }) + fake_accounts_service.update_attributes(account2_id, changed={ + 'manager': 'fakecm', + 'protocol': 'fakeprotocol', + 'DisplayName': 'Personal account', + 'NormalizedName': 'jc.denton@example.com', + 'Enabled': True, + 'ConnectAutomatically': False, + 'AutomaticPresenceType': dbus.UInt32(2), + 'AutomaticPresenceStatus': 'available', + 'AutomaticPresenceMessage': 'My vision is augmented', + 'Nickname': 'JC', + 'AvatarMime': 'image/jpeg', + }) + # 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@unatco.int -param-account=jc.denton@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@example.com -param-account=jc.denton@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() + fake_accounts_service.update_parameters(account1_id, changed={ + 'account': 'jc.denton@unatco.int', + }) + fake_accounts_service.update_parameters(account2_id, changed={ + 'account': 'jc.denton@example.com', + }) os.makedirs(accounts_dir + '/' + account1_id) avatar_bin = open(accounts_dir + '/' + account1_id + '/avatar.bin', 'w') @@ -92,11 +94,15 @@ AvatarMime=image/jpeg account_connections_file.write("") account_connections_file.close() -def test(q, bus, unused): +def test(q, bus, unused, **kwargs): + # make sure RequestConnection doesn't get called yet events = [EventPattern('dbus-method-call', method='RequestConnection')] q.forbid_events(events) + fake_accounts_service = kwargs['fake_accounts_service'] + preseed(q, bus, fake_accounts_service) + # Wait for MC to load mc = MC(q, bus) @@ -230,5 +236,5 @@ def test(q, bus, unused): 'busy', 'Talking to Illuminati') if __name__ == '__main__': - preseed() - exec_test(test, {}, preload_mc=False, use_fake_accounts_service=False) + exec_test(test, {}, preload_mc=False, use_fake_accounts_service=True, + pass_kwargs=True) diff --git a/tests/twisted/account-manager/update-parameters.py b/tests/twisted/account-manager/update-parameters.py index 9abfb76d..56656231 100644 --- a/tests/twisted/account-manager/update-parameters.py +++ b/tests/twisted/account-manager/update-parameters.py @@ -29,7 +29,7 @@ from mctest import exec_test, SimulatedConnection, create_fakecm_account,\ SimulatedChannel import constants as cs -def test(q, bus, mc): +def test(q, bus, mc, **kwargs): cm_name_ref = dbus.service.BusName( tp_name_prefix + '.ConnectionManager.fakecm', bus=bus) @@ -250,27 +250,14 @@ def test(q, bus, mc): cache_dir = os.environ['XDG_CACHE_HOME'] - # fd.o #28557: when the file has been updated, the account parameter + # fd.o #28557: when the "file" has been updated, the account parameter # has its two backslashes doubled to 4 (because of the .desktop encoding), # but they are not doubled again. - i = 0 - updated = False - while i < 500: - - for line in open(cache_dir + - '/mcp-test-diverted-account-plugin.conf', 'r'): - if line.startswith('param-account=') and '\\' in line: - assertEquals(r'param-account=\\\\' + '\n', line) - updated = True - - if updated: - break - - # just to not busy-wait - time.sleep(0.1) - i += 1 - - assert updated + assertEquals(r'\\\\', + kwargs['fake_accounts_service'].accounts + [account.object_path[len(cs.ACCOUNT_PATH_PREFIX):]] + [3] # parameters of unknown type + ['account']) if __name__ == '__main__': - exec_test(test, {}, use_fake_accounts_service=False) + exec_test(test, {}, pass_kwargs=True) diff --git a/tests/twisted/crash-recovery/crash-recovery.py b/tests/twisted/crash-recovery/crash-recovery.py index c3da6de2..2bc45349 100644 --- a/tests/twisted/crash-recovery/crash-recovery.py +++ b/tests/twisted/crash-recovery/crash-recovery.py @@ -31,7 +31,9 @@ from mctest import exec_test, SimulatedConnection, SimulatedClient, \ expect_client_setup, MC import constants as cs -def preseed(): +account_id = 'fakecm/fakeprotocol/jc_2edenton_40unatco_2eint' + +def preseed(q, bus, fake_accounts_service): accounts_dir = os.environ['MC_ACCOUNT_DIR'] try: @@ -39,20 +41,17 @@ def preseed(): except OSError: pass - accounts_cfg = open(accounts_dir + '/accounts.cfg', 'w') - - accounts_cfg.write("""# Telepathy accounts -[fakecm/fakeprotocol/jc_2edenton_40unatco_2eint] -manager=fakecm -protocol=fakeprotocol -DisplayName=Work account -NormalizedName=jc.denton@unatco.int -param-account=jc.denton@unatco.int -param-password=ionstorm -Enabled=1 -""") - - accounts_cfg.close() + fake_accounts_service.update_attributes(account_id, changed={ + 'manager': 'fakecm', + 'protocol': 'fakeprotocol', + 'DisplayName': 'Work account', + 'NormalizedName': 'jc.denton@unatco.int', + 'Enabled': True, + }) + fake_accounts_service.update_parameters(account_id, untyped={ + 'account': 'jc.denton@unatco.int', + 'password': 'ionstorm', + }) account_connections_file = open(accounts_dir + '/.mc_connections', 'w') @@ -61,7 +60,10 @@ Enabled=1 cs.tp_name_prefix + '.Connection.fakecm.fakeprotocol.jc', 'fakecm/fakeprotocol/jc_2edenton_40unatco_2eint')) -def test(q, bus, unused): +def test(q, bus, unused, **kwargs): + fake_accounts_service = kwargs['fake_accounts_service'] + preseed(q, bus, fake_accounts_service) + text_fixed_properties = dbus.Dictionary({ cs.CHANNEL + '.TargetHandleType': cs.HT_CONTACT, cs.CHANNEL + '.ChannelType': cs.CHANNEL_TYPE_TEXT, @@ -124,5 +126,5 @@ def test(q, bus, unused): q.dbus_return(e.message, signature='') if __name__ == '__main__': - preseed() - exec_test(test, {}, preload_mc=False, use_fake_accounts_service=False) + exec_test(test, {}, preload_mc=False, use_fake_accounts_service=True, + pass_kwargs=True) diff --git a/tests/twisted/dispatcher/create-at-startup.py b/tests/twisted/dispatcher/create-at-startup.py index c5a139aa..c3c2a173 100644 --- a/tests/twisted/dispatcher/create-at-startup.py +++ b/tests/twisted/dispatcher/create-at-startup.py @@ -32,7 +32,9 @@ from mctest import exec_test, SimulatedConnection, SimulatedClient, \ expect_client_setup, MC import constants as cs -def preseed(): +account_id = 'fakecm/fakeprotocol/jc_2edenton_40unatco_2eint' + +def preseed(q, bus, fake_accounts_service): accounts_dir = os.environ['MC_ACCOUNT_DIR'] try: @@ -40,28 +42,30 @@ def preseed(): except OSError: pass - accounts_cfg = open(accounts_dir + '/accounts.cfg', 'w') - accounts_cfg.write("""# Telepathy accounts -[fakecm/fakeprotocol/jc_2edenton_40unatco_2eint] -manager=fakecm -protocol=fakeprotocol -DisplayName=Work account -NormalizedName=jc.denton@unatco.int -param-account=jc.denton@unatco.int -param-password=ionstorm -Enabled=1 -ConnectAutomatically=0 -AutomaticPresenceType=2 -AutomaticPresenceStatus=available -AutomaticPresenceMessage= -""") - accounts_cfg.close() + fake_accounts_service.update_attributes(account_id, changed={ + 'manager': 'fakecm', + 'protocol': 'fakeprotocol', + 'DisplayName': 'Work account', + 'NormalizedName': 'jc.denton@unatco.int', + 'Enabled': True, + 'ConnectAutomatically': False, + 'AutomaticPresenceType': dbus.UInt32(2), + 'AutomaticPresenceStatus': 'available', + 'AutomaticPresenceMessage': '', + }) + fake_accounts_service.update_parameters(account_id, untyped={ + 'account': 'jc.denton@unatco.int', + 'password': 'ionstorm', + }) account_connections_file = open(accounts_dir + '/.mc_connections', 'w') account_connections_file.write("") account_connections_file.close() -def test(q, bus, unused): +def test(q, bus, unused, **kwargs): + fake_accounts_service = kwargs['fake_accounts_service'] + preseed(q, bus, fake_accounts_service) + text_fixed_properties = dbus.Dictionary({ cs.CHANNEL + '.TargetHandleType': cs.HT_CONTACT, cs.CHANNEL + '.ChannelType': cs.CHANNEL_TYPE_TEXT, @@ -234,5 +238,5 @@ def test(q, bus, unused): assert len(e.args) == 6 if __name__ == '__main__': - preseed() - exec_test(test, {}, preload_mc=False, use_fake_accounts_service=False) + exec_test(test, {}, preload_mc=False, use_fake_accounts_service=True, + pass_kwargs=True) |