~om26er/dialer-app/lil_fix_for_smart_dial_test

« back to all changes in this revision

Viewing changes to tests/autopilot/dialer_app/contacts.py

  • Committer: Iftikhar Ahmad
  • Date: 2014-01-27 07:47:30 UTC
  • Revision ID: iftikhar.ahmad@canonical.com-20140127074730-pkv3hnu3ebig6nlu
Added a smart dialing test case

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python3
 
2
# -*- encoding: utf-8 -*-
 
3
#
 
4
#  Copyright 2013 Canonical Ltd.
 
5
#
 
6
#  This program is free software; you can redistribute it and/or modify
 
7
#  it under the terms of the GNU Lesser General Public License as published by
 
8
#  the Free Software Foundation; version 3.
 
9
#
 
10
#  This program is distributed in the hope that it will be useful,
 
11
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
#  GNU Lesser General Public License for more details.
 
14
#
 
15
#  You should have received a copy of the GNU Lesser General Public License
 
16
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
#
 
18
 
 
19
import dbus
 
20
import argparse
 
21
 
 
22
VCARD_JOE = """
 
23
BEGIN:VCARD
 
24
VERSION:3.0
 
25
N:Gump;Forrest
 
26
FN:Forrest Gump
 
27
TEL;TYPE=WORK,VOICE;PID=1.1:(111) 555-1212
 
28
TEL;TYPE=HOME,VOICE;PID=1.2:(404) 555-1212
 
29
EMAIL;TYPE=PREF,INTERNET;PID=1.1:forrestgump@example.com
 
30
END:VCARD
 
31
"""
 
32
 
 
33
class Contacts(object):
 
34
    def __init__(self):
 
35
        self.bus = None
 
36
        self.addr = None
 
37
        self.addr_iface = None
 
38
 
 
39
    def connect(self):
 
40
        self.bus = dbus.SessionBus()
 
41
        self.addr = self.bus.get_object('com.canonical.pim',
 
42
                                        '/com/canonical/pim/AddressBook')
 
43
        self.addr_iface = dbus.Interface(self.addr,
 
44
                                         dbus_interface='com.canonical.pim.AddressBook')
 
45
 
 
46
    def query(self, fields = '', query = '', sources = []):
 
47
        view_path = self.addr_iface.query(fields, query, [])
 
48
        view = self.bus.get_object('com.canonical.pim',
 
49
                                   view_path)
 
50
        view_iface = dbus.Interface(view,
 
51
                                    dbus_interface='com.canonical.pim.AddressBookView')
 
52
        contacts = view_iface.contactsDetails([], 0, -1)
 
53
        view.close()
 
54
        return contacts
 
55
 
 
56
    def update(self, vcard):
 
57
        return self.addr_iface.updateContacts([vcard])
 
58
 
 
59
    def create(self, vcard):
 
60
        return self.addr_iface.createContact(vcard, "")
 
61
 
 
62
    def delete(self, ids):
 
63
        return self.addr_iface.removeContacts(ids)
 
64