Merge lp:~martin-borho/ubuntu-weather-app/more_tests into lp:ubuntu-weather-app/obsolete.trunk

Proposed by Martin Borho on 2013-06-26
Status: Merged
Approved by: Francis Ginther on 2013-06-29
Approved revision: 55
Merged at revision: 52
Proposed branch: lp:~martin-borho/ubuntu-weather-app/more_tests
Merge into: lp:ubuntu-weather-app/obsolete.trunk
Diff against target: 331 lines (+156/-28)
8 files modified
components/CurrentWeather.qml (+1/-0)
components/DateComponent.qml (+1/-0)
components/SettingsPage.qml (+2/-1)
tests/autopilot/ubuntu_weather_app/emulators/ubuntusdk.py (+14/-14)
tests/autopilot/ubuntu_weather_app/tests/test_locationmanager.py (+40/-11)
tests/autopilot/ubuntu_weather_app/tests/test_mainview.py (+16/-1)
tests/autopilot/ubuntu_weather_app/tests/test_settings.py (+70/-0)
ubuntu-weather-app.qml (+12/-1)
To merge this branch: bzr merge lp:~martin-borho/ubuntu-weather-app/more_tests
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve on 2013-06-29
Nicholas Skaggs (community) 2013-06-26 Approve on 2013-06-28
Review via email: mp+171511@code.launchpad.net

Commit message

Added more autopilot tests

Description of the change

Added more autopilot tests:

* Test city search
* Test cancel add location
* Test refresh data
* Test switching temperature scale

To post a comment you must log in.
Nicholas Skaggs (nskaggs) wrote :

Looks good Marting, keep on chugging along!

review: Approve
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'components/CurrentWeather.qml'
2--- components/CurrentWeather.qml 2013-06-09 15:42:41 +0000
3+++ components/CurrentWeather.qml 2013-06-26 11:36:31 +0000
4@@ -74,6 +74,7 @@
5 width: units.gu(17)
6 height: units.gu(10)
7 id: tempCurrent
8+ objectName: "CurrentTempText"
9 text: currentTemp+String("°")+currentWeather.scale
10 style: Text.Normal
11 font.bold: false
12
13=== modified file 'components/DateComponent.qml'
14--- components/DateComponent.qml 2013-04-20 16:17:57 +0000
15+++ components/DateComponent.qml 2013-06-26 11:36:31 +0000
16@@ -41,6 +41,7 @@
17
18 Label {
19 id: dayText
20+ objectName: "DayDateLabel"
21 height: parent.height
22 verticalAlignment: Text.AlignVCenter
23 }
24
25=== modified file 'components/SettingsPage.qml'
26--- components/SettingsPage.qml 2013-06-17 19:22:19 +0000
27+++ components/SettingsPage.qml 2013-06-26 11:36:31 +0000
28@@ -25,7 +25,7 @@
29 for(var settingName in storedSettings) {
30 settings[settingName] = storedSettings[settingName];
31 }
32- refreshData();
33+ refreshData(true);
34 });
35 settingsChanged = false;
36 }
37@@ -53,6 +53,7 @@
38 }
39 Switch {
40 id: imperialSwitch
41+ objectName: "ImperialSwitch"
42 anchors {
43 verticalCenter: parent.verticalCenter
44 right: parent.right
45
46=== modified file 'tests/autopilot/ubuntu_weather_app/emulators/ubuntusdk.py'
47--- tests/autopilot/ubuntu_weather_app/emulators/ubuntusdk.py 2013-06-20 16:14:45 +0000
48+++ tests/autopilot/ubuntu_weather_app/emulators/ubuntusdk.py 2013-06-26 11:36:31 +0000
49@@ -68,7 +68,7 @@
50 toolbar = self.get_toolbar()
51 if not toolbar.opened:
52 self.open_toolbar()
53- row = toolbar.select_single("QQuickRow")
54+ row = toolbar.select_single("ToolbarActions")
55 loaderList = row.select_many("QQuickLoader")
56 for loader in loaderList:
57 buttonList = loader.select_many("Button")
58@@ -90,9 +90,9 @@
59 """Open the toolbar"""
60 qmlView = self.get_qml_view()
61
62- lineX = qmlView.x + qmlView.width * 0.50
63- startY = qmlView.y + qmlView.height - 1
64- stopY = qmlView.y + qmlView.height * 0.95
65+ lineX = int(qmlView.x + qmlView.width * 0.50)
66+ startY = int(qmlView.y + qmlView.height - 1)
67+ stopY = int(qmlView.y + qmlView.height * 0.95)
68
69 self.autopilot.pointing_device.drag(lineX, startY, lineX, stopY)
70
71@@ -100,9 +100,9 @@
72 """Hide the toolbar"""
73 qmlView = self.get_qml_view()
74
75- lineX = qmlView.x + qmlView.width * 0.50
76- startY = qmlView.y + qmlView.height * 0.95
77- stopY = qmlView.y + qmlView.height - 1
78+ lineX = int(qmlView.x + qmlView.width * 0.50)
79+ startY = int(qmlView.y + qmlView.height * 0.95)
80+ stopY = int(qmlView.y + qmlView.height - 1)
81
82 self.autopilot.pointing_device.drag(lineX, startY, lineX, stopY)
83
84@@ -134,9 +134,9 @@
85 """Switch to the previous tab"""
86 qmlView = self.get_qml_view()
87
88- startX = qmlView.x + qmlView.width * 0.35
89- stopX = qmlView.x + qmlView.width * 0.50
90- lineY = qmlView.y + qmlView.height * 0.05
91+ startX = int(qmlView.x + qmlView.width * 0.35)
92+ stopX = int(qmlView.x + qmlView.width * 0.50)
93+ lineY = int(qmlView.y + qmlView.height * 0.05)
94
95 self.autopilot.pointing_device.drag(startX, lineY, stopX, lineY)
96 self.autopilot.pointing_device.click()
97@@ -146,9 +146,9 @@
98 """Switch to the next tab"""
99 qmlView = self.get_qml_view()
100
101- startX = qmlView.x + qmlView.width * 0.50
102- stopX = qmlView.x + qmlView.width * 0.35
103- lineY = qmlView.y + qmlView.height * 0.05
104+ startX = int(qmlView.x + qmlView.width * 0.50)
105+ stopX = int(qmlView.x + qmlView.width * 0.35)
106+ lineY = int(qmlView.y + qmlView.height * 0.05)
107
108 self.autopilot.pointing_device.drag(startX, lineY, stopX, lineY)
109- self.autopilot.pointing_device.click()
110+ self.autopilot.pointing_device.click()
111\ No newline at end of file
112
113=== modified file 'tests/autopilot/ubuntu_weather_app/tests/test_locationmanager.py'
114--- tests/autopilot/ubuntu_weather_app/tests/test_locationmanager.py 2013-06-20 11:35:52 +0000
115+++ tests/autopilot/ubuntu_weather_app/tests/test_locationmanager.py 2013-06-26 11:36:31 +0000
116@@ -33,7 +33,7 @@
117 addLocPage = self.main_window.get_object("AddLocationPage", "AddLocationPage")
118 self.assertThat(addLocPage.visible, Eventually(Equals(True)))
119
120- def test_add_location(self):
121+ def test_add_location(self):
122 """Adds a location"""
123 self._open_add_location_page()
124
125@@ -47,13 +47,12 @@
126
127 # wait for results and click on the first item
128 resultsList = self.main_window.get_object('QQuickListView', 'SearchResultList')
129- resultsModel = self.main_window.get_object('QQuickListModel', 'CitiesModel')
130 self.assertThat(resultsList.visible, Eventually(Equals(True), timeout=30))
131 firstResult = resultsList.get_children()[0].get_children()[0]
132 self.pointing_device.move_to_object(firstResult)
133 self.pointing_device.click()
134
135- # LocationManagerPage should be visible and "London" added
136+ # LocationManagerPage should be visible and "London" added
137 locationList = self.main_window.get_object('QQuickListView', 'LocationList')
138 addedItem = locationList.get_children()[0]
139 self.assertThat(addedItem.get_children()[1].text, Eventually(Equals("London")))
140@@ -67,13 +66,43 @@
141 toolbar = self.main_window.get_toolbar()
142 self.assertThat(toolbar.opened, Eventually(Equals(False)))
143
144- """no way found to click the back button"""
145- #def test_cancel_adding_location(self):
146- # self.open_add_location_page()
147- # self.main_window.click_toolbar_button("Back")
148- # locationList = self.main_window.get_object('QQuickListView', 'LocationList')
149- # self.assertThat(locationList, Eventually(Equals(True)))
150-
151+ def test_search_city(self):
152+ """Search for cities"""
153+ self._open_add_location_page()
154+
155+ # insert city name to search for
156+ searchField = self.main_window.get_object("TextField", "SearchField")
157+ self.pointing_device.move_to_object(searchField)
158+ self.pointing_device.click()
159+ self.keyboard.type("London")
160+ self.assertThat(searchField.text, Eventually(Equals("London")))
161+ self.keyboard.press_and_release('Enter')
162+
163+ # wait for results and click on the first item
164+ resultsList = self.main_window.get_object('QQuickListView', 'SearchResultList')
165+ self.assertThat(resultsList.visible, Eventually(Equals(True), timeout=30))
166+ firstResult = resultsList.get_children()[0].get_children()[0]
167+ self.assertThat(firstResult.text, Eventually(Equals("London, GB")))
168+
169+ # clear search field and do another search
170+ for x in range(6):
171+ self.keyboard.press_and_release('BackSpace')
172+ self.assertThat(searchField.text, Eventually(Equals("")))
173+ self.keyboard.type("Hanbu")
174+ for x in range(3):
175+ self.keyboard.press_and_release('BackSpace')
176+ self.keyboard.type("mburg")
177+ self.keyboard.press_and_release('Enter')
178+ firstResult = resultsList.get_children()[0].get_children()[0]
179+ self.assertThat(firstResult.text, Eventually(Equals("Hamburg, DE")))
180+
181+ def test_cancel_adding_location(self):
182+ """Cancel the cities search"""
183+ self._open_add_location_page()
184+ self.main_window.click_toolbar_button("Back")
185+ locationList = self.main_window.get_object('QQuickListView', 'LocationList')
186+ self.assertThat(locationList.visible, Eventually(Equals(True)))
187+
188 class TestLocationManagerWithLocation(WeatherTestCase, DatabaseMixin):
189 def setUp(self):
190 self.clean_db()
191@@ -97,7 +126,7 @@
192 self.assertThat(loadingPage.visible, Eventually(Equals(False)))
193
194 # go to the location manegr
195- self._open_location_manager()
196+ self._open_location_manager()
197
198 # swipe right to delete the first location
199 locationList = self.main_window.get_object('QQuickListView', 'LocationList')
200
201=== modified file 'tests/autopilot/ubuntu_weather_app/tests/test_mainview.py'
202--- tests/autopilot/ubuntu_weather_app/tests/test_mainview.py 2013-06-20 11:18:17 +0000
203+++ tests/autopilot/ubuntu_weather_app/tests/test_mainview.py 2013-06-26 11:36:31 +0000
204@@ -32,7 +32,7 @@
205 super(TestMainView, self).tearDown()
206
207 def test_switch_tabs(self):
208- """Test start of app with two locations and switch from first to
209+ """Test start of app with two locations and switch from first to
210 second tab"""
211 # first tab should be visible after start
212 tabs = self.main_window.get_tabs()
213@@ -48,3 +48,18 @@
214 self.assertThat(tabObjects[1].visible, Eventually(Equals(True)))
215 self.assertThat(tabObjects[1].title, Eventually(Equals("Hamburg")))
216
217+ def test_refresh_tabs(self):
218+ # get the dates from the test data
219+ curr_dates = self.main_window.get_objects('Label','DayDateLabel')
220+ tab1_curr_date = curr_dates[0].text
221+ tab2_curr_date = curr_dates[1].text
222+
223+ # refresh and wait till loading has finished
224+ self.main_window.click_toolbar_button("Refresh")
225+ load_indicator = self.main_window.get_object('ActivityIndicator', 'LoadingSpinner')
226+ self.assertThat(load_indicator.running, Eventually(Equals(False)))
227+
228+ # get the data from the refreshed tabs, have to be new
229+ refreshed_dates = self.main_window.get_objects('Label','DayDateLabel')
230+ self.assertNotEqual(tab1_curr_date, refreshed_dates[0].text)
231+ self.assertNotEqual(tab2_curr_date, refreshed_dates[1].text)
232
233=== added file 'tests/autopilot/ubuntu_weather_app/tests/test_settings.py'
234--- tests/autopilot/ubuntu_weather_app/tests/test_settings.py 1970-01-01 00:00:00 +0000
235+++ tests/autopilot/ubuntu_weather_app/tests/test_settings.py 2013-06-26 11:36:31 +0000
236@@ -0,0 +1,70 @@
237+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
238+# Copyright 2013 Canonical
239+#
240+# This program is free software: you can redistribute it and/or modify it
241+# under the terms of the GNU General Public License version 3, as published
242+# by the Free Software Foundation.
243+
244+"""Tests for managing locations in Weather app"""
245+
246+from __future__ import absolute_import
247+
248+from testtools.matchers import Equals
249+from autopilot.matchers import Eventually
250+
251+from ubuntu_weather_app.tests import WeatherTestCase, DatabaseMixin
252+from ubuntu_weather_app.tests.weatherdata import locations_data
253+
254+class TestSettings(WeatherTestCase, DatabaseMixin):
255+ def setUp(self):
256+ self.clean_db()
257+ self.launch_and_quit_app()
258+ self.save_locations_to_storage(locations_data)
259+ super(TestSettings, self).setUp()
260+ self.assertThat(
261+ self.main_window.get_qml_view().visible, Eventually(Equals(True)))
262+
263+ def _open_settings_page(self):
264+ """Opens the settings page"""
265+ self.main_window.open_toolbar()
266+ self.assertThat(self.main_window.get_toolbar().opened, Eventually(Equals(True)))
267+ self.main_window.click_toolbar_button("Settings")
268+
269+ def test_switch_scale(self):
270+ """Tests switching the scale in the settings"""
271+ # first check metric values
272+ current_temps = self.main_window.get_objects('QQuickText', 'CurrentTempText')
273+ self.assertThat(current_temps[0].text, Eventually(Equals(u'21°C')))
274+ self.assertThat(current_temps[1].text, Eventually(Equals(u'26°C')))
275+
276+ # open the settings and switch to imperial
277+ self._open_settings_page()
278+ switch = self.main_window.get_object('CheckBox', 'ImperialSwitch')
279+ self.assertThat(switch.visible, Eventually(Equals(True)))
280+ self.assertThat(switch.checked, Eventually(Equals(False)))
281+ self.pointing_device.click_object(switch)
282+ self.assertThat(switch.checked, Eventually(Equals(True)))
283+ self.main_window.click_toolbar_button("Back")
284+
285+ # wait for reload and check the imperial values
286+ load_indicator = self.main_window.get_object('ActivityIndicator', 'LoadingSpinner')
287+ self.assertThat(load_indicator.running, Eventually(Equals(False)))
288+ current_temps = self.main_window.get_objects('QQuickText', 'CurrentTempText')
289+ self.assertThat(current_temps[0].text, Eventually(Equals(u'69°F')))
290+ self.assertThat(current_temps[1].text, Eventually(Equals(u'78°F')))
291+
292+ # switch back to metric values again
293+ self._open_settings_page()
294+ switch = self.main_window.get_object('CheckBox', 'ImperialSwitch')
295+ self.assertThat(switch.visible, Eventually(Equals(True)))
296+ self.assertThat(switch.checked, Eventually(Equals(True)))
297+ self.pointing_device.click_object(switch)
298+ self.assertThat(switch.checked, Eventually(Equals(False)))
299+ self.main_window.click_toolbar_button("Back")
300+
301+ # wait for reload and check the metric values again
302+ load_indicator = self.main_window.get_object('ActivityIndicator', 'LoadingSpinner')
303+ self.assertThat(load_indicator.running, Eventually(Equals(False)))
304+ current_temps = self.main_window.get_objects('QQuickText', 'CurrentTempText')
305+ self.assertThat(current_temps[0].text, Eventually(Equals(u'21°C')))
306+ self.assertThat(current_temps[1].text, Eventually(Equals(u'26°C')))
307\ No newline at end of file
308
309=== modified file 'ubuntu-weather-app.qml'
310--- ubuntu-weather-app.qml 2013-06-20 16:10:56 +0000
311+++ ubuntu-weather-app.qml 2013-06-26 11:36:31 +0000
312@@ -132,7 +132,18 @@
313 Page {
314 id: tabPage
315 visible: false
316- ActivityIndicator{id:loading; running: false; z: 1; anchors{top: parent.top; topMargin: units.gu(0.5); right: parent.right; rightMargin: units.gu(1)}}
317+ ActivityIndicator{
318+ id:loading
319+ objectName: "LoadingSpinner"
320+ running: false
321+ z: 1
322+ anchors{
323+ top: parent.top
324+ topMargin: units.gu(0.5)
325+ right: parent.right
326+ rightMargin: units.gu(1)
327+ }
328+ }
329 Tabs {
330 id: tabs
331 objectName: "LoadingTabs"

Subscribers

People subscribed via source and target branches