From 0df88cd7a55e7a3a1e9bfce86adf1d6665e8c770 Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Fri, 15 Jun 2012 18:18:48 +0100 Subject: add initial version of new gvariant account backend The big problem with this right now is that the mcp API depends on all account properties being strings. Once the API is fixed we can update this plugin easily to support it, and actually save types to disk! Bug: https://bugs.freedesktop.org/show_bug.cgi?id=35896 Signed-off-by: Jonny Lamb --- tests/twisted/account-manager/gvariant-accounts.py | 130 +++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 tests/twisted/account-manager/gvariant-accounts.py (limited to 'tests/twisted/account-manager/gvariant-accounts.py') diff --git a/tests/twisted/account-manager/gvariant-accounts.py b/tests/twisted/account-manager/gvariant-accounts.py new file mode 100644 index 00000000..3f271be6 --- /dev/null +++ b/tests/twisted/account-manager/gvariant-accounts.py @@ -0,0 +1,130 @@ +# 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 +import dbus.service +import os +import sys + +from servicetest import EventPattern, call_async, assertEquals +from mctest import exec_test, AccountManager, Account, MC +import constants as cs + +account_prefix = cs.tp_path_prefix + '/Account/' +account1_id = 'fakecm/fakeprotocol/jc_2edenton_40unatco_2eint' +filename = None + +def preseed(): + global filename + + accounts_dir = os.environ['MC_ACCOUNT_DIR'] + + escaped = account1_id.replace('/', '_') + filename = accounts_dir + '/' + escaped + account = open(filename, 'w') + account.write("""{ +'id': <'%s'>, +'manager': <'fakecm'>, +'protocol': <'fakeprotocol'>, +'DisplayName': <'Work account'>, +'NormalizedName': <'jc.denton@unatco.int'>, +'param-account': <'jc.denton@unatco.int'>, +'param-password': <'ionstorm'>, +'Enabled': <'true'>, +'ConnectAutomatically': <'true'>, +'AutomaticPresenceType': <'2'>, +'AutomaticPresenceMessage': <'My vision is augmented'>, +'Nickname': <'JC'>, +'AvatarMime': <'image/jpeg'>, +'avatar_token': <'Deus Ex'> +}""" % account1_id) + account.close() + +def test(q, bus, unused): + global filename + + expected_params = { + 'account': 'jc.denton@unatco.int', + 'password': 'ionstorm', + } + + mc = MC(q, bus) + + am = AccountManager(bus) + + # make sure we have the right accounts + props = am.GetAll(cs.AM, dbus_interface=dbus.PROPERTIES_IFACE) + accounts = props['ValidAccounts'] + + assertEquals(1, len(accounts)) + path = accounts[0] + assertEquals(account_prefix + account1_id, path) + + account = Account(bus, path) + + # make sure the account has got the right properties + props = account.GetAll(cs.ACCOUNT, dbus_interface=dbus.PROPERTIES_IFACE) + + assertEquals('Work account', props['DisplayName']) + assertEquals('jc.denton@unatco.int', props['NormalizedName']) + assertEquals(expected_params, props['Parameters']) + assertEquals(True, props['Enabled']) + assertEquals(True, props['ConnectAutomatically']) + assertEquals((cs.PRESENCE_TYPE_AVAILABLE, '', 'My vision is augmented'), + props['AutomaticPresence']) + assertEquals('JC', props['Nickname']) + + props = account.GetAll(cs.ACCOUNT_IFACE_AVATAR, dbus_interface=dbus.PROPERTIES_IFACE) + avatar = props['Avatar'] + assertEquals('image/jpeg', avatar[1]) + + # now delete the account and make sure the file is removed + assert os.path.exists(filename) + + account.Remove() + + q.expect_many(EventPattern('dbus-signal', signal='Removed'), + EventPattern('dbus-signal', signal='AccountRemoved')) + + assert not os.path.exists(filename) + + accounts = am.Get(cs.AM, 'ValidAccounts', dbus_interface=dbus.PROPERTIES_IFACE) + assertEquals(0, len(accounts)) + + # create an account and assert the file is present + parameters = { + 'account': 'dontdivert@bar.com', + 'password': 'le password' + } + + accounts_dir = os.environ['MC_ACCOUNT_DIR'] + name = 'fakecm/fakeprotocol/dontdivert_40bar_2ecom0' + second_filename = os.path.join(accounts_dir, name.replace('/', '_')) + assert not os.path.exists(second_filename) + + path = am.CreateAccount('fakecm', 'fakeprotocol', 'Display name', parameters, {}) + + e = q.expect('dbus-signal', signal='AccountValidityChanged') + object_path, valid = e.args + assertEquals(path, object_path) + assert valid + + assert os.path.exists(second_filename) + +if __name__ == '__main__': + preseed() + exec_test(test, {}, preload_mc=False) -- cgit v1.2.3