[Merge] lp:~canonical-platform-qa/address-book-app/autopilot-get_contacts into lp:address-book-app
Thomi Richards
thomi.richards at canonical.com
Tue Sep 2 20:56:24 UTC 2014
Diff comments:
> === modified file 'src/imports/Ubuntu/Contacts/ContactDelegate.qml'
> --- src/imports/Ubuntu/Contacts/ContactDelegate.qml 2014-07-31 08:00:56 +0000
> +++ src/imports/Ubuntu/Contacts/ContactDelegate.qml 2014-09-02 19:42:20 +0000
> @@ -96,6 +96,7 @@
>
> Label {
> id: name
> + objectName: "nameLabel"
>
> anchors {
> left: avatar.right
>
> === modified file 'src/imports/Ubuntu/Contacts/ContactSimpleListView.qml'
> --- src/imports/Ubuntu/Contacts/ContactSimpleListView.qml 2014-08-18 19:03:13 +0000
> +++ src/imports/Ubuntu/Contacts/ContactSimpleListView.qml 2014-09-02 19:42:20 +0000
> @@ -279,6 +279,7 @@
> onFlickStarted: view.currentIndex = -1
> listDelegate: ContactDelegate {
> id: contactDelegate
> + objectName: 'contactDelegate' + index
>
> property var removalAnimation
>
>
> === modified file 'tests/autopilot/address_book_app/__init__.py'
> --- tests/autopilot/address_book_app/__init__.py 2014-08-01 22:04:48 +0000
> +++ tests/autopilot/address_book_app/__init__.py 2014-09-02 19:42:20 +0000
> @@ -75,9 +75,9 @@
> objectName="contactViewPage")
>
> def get_contact_list_pick_page(self):
> - pages = self.select_many("ContactListPage",
> - objectName="contactListPage")
> - for p in pages:
> + contact_list_pages = self.select_many(
> + pages.ContactListPage, objectName='contactListPage')
> + for p in contact_list_pages:
> if p.pickMode:
> return p
> return None
> @@ -128,14 +128,6 @@
> self.click_action_button("save")
> bottom_swipe_page.isCollapsed.wait_for(True)
>
> - def done_selection(self, actionName):
> - """
> - Press the 'doneSelection' button
> - """
> - bottom_swipe_page = self.get_contact_list_page()
> - self.click_action_button(actionName)
> - bottom_swipe_page.isCollapsed.wait_for(True)
> -
> def get_toolbar(self):
> """Override base class so we get our expected Toolbar subclass."""
> return self.select_single(ubuntuuitoolkit.Toolbar)
>
> === modified file 'tests/autopilot/address_book_app/pages/_contact_list_page.py'
> --- tests/autopilot/address_book_app/pages/_contact_list_page.py 2014-08-28 20:28:39 +0000
> +++ tests/autopilot/address_book_app/pages/_contact_list_page.py 2014-09-02 19:42:20 +0000
> @@ -19,23 +19,20 @@
> import logging
> import time
>
> -from autopilot.introspection.dbus import StateNotFoundError
> +import autopilot.logging
> +import ubuntuuitoolkit
>
> from address_book_app.pages import _common, _contact_view
>
>
> -LOGGER = logging.getLogger(__name__)
> +logger = logging.getLogger(__name__)
>
>
> class ContactListPage(_common.PageWithHeader, _common.PageWithBottomEdge):
> - """ ContactListPage emulator class """
> -
> - def __init__(self, *args):
> - self.contacts = None
> - self.items = []
> - self.selected_items = []
> - super(ContactListPage, self).__init__(*args)
> -
> +
> + """Autopilot helper for the Contact List page."""
> +
> + @autopilot.logging.log_action(logger.info)
> def open_contact(self, index):
> """Open the page with the contact information.
>
> @@ -43,96 +40,98 @@
> :return: The page with the contact information.
>
> """
> - contacts = self.get_contacts()
> - contact_delegate = contacts[index]
> + contact_delegate = self._get_contact_delegate(index)
> self.pointing_device.click_object(contact_delegate)
> contact_delegate.state.wait_for('expanded')
> - details_button = contact_delegate.wait_select_single(objectName="infoIcon")
> + details_button = contact_delegate.wait_select_single(
> + objectName='infoIcon')
> self.pointing_device.click_object(details_button)
> return self.get_root_instance().select_single(
> _contact_view.ContactView, objectName='contactViewPage')
>
> - def _get_list_view(self):
> - return self.wait_select_single("ContactListView",
> - objectName="contactListView")
> -
> - def get_contacts(self):
> - """
> - Returns a list of ContactDelegate objects and populate
> - self.items
> - """
> - time.sleep(1)
> - self.contacts = self.select_many("ContactDelegate")
> - self.items = []
> - for contact in self.contacts:
> - if contact.visible:
> - item = contact.select_single("QQuickRectangle",
> - objectName="mainItem")
> - self.items.append(item)
> - return self.contacts
> -
> - def start_selection(self, idx):
> - view = self._get_list_view()
> - if not view.isInSelectionMode:
> - self.get_contacts()
> - self.selected_items.append(self.items[idx])
> - self.pointing_device.move_to_object(self.contacts[idx])
> - self.pointing_device.press()
> - time.sleep(2.0)
> - self.pointing_device.release()
> - view.isInSelectionMode.wait_for(True)
> - else:
> - self.selected_items.append(self.items[idx])
> - self.pointing_device.click_object(self.items[idx])
> -
> -
> - def select_contacts_by_index(self, indices):
> + def _get_contact_delegate(self, index):
> + return self.select_single(
> + 'ContactDelegate',
> + objectName='contactDelegate{}'.format(index),
> + visible=True
> + )
> +
> + @autopilot.logging.log_action(logger.info)
Instead of this long, kind of ugly string, how about doing this at the top of the file:
log_action_info = autopilot.logging.log_action(logging.info)
and then use it as a decorator:
@log_action_info
def ....
> + def select_contacts(self, indices):
> """ Select contacts corresponding to the list of index in indices
>
> :param indices: List of integers
> +
> """
> - self.deselect_all()
> + self._deselect_all()
> if len(indices) > 0:
> - self.start_selection(indices[0])
> -
> - # Select matching indices
> - for idx in indices[1:]:
> - self.selected_items.append(self.items[idx])
> - self.pointing_device.click_object(self.items[idx])
> -
> - def deselect_all(self):
> - """Deselect every contacts"""
> - contacts = self.select_many("ContactDelegate")
> - self.selected_items = []
> - for contact in contacts:
> - if contact.selected:
> - mark = contact.select_single("QQuickRectangle",
> - objectName="selectionMark")
> - self.pointing_device.click_object(mark)
> -
> - def click_button(self, parent, objectname):
> - """Press a button that matches objectname
> -
> - :param objectname: Name of the object
> - """
> - if parent:
> - obj = parent
> + view = self._get_list_view()
> + if not view.isInSelectionMode:
> + self._start_selection(indices[0])
> + indices = indices[1:]
> +
> + for index in indices:
> + contact = self._get_contact_delegate(index)
> + self.pointing_device.click_object(contact)
> +
> + @autopilot.logging.log_action(logger.debug)
> + def _deselect_all(self):
> + """Deselect all contacts."""
> + view = self._get_list_view()
> + if view.isInSelectionMode:
> + contacts = self.select_many('ContactDelegate', visible=True)
> + for contact in contacts:
> + if contact.selected:
> + logger.info('Deselect {}.'.format(contact.objectName))
> + self.pointing_device.click_object(contact)
> else:
> - obj = self
> - try:
> - buttons = obj.select_many("Button",
> - objectName=objectname)
> - for button in buttons:
> - if button.visible:
> - self.pointing_device.click_object(button)
> - except StateNotFoundError:
> - LOGGER.error(
> - 'Button with objectName "{0}" not found.'.format(objectname)
> - )
> - raise
> -
> - def delete(self, main_window):
> - main_window.done_selection("delete")
> - dialog = main_window.wait_select_single("RemoveContactsDialog",
> - objectName="removeContactsDialog")
> - self.click_button(main_window, "removeContactsDialog.Yes")
> + logger.debug('The page is not in selection mode.')
> +
> + def _start_selection(self, index):
> + # TODO change this for click_object once the press duration
> + # parameter is added. See http://pad.lv/1268782
> + contact = self._get_contact_delegate(index)
> + self.pointing_device.move_to_object(contact)
> + self.pointing_device.press()
> + time.sleep(2.0)
> + self.pointing_device.release()
> + view = self._get_list_view()
> + view.isInSelectionMode.wait_for(True)
> +
> + def _get_list_view(self):
> + return self.wait_select_single(
> + 'ContactListView', objectName='contactListView')
> +
> + @autopilot.logging.log_action(logger.info)
> + def delete_selected_contacts(self):
> + self.get_header().click_action_button('delete')
> + self.isCollapsed.wait_for(True)
> + dialog = self.get_root_instance().wait_select_single(
> + RemoveContactsDialog, objectName='removeContactsDialog')
> + dialog.confirm_removal()
> +
> + def get_contacts(self):
> + """Return a list with the names of the contacts."""
> + contact_delegates = self.select_many('ContactDelegate', visible=True)
> + contact_delegates = sorted(
> + contact_delegates,
> + key=lambda delegate: delegate.globalRect.y)
> +
> + name_labels = [
> + delegate.select_single('Label', objectName='nameLabel') for
> + delegate in contact_delegates
> + ]
> + return [label.text for label in name_labels]
> +
> +
> +class RemoveContactsDialog(
> + ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase):
> +
> + """Autopilot helper for the Remove Contacts dialog."""
> +
> + @autopilot.logging.log_action(logger.debug)
> + def confirm_removal(self):
> + button = self.select_single(
> + 'Button', objectName='removeContactsDialog.Yes')
> + self.pointing_device.click_object(button)
> + self.wait_until_destroyed()
>
> === modified file 'tests/autopilot/address_book_app/tests/__init__.py'
> --- tests/autopilot/address_book_app/tests/__init__.py 2014-07-18 00:49:35 +0000
> +++ tests/autopilot/address_book_app/tests/__init__.py 2014-09-02 19:42:20 +0000
> @@ -52,7 +52,7 @@
> os.environ['QTCONTACTS_MANAGER_OVERRIDE'] = 'galera'
> os.environ['ADDRESS_BOOK_APP_ICON_THEME'] = 'ubuntu-mobile'
> vcard_data = ""
> - if AddressBookAppTestCase.PRELOAD_VCARD:
> + if self.PRELOAD_VCARD:
> # Use vcard from source tree and fallback on installed vcard (from
> # address-book-app-autopilot package)
> if os.path.exists(AddressBookAppTestCase.VCARD_PATH_DEV):
> @@ -76,7 +76,6 @@
> self.launch_click_installed()
>
> AddressBookAppTestCase.ARGS = []
> - AddressBookAppTestCase.PRELOAD_VCARD = False
> self.main_window.visible.wait_for(True)
> self.app = address_book_app.AddressBookApp(self.app_proxy)
>
>
> === modified file 'tests/autopilot/address_book_app/tests/test_create_new_from_uri.py'
> --- tests/autopilot/address_book_app/tests/test_create_new_from_uri.py 2014-06-08 13:55:29 +0000
> +++ tests/autopilot/address_book_app/tests/test_create_new_from_uri.py 2014-09-02 19:42:20 +0000
> @@ -19,7 +19,6 @@
>
> def setUp(self):
> self.ARGS.append("addressbook:///create?phone=1234567890")
> - AddressBookAppTestCase.PRELOAD_VCARD = False
> super(TestCreateNewContactFromURI, self).setUp()
>
> def test_save_new_contact(self):
>
> === modified file 'tests/autopilot/address_book_app/tests/test_delete_contact.py'
> --- tests/autopilot/address_book_app/tests/test_delete_contact.py 2014-05-22 13:42:45 +0000
> +++ tests/autopilot/address_book_app/tests/test_delete_contact.py 2014-09-02 19:42:20 +0000
> @@ -1,41 +1,58 @@
> # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
>
> -"""Tests for the Addressbook App"""
> -
> -# Copyright 2014 Canonical
> +# Copyright (C) 2014 Canonical Ltd.
> #
> -# This program is free software: you can redistribute it and/or modify it
> -# under the terms of the GNU General Public License version 3, as published
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License version 3, as published
> # by the Free Software Foundation.
> -
> -from testtools.matchers import Equals
> -from address_book_app.tests import AddressBookAppTestCase
> -
> -
> -class TestDeleteSelectContact(AddressBookAppTestCase):
> +#
> +# This program 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 General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program. If not, see <http://www.gnu.org/licenses/>.
> +
> +"""Delete tests for the Addressbook App."""
> +
> +from address_book_app import tests
> +
> +
> +class TestDeleteSelectContact(tests.AddressBookAppTestCase):
> +
> """
> Delete a contact using pick mode and verify the behavior of Cancel and
> Delete actions
> """
> +
> + PRELOAD_VCARD = True
> +
> + ALL_CONTACTS = [
> + 'teste test34',
> + 'teste teste2',
> + 'teste3 teste3',
> + ]
> +
> scenarios = [
> - ("single_cancel", {
> - "select": [1],
> - "action": "cancel"}),
> - ("multiple_cancel", {
> - "select": [1, 2],
> - "action": "cancel"}),
> - ("single_delete", {
> - "select": [1],
> - "action": "delete"}),
> - ("multiple_delete", {
> - "select": [1, 2],
> - "action": "delete"}),
> + ('single_cancel', {
> + 'select': [ALL_CONTACTS[1]],
> + 'action': 'cancel',
> + 'expected_result': ALL_CONTACTS}),
> + ('multiple_cancel', {
> + 'select': [ALL_CONTACTS[1], ALL_CONTACTS[2]],
> + 'action': 'cancel',
> + 'expected_result': ALL_CONTACTS}),
> + ('single_delete', {
> + 'select': [ALL_CONTACTS[1]],
> + 'action': 'delete',
> + 'expected_result': [ALL_CONTACTS[0], ALL_CONTACTS[2]]}),
> + ('multiple_delete', {
> + 'select': [ALL_CONTACTS[1], ALL_CONTACTS[2]],
> + 'action': 'delete',
> + 'expected_result': [ALL_CONTACTS[0]]}),
> ]
>
> - def setUp(self):
> - AddressBookAppTestCase.PRELOAD_VCARD = True
> - super(TestDeleteSelectContact, self).setUp()
> -
> def test_select(self):
> """
> Delete a contact in pick mode
> @@ -45,19 +62,13 @@
> contact in the list before and after the action.
> Note that it doesn't check which contact has been deleted.
> """
> - listpage = self.app.main_window.get_contact_list_page()
> - contacts_before = listpage.get_contacts()
> + list_page = self.app.main_window.get_contact_list_page()
>
> - listpage.select_contacts_by_index(self.select)
> - deleted = []
> + indices = [self.ALL_CONTACTS.index(name) for name in self.select]
> + list_page.select_contacts(indices)
> if self.action == "cancel":
> self.app.main_window.cancel()
> elif self.action == "delete":
> - listpage.delete(self.app.main_window)
> - deleted = self.select
> + list_page.delete_selected_contacts()
>
> - contacts_after = listpage.get_contacts()
> - # TODO:
> - # - Verify which contact have been deleted
> - self.assertThat(len(contacts_after), Equals(len(contacts_before) -
> - len(deleted)))
> + self.assertEqual(list_page.get_contacts(), self.expected_result)
>
> === modified file 'tests/autopilot/address_book_app/tests/test_multiple_pick_mode.py'
> --- tests/autopilot/address_book_app/tests/test_multiple_pick_mode.py 2014-07-25 20:51:16 +0000
> +++ tests/autopilot/address_book_app/tests/test_multiple_pick_mode.py 2014-09-02 19:42:20 +0000
> @@ -16,9 +16,10 @@
> class TestMultiplePickerMode(AddressBookAppTestCase):
> """ Tests app in single picker mode"""
>
> + PRELOAD_VCARD = True
> +
> def setUp(self):
> self.ARGS.append("addressbook:///pick?single=false")
> - AddressBookAppTestCase.PRELOAD_VCARD = True
> super(TestMultiplePickerMode, self).setUp()
>
> def test_select_contacts(self):
>
> === modified file 'tests/autopilot/address_book_app/tests/test_single_pick_mode.py'
> --- tests/autopilot/address_book_app/tests/test_single_pick_mode.py 2014-07-26 01:37:57 +0000
> +++ tests/autopilot/address_book_app/tests/test_single_pick_mode.py 2014-09-02 19:42:20 +0000
> @@ -16,9 +16,10 @@
> class TestSinglePickerMode(AddressBookAppTestCase):
> """ Tests app in single picker mode"""
>
> + PRELOAD_VCARD = True
> +
> def setUp(self):
> AddressBookAppTestCase.ARGS.append("addressbook:///pick?single=true")
> - AddressBookAppTestCase.PRELOAD_VCARD = True
> super(TestSinglePickerMode, self).setUp()
>
> def test_select_single_contact(self):
>
--
https://code.launchpad.net/~canonical-platform-qa/address-book-app/autopilot-get_contacts/+merge/233104
Your team Ubuntu Phablet Team is requested to review the proposed merge of lp:~canonical-platform-qa/address-book-app/autopilot-get_contacts into lp:address-book-app.
More information about the Ubuntu-reviews
mailing list