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
=== modified file 'app/ui/AddLocationPage.qml'
--- app/ui/AddLocationPage.qml 2015-05-09 22:29:05 +0000
+++ app/ui/AddLocationPage.qml 2015-06-03 17:50:01 +0000
@@ -26,7 +26,7 @@
2626
27Page {27Page {
28 id: addLocationPage28 id: addLocationPage
2929 objectName: "addLocationPage"
30 title: i18n.tr("Select a city")30 title: i18n.tr("Select a city")
31 visible: false31 visible: false
3232
3333
=== modified file 'app/ui/HomePage.qml'
--- app/ui/HomePage.qml 2015-04-29 14:22:00 +0000
+++ app/ui/HomePage.qml 2015-06-03 17:50:01 +0000
@@ -24,6 +24,7 @@
24PageWithBottomEdge {24PageWithBottomEdge {
25 // Set to null otherwise the header is shown (but blank) over the top of the listview25 // Set to null otherwise the header is shown (but blank) over the top of the listview
26 id: locationPage26 id: locationPage
27 objectName: "homePage"
27 flickable: null28 flickable: null
2829
29 bottomEdgePageSource: Qt.resolvedUrl("LocationsPage.qml")30 bottomEdgePageSource: Qt.resolvedUrl("LocationsPage.qml")
3031
=== 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-03 17:50:01 +0000
@@ -8,7 +8,7 @@
8msgstr ""8msgstr ""
9"Project-Id-Version: ubuntu-weather-app\n"9"Project-Id-Version: ubuntu-weather-app\n"
10"Report-Msgid-Bugs-To: \n"10"Report-Msgid-Bugs-To: \n"
11"POT-Creation-Date: 2015-05-21 19:13-0500\n"11"POT-Creation-Date: 2015-05-29 05:21+0100\n"
12"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"12"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"13"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14"Language-Team: LANGUAGE <LL@li.org>\n"14"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -98,7 +98,7 @@
98msgid "OK"98msgid "OK"
99msgstr ""99msgstr ""
100100
101#: ../app/ui/HomePage.qml:30 ../app/ui/LocationsPage.qml:30101#: ../app/ui/HomePage.qml:31 ../app/ui/LocationsPage.qml:30
102msgid "Locations"102msgid "Locations"
103msgstr ""103msgstr ""
104104
105105
=== modified file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 2015-01-23 23:15:52 +0000
+++ tests/CMakeLists.txt 2015-06-03 17:50:01 +0000
@@ -1,3 +1,1 @@
1if(NOT CLICK_MODE)1add_subdirectory(autopilot)
2 add_subdirectory(autopilot)
3endif(NOT CLICK_MODE)
42
=== modified file 'tests/autopilot/CMakeLists.txt'
--- tests/autopilot/CMakeLists.txt 2015-01-23 02:25:35 +0000
+++ tests/autopilot/CMakeLists.txt 2015-06-03 17:50:01 +0000
@@ -6,3 +6,5 @@
6 DESTINATION ${PYTHON_PACKAGE_DIR}6 DESTINATION ${PYTHON_PACKAGE_DIR}
7 )7 )
8endif(INSTALL_TESTS)8endif(INSTALL_TESTS)
9
10add_subdirectory(ubuntu_weather_app)
911
=== 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-03 17:50:01 +0000
@@ -0,0 +1,8 @@
1add_subdirectory(tests)
2
3# make the emulator files visible on qtcreator
4file(GLOB PYTHON_EMULATOR_FILES
5 RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
6 *.py)
7
8add_custom_target(ubuntu-weather-app_PYTHONEMULATORFiles ALL SOURCES ${PYTHON_EMULATOR_FILES})
09
=== 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-03 17:50:01 +0000
@@ -0,0 +1,54 @@
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2# Copyright 2013, 2014, 2015 Canonical
3#
4# This program is free software: you can redistribute it and/or modify it
5# under the terms of the GNU General Public License version 3, as published
6# by the Free Software Foundation.
7
8"""ubuntu-weather-app tests and emulators - top level package."""
9from ubuntuuitoolkit import MainView, UbuntuUIToolkitCustomProxyObjectBase
10
11
12class UbuntuWeatherAppException(Exception):
13 """Exception raised when there's an error in the Weather App."""
14
15
16def click_object(func):
17 """Wrapper which clicks the returned object"""
18 def func_wrapper(self, *args, **kwargs):
19 return self.pointing_device.click_object(func(self, *args, **kwargs))
20
21 return func_wrapper
22
23
24class UbuntuWeatherApp(object):
25 """Autopilot helper object for the Weather application."""
26
27 def __init__(self, app_proxy):
28 self.app = app_proxy
29 self.main_view = self.app.wait_select_single(MainView)
30
31 def get_add_location_page(self):
32 return self.main_view.wait_select_single(
33 AddLocationPage, objectName="addLocationPage")
34
35
36class Page(UbuntuUIToolkitCustomProxyObjectBase):
37 """Autopilot helper for Pages."""
38 def __init__(self, *args):
39 super(Page, self).__init__(*args)
40
41
42class AddLocationPage(Page):
43 """Autopilot helper for AddLocationPage."""
44 def __init__(self, *args):
45 super(AddLocationPage, self).__init__(*args)
46
47
48class MainView(MainView):
49 """Autopilot custom proxy object for the MainView."""
50 retry_delay = 0.2
51
52 def __init__(self, *args):
53 super(MainView, self).__init__(*args)
54 self.visible.wait_for(True)
055
=== 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-03 17:50:01 +0000
@@ -0,0 +1,6 @@
1# make the test files visible on qtcreator
2file(GLOB PYTHON_TEST_FILES
3 RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
4 *.py)
5
6add_custom_target(ubuntu-weather-app_PYTHONTESTFiles ALL SOURCES ${PYTHON_TEST_FILES})
07
=== 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-03 17:50:01 +0000
@@ -0,0 +1,150 @@
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2#
3# Copyright (C) 2013, 2014, 2015 Canonical Ltd
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License version 3 as
7# published by the Free Software Foundation.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17"""Weather app autopilot tests."""
18
19import os
20import os.path
21import shutil
22import logging
23
24import fixtures
25from ubuntu_weather_app import UbuntuWeatherApp
26
27from autopilot import logging as autopilot_logging
28from autopilot.testcase import AutopilotTestCase
29
30import ubuntuuitoolkit
31from ubuntuuitoolkit import base
32
33logger = logging.getLogger(__name__)
34
35
36class BaseTestCaseWithPatchedHome(AutopilotTestCase):
37
38 """A common test case class that provides several useful methods for
39 ubuntu-weather-app tests.
40
41 """
42
43 working_dir = os.getcwd()
44 local_location_dir = os.path.dirname(os.path.dirname(working_dir))
45 local_location = local_location_dir + "/app/ubuntu-weather-app.qml"
46 installed_location = "/usr/share/ubuntu-weather-app/app/" \
47 "ubuntu-weather-app.qml"
48
49 def get_launcher_method_and_type(self):
50 if os.path.exists(self.local_location):
51 launch = self.launch_test_local
52 test_type = 'local'
53 elif os.path.exists(self.installed_location):
54 launch = self.launch_test_installed
55 test_type = 'deb'
56 else:
57 launch = self.launch_test_click
58 test_type = 'click'
59 return launch, test_type
60
61 def setUp(self):
62 super(BaseTestCaseWithPatchedHome, self).setUp()
63 self.launcher, self.test_type = self.get_launcher_method_and_type()
64 self.home_dir = self._patch_home()
65
66 @autopilot_logging.log_action(logger.info)
67 def launch_test_local(self):
68 return self.launch_test_application(
69 base.get_qmlscene_launch_command(),
70 self.local_location,
71 "debug",
72 app_type='qt',
73 emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
74
75 @autopilot_logging.log_action(logger.info)
76 def launch_test_installed(self):
77 return self.launch_test_application(
78 base.get_qmlscene_launch_command(),
79 self.installed_location,
80 "debug",
81 app_type='qt',
82 emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
83
84 @autopilot_logging.log_action(logger.info)
85 def launch_test_click(self):
86 return self.launch_click_package(
87 "com.ubuntu.weather",
88 emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
89
90 def _copy_xauthority_file(self, directory):
91 """ Copy .Xauthority file to directory, if it exists in /home
92 """
93 # If running under xvfb, as jenkins does,
94 # xsession will fail to start without xauthority file
95 # Thus if the Xauthority file is in the home directory
96 # make sure we copy it to our temp home directory
97
98 xauth = os.path.expanduser(os.path.join(os.environ.get('HOME'),
99 '.Xauthority'))
100 if os.path.isfile(xauth):
101 logger.debug("Copying .Xauthority to %s" % directory)
102 shutil.copyfile(
103 os.path.expanduser(os.path.join(os.environ.get('HOME'),
104 '.Xauthority')),
105 os.path.join(directory, '.Xauthority'))
106
107 def _patch_home(self):
108 """ mock /home for testing purposes to preserve user data
109 """
110
111 # if running on non-phablet device,
112 # run in temp folder to avoid mucking up home
113 # bug 1316746
114 # bug 1376423
115 if self.test_type is 'click':
116 # just use home for now on devices
117 temp_dir = os.environ.get('HOME')
118
119 # before each test, remove the app's databases
120 local_dir = os.path.join(temp_dir,
121 '.local/share/com.ubuntu.weather')
122
123 if (os.path.exists(local_dir)):
124 shutil.rmtree(local_dir)
125
126 local_dir = os.path.join(temp_dir, '.config/com.ubuntu.weather')
127
128 if (os.path.exists(local_dir)):
129 shutil.rmtree(local_dir)
130 else:
131 temp_dir_fixture = fixtures.TempDir()
132 self.useFixture(temp_dir_fixture)
133 temp_dir = temp_dir_fixture.path
134
135 # before we set fixture, copy xauthority if needed
136 self._copy_xauthority_file(temp_dir)
137 self.useFixture(fixtures.EnvironmentVariable('HOME',
138 newvalue=temp_dir))
139
140 logger.debug("Patched home to fake home directory %s" % temp_dir)
141 return temp_dir
142
143
144class UbuntuWeatherAppTestCase(BaseTestCaseWithPatchedHome):
145
146 """Base test case that launches the ubuntu-weather-app."""
147
148 def setUp(self):
149 super(UbuntuWeatherAppTestCase, self).setUp()
150 self.app = UbuntuWeatherApp(self.launcher())
0151
=== 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-03 17:50:01 +0000
@@ -0,0 +1,32 @@
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2# Copyright 2013, 2014, 2015 Canonical
3#
4# This program is free software: you can redistribute it and/or modify it
5# under the terms of the GNU General Public License version 3, as published
6# by the Free Software Foundation.
7
8"""Ubuntu Weather app autopilot tests."""
9
10from __future__ import absolute_import
11
12import logging
13from autopilot.matchers import Eventually
14from testtools.matchers import Equals
15
16
17from ubuntu_weather_app.tests import UbuntuWeatherAppTestCase
18
19logger = logging.getLogger(__name__)
20
21
22class TestMainWindow(UbuntuWeatherAppTestCase):
23
24 def setUp(self):
25 super(TestMainWindow, self).setUp()
26
27 def test_add_location_page_start(self):
28 """ tests that the add location page is shown on startup"""
29
30 add_location_page = self.app.get_add_location_page()
31
32 self.assertThat(add_location_page.visible, Eventually(Equals(True)))

Subscribers

People subscribed via source and target branches

to all changes: