ubuntu-touch-coreapps-reviewers team mailing list archive
-
ubuntu-touch-coreapps-reviewers team
-
Mailing list archive
-
Message #02530
[Merge] lp:~ahayzen/ubuntu-weather-app/reboot-add-base-for-autopilot-tests into lp:ubuntu-weather-app/reboot
Andrew Hayzen has proposed merging lp:~ahayzen/ubuntu-weather-app/reboot-add-base-for-autopilot-tests into lp:ubuntu-weather-app/reboot.
Commit message:
* First cut of adding autopilot tests to ubuntu-weather-app reboot
Requested reviews:
Ubuntu Weather Developers (ubuntu-weather-dev)
Related bugs:
Bug #1432261 in Ubuntu Weather App: "Set up basic autopilot framework for weather app reboot"
https://bugs.launchpad.net/ubuntu-weather-app/+bug/1432261
For more details, see:
https://code.launchpad.net/~ahayzen/ubuntu-weather-app/reboot-add-base-for-autopilot-tests/+merge/260868
* First cut of adding autopilot tests to ubuntu-weather-app reboot
--
Your team Ubuntu Weather Developers is requested to review the proposed merge of lp:~ahayzen/ubuntu-weather-app/reboot-add-base-for-autopilot-tests into lp:ubuntu-weather-app/reboot.
=== modified file 'app/ui/AddLocationPage.qml'
--- app/ui/AddLocationPage.qml 2015-05-09 22:29:05 +0000
+++ app/ui/AddLocationPage.qml 2015-06-02 18:01:45 +0000
@@ -26,7 +26,7 @@
Page {
id: addLocationPage
-
+ objectName: "addLocationPage"
title: i18n.tr("Select a city")
visible: false
=== modified file 'app/ui/HomePage.qml'
--- app/ui/HomePage.qml 2015-04-29 14:22:00 +0000
+++ app/ui/HomePage.qml 2015-06-02 18:01:45 +0000
@@ -24,6 +24,7 @@
PageWithBottomEdge {
// Set to null otherwise the header is shown (but blank) over the top of the listview
id: locationPage
+ objectName: "homePage"
flickable: null
bottomEdgePageSource: Qt.resolvedUrl("LocationsPage.qml")
=== modified file 'po/com.ubuntu.weather.pot'
--- po/com.ubuntu.weather.pot 2015-05-22 00:13:54 +0000
+++ po/com.ubuntu.weather.pot 2015-06-02 18:01:45 +0000
@@ -8,7 +8,7 @@
msgstr ""
"Project-Id-Version: ubuntu-weather-app\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2015-05-21 19:13-0500\n"
+"POT-Creation-Date: 2015-05-29 03:55+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@xxxxxx>\n"
@@ -98,7 +98,7 @@
msgid "OK"
msgstr ""
-#: ../app/ui/HomePage.qml:30 ../app/ui/LocationsPage.qml:30
+#: ../app/ui/HomePage.qml:31 ../app/ui/LocationsPage.qml:30
msgid "Locations"
msgstr ""
=== modified file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 2015-01-23 23:15:52 +0000
+++ tests/CMakeLists.txt 2015-06-02 18:01:45 +0000
@@ -1,3 +1,1 @@
-if(NOT CLICK_MODE)
- add_subdirectory(autopilot)
-endif(NOT CLICK_MODE)
+add_subdirectory(autopilot)
=== modified file 'tests/autopilot/CMakeLists.txt'
--- tests/autopilot/CMakeLists.txt 2015-01-23 02:25:35 +0000
+++ tests/autopilot/CMakeLists.txt 2015-06-02 18:01:45 +0000
@@ -6,3 +6,5 @@
DESTINATION ${PYTHON_PACKAGE_DIR}
)
endif(INSTALL_TESTS)
+
+add_subdirectory(ubuntu_weather_app)
=== added file 'tests/autopilot/ubuntu_weather_app/CMakeLists.txt'
--- tests/autopilot/ubuntu_weather_app/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ tests/autopilot/ubuntu_weather_app/CMakeLists.txt 2015-06-02 18:01:45 +0000
@@ -0,0 +1,8 @@
+add_subdirectory(tests)
+
+# make the emulator files visible on qtcreator
+file(GLOB PYTHON_EMULATOR_FILES
+ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
+ *.py)
+
+add_custom_target(ubuntu-weather-app_PYTHONEMULATORFiles ALL SOURCES ${PYTHON_EMULATOR_FILES})
=== added file 'tests/autopilot/ubuntu_weather_app/__init__.py'
--- tests/autopilot/ubuntu_weather_app/__init__.py 1970-01-01 00:00:00 +0000
+++ tests/autopilot/ubuntu_weather_app/__init__.py 2015-06-02 18:01:45 +0000
@@ -0,0 +1,57 @@
+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
+# Copyright 2013, 2014, 2015 Canonical
+#
+# 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.
+
+"""ubuntu-weather-app tests and emulators - top level package."""
+from ubuntuuitoolkit import MainView, UbuntuUIToolkitCustomProxyObjectBase
+
+
+class UbuntuWeatherAppException(Exception):
+ """Exception raised when there's an error in the Music App."""
+
+
+def click_object(func):
+ """Wrapper which clicks the returned object"""
+ def func_wrapper(self, *args, **kwargs):
+ return self.pointing_device.click_object(func(self, *args, **kwargs))
+
+ return func_wrapper
+
+
+class UbuntuWeatherApp(object):
+ """Autopilot helper object for the Music application."""
+
+ def __init__(self, app_proxy):
+ self.app = app_proxy
+ self.main_view = self.app.wait_select_single(MainView)
+
+ def get_add_location_page(self):
+ return self.main_view.wait_select_single(
+ AddLocationPage, objectName="addLocationPage")
+
+
+class Page(UbuntuUIToolkitCustomProxyObjectBase):
+ """Autopilot helper for Pages."""
+ def __init__(self, *args):
+ super(Page, self).__init__(*args)
+ # XXX we need a better way to keep reference to the main view.
+ # --elopio - 2014-01-31
+ self.main_view = self.get_root_instance().select_single(MainView)
+
+
+class AddLocationPage(Page):
+ """Autopilot helper for AddLocationPage."""
+ def __init__(self, *args):
+ super(AddLocationPage, self).__init__(*args)
+
+
+class MainView(MainView):
+ """Autopilot custom proxy object for the MainView."""
+ retry_delay = 0.2
+
+ def __init__(self, *args):
+ super(MainView, self).__init__(*args)
+ self.visible.wait_for(True)
=== added directory 'tests/autopilot/ubuntu_weather_app/tests'
=== added file 'tests/autopilot/ubuntu_weather_app/tests/CMakeLists.txt'
--- tests/autopilot/ubuntu_weather_app/tests/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ tests/autopilot/ubuntu_weather_app/tests/CMakeLists.txt 2015-06-02 18:01:45 +0000
@@ -0,0 +1,6 @@
+# make the test files visible on qtcreator
+file(GLOB PYTHON_TEST_FILES
+ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
+ *.py)
+
+add_custom_target(ubuntu-weather-app_PYTHONTESTFiles ALL SOURCES ${PYTHON_TEST_FILES})
=== added file 'tests/autopilot/ubuntu_weather_app/tests/__init__.py'
--- tests/autopilot/ubuntu_weather_app/tests/__init__.py 1970-01-01 00:00:00 +0000
+++ tests/autopilot/ubuntu_weather_app/tests/__init__.py 2015-06-02 18:01:45 +0000
@@ -0,0 +1,150 @@
+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
+#
+# Copyright (C) 2013, 2014, 2015 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 by the Free Software Foundation.
+#
+# 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/>.
+
+"""Music app autopilot tests."""
+
+import os
+import os.path
+import shutil
+import logging
+
+import fixtures
+from ubuntu_weather_app import UbuntuWeatherApp
+
+from autopilot import logging as autopilot_logging
+from autopilot.testcase import AutopilotTestCase
+
+import ubuntuuitoolkit
+from ubuntuuitoolkit import base
+
+logger = logging.getLogger(__name__)
+
+
+class BaseTestCaseWithPatchedHome(AutopilotTestCase):
+
+ """A common test case class that provides several useful methods for
+ ubuntu-weather-app tests.
+
+ """
+
+ working_dir = os.getcwd()
+ local_location_dir = os.path.dirname(os.path.dirname(working_dir))
+ local_location = local_location_dir + "/app/ubuntu-weather-app.qml"
+ installed_location = "/usr/share/ubuntu-weather-app/app/" \
+ "ubuntu-weather-app.qml"
+
+ def get_launcher_method_and_type(self):
+ if os.path.exists(self.local_location):
+ launch = self.launch_test_local
+ test_type = 'local'
+ elif os.path.exists(self.installed_location):
+ launch = self.launch_test_installed
+ test_type = 'deb'
+ else:
+ launch = self.launch_test_click
+ test_type = 'click'
+ return launch, test_type
+
+ def setUp(self):
+ super(BaseTestCaseWithPatchedHome, self).setUp()
+ self.launcher, self.test_type = self.get_launcher_method_and_type()
+ self.home_dir = self._patch_home()
+
+ @autopilot_logging.log_action(logger.info)
+ def launch_test_local(self):
+ return self.launch_test_application(
+ base.get_qmlscene_launch_command(),
+ self.local_location,
+ "debug",
+ app_type='qt',
+ emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
+
+ @autopilot_logging.log_action(logger.info)
+ def launch_test_installed(self):
+ return self.launch_test_application(
+ base.get_qmlscene_launch_command(),
+ self.installed_location,
+ "debug",
+ app_type='qt',
+ emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
+
+ @autopilot_logging.log_action(logger.info)
+ def launch_test_click(self):
+ return self.launch_click_package(
+ "com.ubuntu.weather",
+ emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
+
+ def _copy_xauthority_file(self, directory):
+ """ Copy .Xauthority file to directory, if it exists in /home
+ """
+ # If running under xvfb, as jenkins does,
+ # xsession will fail to start without xauthority file
+ # Thus if the Xauthority file is in the home directory
+ # make sure we copy it to our temp home directory
+
+ xauth = os.path.expanduser(os.path.join(os.environ.get('HOME'),
+ '.Xauthority'))
+ if os.path.isfile(xauth):
+ logger.debug("Copying .Xauthority to %s" % directory)
+ shutil.copyfile(
+ os.path.expanduser(os.path.join(os.environ.get('HOME'),
+ '.Xauthority')),
+ os.path.join(directory, '.Xauthority'))
+
+ def _patch_home(self):
+ """ mock /home for testing purposes to preserve user data
+ """
+
+ # if running on non-phablet device,
+ # run in temp folder to avoid mucking up home
+ # bug 1316746
+ # bug 1376423
+ if self.test_type is 'click':
+ # just use home for now on devices
+ temp_dir = os.environ.get('HOME')
+
+ # before each test, remove the app's databases
+ local_dir = os.path.join(temp_dir,
+ '.local/share/com.ubuntu.weather')
+
+ if (os.path.exists(local_dir)):
+ shutil.rmtree(local_dir)
+
+ local_dir = os.path.join(temp_dir, '.config/com.ubuntu.weather')
+
+ if (os.path.exists(local_dir)):
+ shutil.rmtree(local_dir)
+ else:
+ temp_dir_fixture = fixtures.TempDir()
+ self.useFixture(temp_dir_fixture)
+ temp_dir = temp_dir_fixture.path
+
+ # before we set fixture, copy xauthority if needed
+ self._copy_xauthority_file(temp_dir)
+ self.useFixture(fixtures.EnvironmentVariable('HOME',
+ newvalue=temp_dir))
+
+ logger.debug("Patched home to fake home directory %s" % temp_dir)
+ return temp_dir
+
+
+class UbuntuWeatherAppTestCase(BaseTestCaseWithPatchedHome):
+
+ """Base test case that launches the ubuntu-weather-app."""
+
+ def setUp(self):
+ super(UbuntuWeatherAppTestCase, self).setUp()
+ self.app = UbuntuWeatherApp(self.launcher())
=== added file 'tests/autopilot/ubuntu_weather_app/tests/test_weather.py'
--- tests/autopilot/ubuntu_weather_app/tests/test_weather.py 1970-01-01 00:00:00 +0000
+++ tests/autopilot/ubuntu_weather_app/tests/test_weather.py 2015-06-02 18:01:45 +0000
@@ -0,0 +1,32 @@
+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
+# Copyright 2013, 2014, 2015 Canonical
+#
+# 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.
+
+"""Ubuntu Weather app autopilot tests."""
+
+from __future__ import absolute_import
+
+import logging
+from autopilot.matchers import Eventually
+from testtools.matchers import Equals
+
+
+from ubuntu_weather_app.tests import UbuntuWeatherAppTestCase
+
+logger = logging.getLogger(__name__)
+
+
+class TestMainWindow(UbuntuWeatherAppTestCase):
+
+ def setUp(self):
+ super(TestMainWindow, self).setUp()
+
+ def test_add_location_page_start(self):
+ """ tests that the add location page is shown on startup"""
+
+ add_location_page = self.app.get_add_location_page()
+
+ self.assertThat(add_location_page.visible, Eventually(Equals(True)))
Follow ups