Merge lp:~ahayzen/ubuntu-weather-app/reboot-add-base-for-autopilot-tests into lp:ubuntu-weather-app

Proposed by Andrew Hayzen
Status: Merged
Approved by: Victor Thompson
Approved revision: 40
Merged at revision: 46
Proposed branch: lp:~ahayzen/ubuntu-weather-app/reboot-add-base-for-autopilot-tests
Merge into: lp:ubuntu-weather-app
Diff against target: 341 lines (+257/-6)
10 files modified
app/ui/AddLocationPage.qml (+1/-1)
app/ui/HomePage.qml (+1/-0)
po/com.ubuntu.weather.pot (+2/-2)
tests/CMakeLists.txt (+1/-3)
tests/autopilot/CMakeLists.txt (+2/-0)
tests/autopilot/ubuntu_weather_app/CMakeLists.txt (+8/-0)
tests/autopilot/ubuntu_weather_app/__init__.py (+54/-0)
tests/autopilot/ubuntu_weather_app/tests/CMakeLists.txt (+6/-0)
tests/autopilot/ubuntu_weather_app/tests/__init__.py (+150/-0)
tests/autopilot/ubuntu_weather_app/tests/test_weather.py (+32/-0)
To merge this branch: bzr merge lp:~ahayzen/ubuntu-weather-app/reboot-add-base-for-autopilot-tests
Reviewer Review Type Date Requested Status
Victor Thompson Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Review via email: mp+260868@code.launchpad.net

Commit message

* First cut of adding autopilot tests to ubuntu-weather-app reboot

Description of the change

* First cut of adding autopilot tests to ubuntu-weather-app reboot

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Victor Thompson (vthompson) wrote :

Needs fixing. See inline comments.

review: Needs Fixing
40. By Andrew Hayzen

* Remove any instances of the term "music"
* Remove unused self.main_view in Page

Revision history for this message
Andrew Hayzen (ahayzen) wrote :

Removed all the instances of "music" (can't tell where I hijacked my code from can you?), removed the self.main_view part that had the comment with no bug number as it isn't used. Not sure about the licensing dates as the code has literally been copied.

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Victor Thompson (vthompson) wrote :

lgtm! We'll probably iterate over some of the initial test setup as we provide more tests.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'app/ui/AddLocationPage.qml'
2--- app/ui/AddLocationPage.qml 2015-05-09 22:29:05 +0000
3+++ app/ui/AddLocationPage.qml 2015-06-03 17:50:01 +0000
4@@ -26,7 +26,7 @@
5
6 Page {
7 id: addLocationPage
8-
9+ objectName: "addLocationPage"
10 title: i18n.tr("Select a city")
11 visible: false
12
13
14=== modified file 'app/ui/HomePage.qml'
15--- app/ui/HomePage.qml 2015-04-29 14:22:00 +0000
16+++ app/ui/HomePage.qml 2015-06-03 17:50:01 +0000
17@@ -24,6 +24,7 @@
18 PageWithBottomEdge {
19 // Set to null otherwise the header is shown (but blank) over the top of the listview
20 id: locationPage
21+ objectName: "homePage"
22 flickable: null
23
24 bottomEdgePageSource: Qt.resolvedUrl("LocationsPage.qml")
25
26=== modified file 'po/com.ubuntu.weather.pot'
27--- po/com.ubuntu.weather.pot 2015-05-22 00:13:54 +0000
28+++ po/com.ubuntu.weather.pot 2015-06-03 17:50:01 +0000
29@@ -8,7 +8,7 @@
30 msgstr ""
31 "Project-Id-Version: ubuntu-weather-app\n"
32 "Report-Msgid-Bugs-To: \n"
33-"POT-Creation-Date: 2015-05-21 19:13-0500\n"
34+"POT-Creation-Date: 2015-05-29 05:21+0100\n"
35 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
36 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
37 "Language-Team: LANGUAGE <LL@li.org>\n"
38@@ -98,7 +98,7 @@
39 msgid "OK"
40 msgstr ""
41
42-#: ../app/ui/HomePage.qml:30 ../app/ui/LocationsPage.qml:30
43+#: ../app/ui/HomePage.qml:31 ../app/ui/LocationsPage.qml:30
44 msgid "Locations"
45 msgstr ""
46
47
48=== modified file 'tests/CMakeLists.txt'
49--- tests/CMakeLists.txt 2015-01-23 23:15:52 +0000
50+++ tests/CMakeLists.txt 2015-06-03 17:50:01 +0000
51@@ -1,3 +1,1 @@
52-if(NOT CLICK_MODE)
53- add_subdirectory(autopilot)
54-endif(NOT CLICK_MODE)
55+add_subdirectory(autopilot)
56
57=== modified file 'tests/autopilot/CMakeLists.txt'
58--- tests/autopilot/CMakeLists.txt 2015-01-23 02:25:35 +0000
59+++ tests/autopilot/CMakeLists.txt 2015-06-03 17:50:01 +0000
60@@ -6,3 +6,5 @@
61 DESTINATION ${PYTHON_PACKAGE_DIR}
62 )
63 endif(INSTALL_TESTS)
64+
65+add_subdirectory(ubuntu_weather_app)
66
67=== added file 'tests/autopilot/ubuntu_weather_app/CMakeLists.txt'
68--- tests/autopilot/ubuntu_weather_app/CMakeLists.txt 1970-01-01 00:00:00 +0000
69+++ tests/autopilot/ubuntu_weather_app/CMakeLists.txt 2015-06-03 17:50:01 +0000
70@@ -0,0 +1,8 @@
71+add_subdirectory(tests)
72+
73+# make the emulator files visible on qtcreator
74+file(GLOB PYTHON_EMULATOR_FILES
75+ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
76+ *.py)
77+
78+add_custom_target(ubuntu-weather-app_PYTHONEMULATORFiles ALL SOURCES ${PYTHON_EMULATOR_FILES})
79
80=== added file 'tests/autopilot/ubuntu_weather_app/__init__.py'
81--- tests/autopilot/ubuntu_weather_app/__init__.py 1970-01-01 00:00:00 +0000
82+++ tests/autopilot/ubuntu_weather_app/__init__.py 2015-06-03 17:50:01 +0000
83@@ -0,0 +1,54 @@
84+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
85+# Copyright 2013, 2014, 2015 Canonical
86+#
87+# This program is free software: you can redistribute it and/or modify it
88+# under the terms of the GNU General Public License version 3, as published
89+# by the Free Software Foundation.
90+
91+"""ubuntu-weather-app tests and emulators - top level package."""
92+from ubuntuuitoolkit import MainView, UbuntuUIToolkitCustomProxyObjectBase
93+
94+
95+class UbuntuWeatherAppException(Exception):
96+ """Exception raised when there's an error in the Weather App."""
97+
98+
99+def click_object(func):
100+ """Wrapper which clicks the returned object"""
101+ def func_wrapper(self, *args, **kwargs):
102+ return self.pointing_device.click_object(func(self, *args, **kwargs))
103+
104+ return func_wrapper
105+
106+
107+class UbuntuWeatherApp(object):
108+ """Autopilot helper object for the Weather application."""
109+
110+ def __init__(self, app_proxy):
111+ self.app = app_proxy
112+ self.main_view = self.app.wait_select_single(MainView)
113+
114+ def get_add_location_page(self):
115+ return self.main_view.wait_select_single(
116+ AddLocationPage, objectName="addLocationPage")
117+
118+
119+class Page(UbuntuUIToolkitCustomProxyObjectBase):
120+ """Autopilot helper for Pages."""
121+ def __init__(self, *args):
122+ super(Page, self).__init__(*args)
123+
124+
125+class AddLocationPage(Page):
126+ """Autopilot helper for AddLocationPage."""
127+ def __init__(self, *args):
128+ super(AddLocationPage, self).__init__(*args)
129+
130+
131+class MainView(MainView):
132+ """Autopilot custom proxy object for the MainView."""
133+ retry_delay = 0.2
134+
135+ def __init__(self, *args):
136+ super(MainView, self).__init__(*args)
137+ self.visible.wait_for(True)
138
139=== added directory 'tests/autopilot/ubuntu_weather_app/tests'
140=== added file 'tests/autopilot/ubuntu_weather_app/tests/CMakeLists.txt'
141--- tests/autopilot/ubuntu_weather_app/tests/CMakeLists.txt 1970-01-01 00:00:00 +0000
142+++ tests/autopilot/ubuntu_weather_app/tests/CMakeLists.txt 2015-06-03 17:50:01 +0000
143@@ -0,0 +1,6 @@
144+# make the test files visible on qtcreator
145+file(GLOB PYTHON_TEST_FILES
146+ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
147+ *.py)
148+
149+add_custom_target(ubuntu-weather-app_PYTHONTESTFiles ALL SOURCES ${PYTHON_TEST_FILES})
150
151=== added file 'tests/autopilot/ubuntu_weather_app/tests/__init__.py'
152--- tests/autopilot/ubuntu_weather_app/tests/__init__.py 1970-01-01 00:00:00 +0000
153+++ tests/autopilot/ubuntu_weather_app/tests/__init__.py 2015-06-03 17:50:01 +0000
154@@ -0,0 +1,150 @@
155+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
156+#
157+# Copyright (C) 2013, 2014, 2015 Canonical Ltd
158+#
159+# This program is free software: you can redistribute it and/or modify
160+# it under the terms of the GNU General Public License version 3 as
161+# published by the Free Software Foundation.
162+#
163+# This program is distributed in the hope that it will be useful,
164+# but WITHOUT ANY WARRANTY; without even the implied warranty of
165+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
166+# GNU General Public License for more details.
167+#
168+# You should have received a copy of the GNU General Public License
169+# along with this program. If not, see <http://www.gnu.org/licenses/>.
170+
171+"""Weather app autopilot tests."""
172+
173+import os
174+import os.path
175+import shutil
176+import logging
177+
178+import fixtures
179+from ubuntu_weather_app import UbuntuWeatherApp
180+
181+from autopilot import logging as autopilot_logging
182+from autopilot.testcase import AutopilotTestCase
183+
184+import ubuntuuitoolkit
185+from ubuntuuitoolkit import base
186+
187+logger = logging.getLogger(__name__)
188+
189+
190+class BaseTestCaseWithPatchedHome(AutopilotTestCase):
191+
192+ """A common test case class that provides several useful methods for
193+ ubuntu-weather-app tests.
194+
195+ """
196+
197+ working_dir = os.getcwd()
198+ local_location_dir = os.path.dirname(os.path.dirname(working_dir))
199+ local_location = local_location_dir + "/app/ubuntu-weather-app.qml"
200+ installed_location = "/usr/share/ubuntu-weather-app/app/" \
201+ "ubuntu-weather-app.qml"
202+
203+ def get_launcher_method_and_type(self):
204+ if os.path.exists(self.local_location):
205+ launch = self.launch_test_local
206+ test_type = 'local'
207+ elif os.path.exists(self.installed_location):
208+ launch = self.launch_test_installed
209+ test_type = 'deb'
210+ else:
211+ launch = self.launch_test_click
212+ test_type = 'click'
213+ return launch, test_type
214+
215+ def setUp(self):
216+ super(BaseTestCaseWithPatchedHome, self).setUp()
217+ self.launcher, self.test_type = self.get_launcher_method_and_type()
218+ self.home_dir = self._patch_home()
219+
220+ @autopilot_logging.log_action(logger.info)
221+ def launch_test_local(self):
222+ return self.launch_test_application(
223+ base.get_qmlscene_launch_command(),
224+ self.local_location,
225+ "debug",
226+ app_type='qt',
227+ emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
228+
229+ @autopilot_logging.log_action(logger.info)
230+ def launch_test_installed(self):
231+ return self.launch_test_application(
232+ base.get_qmlscene_launch_command(),
233+ self.installed_location,
234+ "debug",
235+ app_type='qt',
236+ emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
237+
238+ @autopilot_logging.log_action(logger.info)
239+ def launch_test_click(self):
240+ return self.launch_click_package(
241+ "com.ubuntu.weather",
242+ emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
243+
244+ def _copy_xauthority_file(self, directory):
245+ """ Copy .Xauthority file to directory, if it exists in /home
246+ """
247+ # If running under xvfb, as jenkins does,
248+ # xsession will fail to start without xauthority file
249+ # Thus if the Xauthority file is in the home directory
250+ # make sure we copy it to our temp home directory
251+
252+ xauth = os.path.expanduser(os.path.join(os.environ.get('HOME'),
253+ '.Xauthority'))
254+ if os.path.isfile(xauth):
255+ logger.debug("Copying .Xauthority to %s" % directory)
256+ shutil.copyfile(
257+ os.path.expanduser(os.path.join(os.environ.get('HOME'),
258+ '.Xauthority')),
259+ os.path.join(directory, '.Xauthority'))
260+
261+ def _patch_home(self):
262+ """ mock /home for testing purposes to preserve user data
263+ """
264+
265+ # if running on non-phablet device,
266+ # run in temp folder to avoid mucking up home
267+ # bug 1316746
268+ # bug 1376423
269+ if self.test_type is 'click':
270+ # just use home for now on devices
271+ temp_dir = os.environ.get('HOME')
272+
273+ # before each test, remove the app's databases
274+ local_dir = os.path.join(temp_dir,
275+ '.local/share/com.ubuntu.weather')
276+
277+ if (os.path.exists(local_dir)):
278+ shutil.rmtree(local_dir)
279+
280+ local_dir = os.path.join(temp_dir, '.config/com.ubuntu.weather')
281+
282+ if (os.path.exists(local_dir)):
283+ shutil.rmtree(local_dir)
284+ else:
285+ temp_dir_fixture = fixtures.TempDir()
286+ self.useFixture(temp_dir_fixture)
287+ temp_dir = temp_dir_fixture.path
288+
289+ # before we set fixture, copy xauthority if needed
290+ self._copy_xauthority_file(temp_dir)
291+ self.useFixture(fixtures.EnvironmentVariable('HOME',
292+ newvalue=temp_dir))
293+
294+ logger.debug("Patched home to fake home directory %s" % temp_dir)
295+ return temp_dir
296+
297+
298+class UbuntuWeatherAppTestCase(BaseTestCaseWithPatchedHome):
299+
300+ """Base test case that launches the ubuntu-weather-app."""
301+
302+ def setUp(self):
303+ super(UbuntuWeatherAppTestCase, self).setUp()
304+ self.app = UbuntuWeatherApp(self.launcher())
305
306=== added file 'tests/autopilot/ubuntu_weather_app/tests/test_weather.py'
307--- tests/autopilot/ubuntu_weather_app/tests/test_weather.py 1970-01-01 00:00:00 +0000
308+++ tests/autopilot/ubuntu_weather_app/tests/test_weather.py 2015-06-03 17:50:01 +0000
309@@ -0,0 +1,32 @@
310+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
311+# Copyright 2013, 2014, 2015 Canonical
312+#
313+# This program is free software: you can redistribute it and/or modify it
314+# under the terms of the GNU General Public License version 3, as published
315+# by the Free Software Foundation.
316+
317+"""Ubuntu Weather app autopilot tests."""
318+
319+from __future__ import absolute_import
320+
321+import logging
322+from autopilot.matchers import Eventually
323+from testtools.matchers import Equals
324+
325+
326+from ubuntu_weather_app.tests import UbuntuWeatherAppTestCase
327+
328+logger = logging.getLogger(__name__)
329+
330+
331+class TestMainWindow(UbuntuWeatherAppTestCase):
332+
333+ def setUp(self):
334+ super(TestMainWindow, self).setUp()
335+
336+ def test_add_location_page_start(self):
337+ """ tests that the add location page is shown on startup"""
338+
339+ add_location_page = self.app.get_add_location_page()
340+
341+ self.assertThat(add_location_page.visible, Eventually(Equals(True)))

Subscribers

People subscribed via source and target branches

to all changes: