summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonny Lamb <jonny.lamb@collabora.co.uk>2012-06-28 17:02:39 +0100
committerJonny Lamb <jonny.lamb@collabora.co.uk>2012-08-03 10:44:54 +0100
commit9d0d65d0920f080eb324e5bab2cce61e983c1a3e (patch)
treef599de157fa9742169ea37b29c99cb5f17871638
parent41689eb5bbdbaa33e88e891031f9e0baabed3e30 (diff)
tests: add a test for the account migrator
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
-rw-r--r--tests/twisted/Makefile.am2
-rw-r--r--tests/twisted/account-manager/migrate-accounts.py99
2 files changed, 101 insertions, 0 deletions
diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am
index 0cf469b1..69f3fe01 100644
--- a/tests/twisted/Makefile.am
+++ b/tests/twisted/Makefile.am
@@ -10,6 +10,7 @@ TWISTED_BASIC_TESTS = \
account-manager/create-with-properties.py \
account-manager/enable-auto-connect.py \
account-manager/enable.py \
+ account-manager/migrate-accounts.py \
account-manager/nickname.py \
account-manager/param-types.py \
account-manager/presence.py \
@@ -339,6 +340,7 @@ EXTRA_DIST = \
CLEANFILES = \
accounts/accounts.cfg \
+ accounts/fakecm_* \
accounts/.mc_connections \
mc-[1-9]*.log \
*.pyc \
diff --git a/tests/twisted/account-manager/migrate-accounts.py b/tests/twisted/account-manager/migrate-accounts.py
new file mode 100644
index 00000000..0fd7f001
--- /dev/null
+++ b/tests/twisted/account-manager/migrate-accounts.py
@@ -0,0 +1,99 @@
+# Copyright (C) 2012 Collabora Ltd.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+# 02110-1301 USA
+
+import dbus
+"""Test for migrating accounts from old accounts.cfg to the new files
+"""
+
+import os
+
+import dbus
+import dbus.service
+
+from servicetest import assertEquals
+from mctest import exec_test, MC, AccountManager, Account, keyfile_read
+import constants as cs
+
+account_id = 'fakecm/fakeprotocol/jc_2edenton_40unatco_2eint'
+
+def preseed():
+
+ accounts_dir = os.environ['MC_ACCOUNT_DIR']
+
+ accounts_cfg = open(accounts_dir + '/accounts.cfg', 'w')
+
+ 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=0
+AutomaticPresenceType=2
+AutomaticPresenceStatus=available
+AutomaticPresenceMessage=My vision is augmented
+Nickname=JC
+""" % account_id)
+ accounts_cfg.close()
+
+def test(q, bus, unused):
+
+ expected_params = {
+ 'account': 'jc.denton@unatco.int',
+ 'password': r'ionstorm',
+ }
+
+ mc = MC(q, bus)
+
+ am = AccountManager(bus)
+ accounts = am.Get(cs.AM, 'ValidAccounts', dbus_interface=dbus.PROPERTIES_IFACE)
+ assertEquals(1, len(accounts))
+
+ account = Account(bus, accounts[0])
+ props = account.GetAll(cs.ACCOUNT, dbus_interface=dbus.PROPERTIES_IFACE)
+
+ assertEquals((2, 'available', 'My vision is augmented'), props['AutomaticPresence'])
+ assertEquals(False, props['ChangingPresence'])
+ assertEquals(False, props['ConnectAutomatically'])
+ assertEquals('Work account', props['DisplayName'])
+ assertEquals(True, props['Enabled'])
+ assertEquals(False, props['HasBeenOnline'])
+ assertEquals('', props['Icon'])
+ assertEquals('JC', props['Nickname'])
+ assertEquals('jc.denton@unatco.int', props['NormalizedName'])
+ assertEquals(expected_params, props['Parameters'])
+ assertEquals('', props['Service'])
+ assertEquals([], props['Supersedes'])
+ assertEquals(True, props['Valid'])
+
+ accounts_dir = os.environ['MC_ACCOUNT_DIR']
+ accounts = keyfile_read(accounts_dir + '/accounts.cfg')
+ assertEquals({None: {}}, accounts)
+
+ filename = os.path.join(accounts_dir, account_id.replace('/', '_'))
+ assert os.path.exists(filename)
+
+ s = file(filename).read()
+ # this will do tbh.
+ assert account_id in s
+
+if __name__ == '__main__':
+ preseed()
+ exec_test(test, {}, preload_mc=False)