Merge lp:~iahmad/dialer-app/smart-dialing-test into lp:dialer-app

Proposed by Omer Akram
Status: Work in progress
Proposed branch: lp:~iahmad/dialer-app/smart-dialing-test
Merge into: lp:dialer-app
Diff against target: 205 lines (+152/-2)
3 files modified
tests/autopilot/dialer_app/contacts.py (+58/-0)
tests/autopilot/dialer_app/emulators.py (+32/-0)
tests/autopilot/dialer_app/tests/test_calls.py (+62/-2)
To merge this branch: bzr merge lp:~iahmad/dialer-app/smart-dialing-test
Reviewer Review Type Date Requested Status
Gustavo Pichorim Boiko (community) Needs Fixing
Omer Akram (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+205706@code.launchpad.net

Commit message

Added smart dialing test.

Description of the change

Are there any related MPs required for this MP to build/function as expected? Please list.

None

Is your branch in sync with latest trunk (e.g. bzr pull lp:trunk -> no changes)

Yes. if not lp:dialer-app is broken

Did you perform an exploratory manual test run of your code change and any related functionality on device or emulator?

Yes, ran the test suite
Did you successfully run all tests found in your component's Test Plan on device or emulator?

Not needed, we only added tests

If you changed the UI, was the change specified/approved by design?

No change.

If you changed the packaging (debian), did you subscribe a core-dev to this MP?

None.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
93. By I Ahmad

fix for MismatchError and use of Eventually

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Omer Akram (om26er) wrote :

looks good to me

review: Approve
Revision history for this message
Gustavo Pichorim Boiko (boiko) wrote :

Thanks for writing this test.
This MR uses the user's addressbook and also assumes it is empty. I don't think that is a good idea, because we are required to run tests on our own devices and we are not going to be emptying the addressbook for that.

My suggestion would be to use the memory backend for the addressbook, there are two MRs being done to prepare the dialer-app to support that:
https://code.launchpad.net/~renatofilho/address-book-app/contact-list-default-model/+merge/204103
https://code.launchpad.net/~boiko/dialer-app/contacts_memory_backend/+merge/206521

Can you please revisit this test after those MRs are merged?

review: Needs Fixing
Revision history for this message
Gustavo Pichorim Boiko (boiko) wrote :

> Thanks for writing this test.
> This MR uses the user's addressbook and also assumes it is empty. I don't
> think that is a good idea, because we are required to run tests on our own
> devices and we are not going to be emptying the addressbook for that.
>
> My suggestion would be to use the memory backend for the addressbook, there
> are two MRs being done to prepare the dialer-app to support that:
> https://code.launchpad.net/~renatofilho/address-book-app/contact-list-default-
> model/+merge/204103
> https://code.launchpad.net/~boiko/dialer-
> app/contacts_memory_backend/+merge/206521
>
> Can you please revisit this test after those MRs are merged?

Actually, I was talking to Renato about that, and we both think it would be a much better idea to have the address-book-service to use the folks dummy backend (same effect as using the memory backend on the apps themselves), but with the advantage that we can write inter-app tests (like creating a contact from a call log entry, etc).
This would probably require that the autopilot tests are executed in a separate dbus session, not sure if this would be possible.

Unmerged revisions

93. By I Ahmad

fix for MismatchError and use of Eventually

92. By I Ahmad

merge om26er branch

91. By I Ahmad

fixed pep8 warnings

90. By I Ahmad

Fixed the typo in delete contact and added few more asserts

89. By I Ahmad

removed the commented code and simplified the contact details

88. By I Ahmad

fix the pyflakes and pep8 warnings

87. By I Ahmad

code cleanup

86. By I Ahmad

Added a smart dialing test case

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'tests/autopilot/dialer_app/contacts.py'
2--- tests/autopilot/dialer_app/contacts.py 1970-01-01 00:00:00 +0000
3+++ tests/autopilot/dialer_app/contacts.py 2014-02-11 07:56:02 +0000
4@@ -0,0 +1,58 @@
5+#!/usr/bin/env python3
6+# -*- encoding: utf-8 -*-
7+#
8+# Copyright 2013 Canonical Ltd.
9+#
10+# This program is free software; you can redistribute it and/or modify
11+# it under the terms of the GNU Lesser General Public License as published by
12+# the Free Software Foundation; version 3.
13+#
14+# This program is distributed in the hope that it will be useful,
15+# but WITHOUT ANY WARRANTY; without even the implied warranty of
16+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+# GNU Lesser General Public License for more details.
18+#
19+# You should have received a copy of the GNU Lesser General Public License
20+# along with this program. If not, see <http://www.gnu.org/licenses/>.
21+#
22+
23+# Borrowed the following helper class from
24+# lp:address-book-service/examples/contacts.py
25+
26+import dbus
27+
28+DBUS_IFACE_ADD_BOOK = 'com.canonical.pim.AddressBook'
29+DBUS_IFACE_ADD_BOOKVIEW = 'com.canonical.pim.AddressBookView'
30+
31+
32+class Contacts(object):
33+ def __init__(self):
34+ self.bus = None
35+ self.addr = None
36+ self.addr_iface = None
37+
38+ def connect(self):
39+ self.bus = dbus.SessionBus()
40+ self.addr = self.bus.get_object('com.canonical.pim',
41+ '/com/canonical/pim/AddressBook')
42+ self.addr_iface = dbus.Interface(self.addr,
43+ dbus_interface=DBUS_IFACE_ADD_BOOK)
44+
45+ def query(self, fields='', query='', sources=[]):
46+ view_path = self.addr_iface.query(fields, query, [])
47+ view = self.bus.get_object('com.canonical.pim',
48+ view_path)
49+ view_iface = dbus.Interface(view,
50+ dbus_interface=DBUS_IFACE_ADD_BOOKVIEW)
51+ contacts = view_iface.contactsDetails([], 0, -1)
52+ view.close()
53+ return contacts
54+
55+ def update(self, vcard):
56+ return self.addr_iface.updateContacts([vcard])
57+
58+ def create(self, vcard):
59+ return self.addr_iface.createContact(vcard, "")
60+
61+ def delete(self, ids):
62+ return self.addr_iface.removeContacts(ids)
63
64=== modified file 'tests/autopilot/dialer_app/emulators.py'
65--- tests/autopilot/dialer_app/emulators.py 2013-11-12 15:57:52 +0000
66+++ tests/autopilot/dialer_app/emulators.py 2014-02-11 07:56:02 +0000
67@@ -49,6 +49,38 @@
68 return self.select_single("KeypadButton",
69 objectName=buttonsDict[number])
70
71+ def get_key_from_letter(self, letter):
72+ buttonsDict = {
73+ "A": "buttonTwo",
74+ "B": "buttonTwo",
75+ "C": "buttonTwo",
76+ "D": "buttonThree",
77+ "E": "buttonThree",
78+ "F": "buttonThree",
79+ "G": "buttonFour",
80+ "H": "buttonFour",
81+ "I": "buttonFour",
82+ "J": "buttonFive",
83+ "K": "buttonFive",
84+ "L": "buttonFive",
85+ "M": "buttonSix",
86+ "N": "buttonSix",
87+ "O": "buttonSix",
88+ "P": "buttonSeven",
89+ "Q": "buttonSeven",
90+ "R": "buttonSeven",
91+ "S": "buttonSeven",
92+ "T": "buttonEight",
93+ "U": "buttonEight",
94+ "V": "buttonEight",
95+ "W": "buttonNine",
96+ "X": "buttonNine",
97+ "Y": "buttonNine",
98+ "Z": "buttonNine",
99+ }
100+ return self.select_single("KeypadButton",
101+ objectName=buttonsDict[letter.upper()])
102+
103 def get_erase_button(self):
104 return self.select_single("CustomButton", objectName="eraseButton")
105
106
107=== modified file 'tests/autopilot/dialer_app/tests/test_calls.py'
108--- tests/autopilot/dialer_app/tests/test_calls.py 2014-01-30 03:36:43 +0000
109+++ tests/autopilot/dialer_app/tests/test_calls.py 2014-02-11 07:56:02 +0000
110@@ -22,6 +22,23 @@
111
112 from dialer_app.tests import DialerAppTestCase
113
114+from dialer_app import contacts
115+
116+#Connect to address-book-service
117+service = contacts.Contacts()
118+service.connect()
119+
120+#Test VCARD
121+VCARD_HUMPTY = """
122+BEGIN:VCARD
123+VERSION:3.0
124+N:Dumpty;Humpty
125+FN:Humpty Dumpty
126+TEL;TYPE=WORK,VOICE;PID=1.1:(111) 555-1212
127+EMAIL;TYPE=PREF,INTERNET;PID=1.1:humty.dumty@example.com
128+END:VCARD
129+"""
130+
131 # determine whether we are running with phonesim
132 try:
133 out = subprocess.check_output(["/usr/share/ofono/scripts/list-modems"],
134@@ -151,6 +168,30 @@
135 print('Expected failure due to known Mir crash '
136 '(https://launchpad.net/bugs/1240400): %s' % e)
137
138+ def test_smart_dialing(self):
139+ """Test for smart dialing feature."""
140+ # assert that address book is empty.
141+ self.assert_number_of_contacts(0)
142+
143+ self.add_new_contact_from_predefined_vcard()
144+ self.addCleanup(self.delete_newly_added_contact)
145+
146+ self.dial_number_from_letter('Humpty')
147+
148+ contact_title = 'Humpty Dumpty'
149+ contact_search_list = self.main_view.dialer_page.wait_select_single(
150+ "ContactSearchListView"
151+ )
152+ Name = contact_search_list.select_single(
153+ "Label",
154+ text=contact_title,
155+ visible=True
156+ )
157+
158+ self.pointing_device.click_object(Name)
159+ self.wait_live_call_page(contact_title)
160+ self.hangup()
161+
162 #
163 # Helper methods
164 #
165@@ -163,7 +204,7 @@
166
167 self.pointing_device.click_object(self.call_button)
168
169- def wait_live_call_page(self, number):
170+ def wait_live_call_page(self, contact):
171 """Wait until live call page gets visible
172
173 Sets self.hangup_button.
174@@ -175,7 +216,7 @@
175
176 # should show called number in title page
177 lcp = self.app.select_single(objectName="pageLiveCall")
178- self.assertThat(lcp.title, Equals(number))
179+ self.assertThat(lcp.title, Eventually(Equals(contact)))
180
181 def wait_for_incoming_call(self):
182 """Wait up to 5 s for an incoming phone call"""
183@@ -200,3 +241,22 @@
184
185 # should switch to call log page
186 self.assertThat(self.history_list.visible, Eventually(Equals(True)))
187+
188+ def assert_number_of_contacts(self, number):
189+ contacts = service.query()
190+
191+ self.assertThat(lambda: len(contacts), Eventually(Equals(number)))
192+
193+ def dial_number_from_letter(self, letters):
194+ for letter in letters:
195+ key = self.main_view.dialer_page.get_key_from_letter(letter)
196+ self.pointing_device.click_object(key)
197+
198+ def add_new_contact_from_predefined_vcard(self):
199+ self.contactId = service.create(VCARD_HUMPTY)
200+ self.assert_number_of_contacts(1)
201+
202+ def delete_newly_added_contact(self):
203+ service.delete([self.contactId])
204+
205+ self.assert_number_of_contacts(0)

Subscribers

People subscribed via source and target branches