Merge lp:~brendan-donegan/ubuntu-autopilot-tests/contacts_dbus into lp:ubuntu-autopilot-tests/ubuntu-experience-tests

Proposed by Brendan Donegan
Status: Merged
Approved by: Dan Chapman 
Approved revision: 22
Merged at revision: 21
Proposed branch: lp:~brendan-donegan/ubuntu-autopilot-tests/contacts_dbus
Merge into: lp:ubuntu-autopilot-tests/ubuntu-experience-tests
Diff against target: 91 lines (+67/-0)
1 file modified
ubuntu_experience_tests/helpers.py (+67/-0)
To merge this branch: bzr merge lp:~brendan-donegan/ubuntu-autopilot-tests/contacts_dbus
Reviewer Review Type Date Requested Status
Dan Chapman  (community) Approve
Richard Huddie (community) Approve
PS Jenkins bot continuous-integration Pending
Review via email: mp+223703@code.launchpad.net

Description of the change

Put ContactsDbusService in helpers.py, so that all UX tests can use it.

To post a comment you must log in.
22. By Brendan Donegan

Fix call to get_vcard_uid

Revision history for this message
Richard Huddie (rhuddie) :
review: Approve
Revision history for this message
Dan Chapman  (dpniel) wrote :

Looks good to me

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntu_experience_tests/helpers.py'
2--- ubuntu_experience_tests/helpers.py 2014-05-20 12:35:59 +0000
3+++ ubuntu_experience_tests/helpers.py 2014-06-19 09:50:40 +0000
4@@ -2,6 +2,7 @@
5 #
6 # Copyright 2014 Canonical Ltd.
7 # Author: Omer Akram <omer.akram@canonical.com>
8+# Brendan Donegan <brendan.donegan@canonical.com>
9 #
10 # This file is part of ubuntu-experience-tests.
11 #
12@@ -19,6 +20,7 @@
13
14 """Helper functions to make writing Inter-app integration tests easier."""
15
16+import dbus
17 import subprocess
18 import time
19
20@@ -26,6 +28,71 @@
21 from ubuntuuitoolkit import emulators as toolkit_emulators
22 from unity8.shell.emulators import UnityEmulatorBase
23
24+DBUS_IFACE_ADD_BOOK = 'com.canonical.pim.AddressBook'
25+DBUS_IFACE_ADD_BOOKVIEW = 'com.canonical.pim.AddressBookView'
26+
27+
28+class ContacstDbusService(object):
29+ def __init__(self):
30+ self.bus = None
31+ self.addr = None
32+ self.addr_iface = None
33+ self.bus = dbus.SessionBus()
34+ self.addr = self.bus.get_object(
35+ 'com.canonical.pim', '/com/canonical/pim/AddressBook')
36+ self.addr_iface = dbus.Interface(
37+ self.addr, dbus_interface=DBUS_IFACE_ADD_BOOK)
38+
39+ def query_contacts(self, fields='', query='', sources=[]):
40+ view_path = self.addr_iface.query(fields, query, [])
41+ view = self.bus.get_object(
42+ 'com.canonical.pim', view_path)
43+ view_iface = dbus.Interface(
44+ view, dbus_interface=DBUS_IFACE_ADD_BOOKVIEW)
45+ contacts = view_iface.contactsDetails([], 0, -1)
46+ view.close()
47+ return contacts
48+
49+ def update_contact(self, vcard):
50+ return self.addr_iface.updateContacts([vcard])
51+
52+ def create_contact(self, vcard):
53+ return self.addr_iface.createContact(vcard, "")
54+
55+ def delete_contact(self, ids):
56+ return self.addr_iface.removeContacts(ids)
57+
58+ def get_vcard_uid(self, vcard):
59+ """
60+ Return the UID of the provided vcard
61+ :param vcard: vcard formatted data
62+ :return: uid value from vcard, else None
63+ """
64+ uid_pattern = re.compile(r'''
65+ ^ # start of string
66+ .* # any characters
67+ UID:(.*?) # UID value, saved to group, non-greedy
68+ \r\n # new line
69+ .* # anything else
70+ $ # end of string
71+ ''', re.VERBOSE | re.IGNORECASE | re.DOTALL)
72+ uid = None
73+ match = uid_pattern.match(vcard)
74+ if match:
75+ uid = match.group(1)
76+ return uid
77+
78+ def delete_all_contacts(self):
79+ """
80+ Delete all contacts using the dbus service
81+ """
82+ uids = []
83+ contacts = self.query_contacts()
84+ for contact in contacts:
85+ uid = self.get_vcard_uid(contact)
86+ if uid:
87+ uids.append(uid)
88+ self.delete_contact(uids)
89
90 def get_proxy_object_by_process_name(proc_name):
91 """Helper function to return proxy object of a process

Subscribers

People subscribed via source and target branches