Merge lp:~nskaggs/ubuntu-weather-app/swipe-delete-ap-tests into lp:ubuntu-weather-app/obsolete.trunk

Proposed by Nicholas Skaggs
Status: Merged
Approved by: Nicholas Skaggs
Approved revision: 167
Merged at revision: 163
Proposed branch: lp:~nskaggs/ubuntu-weather-app/swipe-delete-ap-tests
Merge into: lp:ubuntu-weather-app/obsolete.trunk
Diff against target: 407 lines (+90/-164)
2 files modified
tests/autopilot/ubuntu_weather_app/tests/__init__.py (+1/-2)
tests/autopilot/ubuntu_weather_app/tests/test_locationmanager.py (+89/-162)
To merge this branch: bzr merge lp:~nskaggs/ubuntu-weather-app/swipe-delete-ap-tests
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Ubuntu Weather Developers Pending
Review via email: mp+198482@code.launchpad.net

Commit message

Fix test_del_add_bug test, simplify tests, re-enable disabled tests

Description of the change

To post a comment you must log in.
167. By Nicholas Skaggs

remove more extraneous stuff :-)

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/autopilot/ubuntu_weather_app/tests/__init__.py'
2--- tests/autopilot/ubuntu_weather_app/tests/__init__.py 2013-11-05 19:50:18 +0000
3+++ tests/autopilot/ubuntu_weather_app/tests/__init__.py 2013-12-11 01:10:20 +0000
4@@ -118,8 +118,7 @@
5 def _open_add_location_page(self):
6 """Opens the AddLocationPage"""
7 # click on listitem to open AddLocationPage
8- self.assertThat(lambda: self.main_window.select_single('Standard', objectName='AddCityListItem'), Eventually(Not(Is(None))))
9- addCityItem = self.main_window.select_single('Standard', objectName='AddCityListItem')
10+ addCityItem = self.main_window.wait_select_single('Standard', objectName='AddCityListItem')
11 self.assertThat(lambda: addCityItem.visible, Eventually(Equals(True)))
12 self.pointing_device.move_to_object(addCityItem)
13 self.pointing_device.click()
14
15=== modified file 'tests/autopilot/ubuntu_weather_app/tests/test_locationmanager.py'
16--- tests/autopilot/ubuntu_weather_app/tests/test_locationmanager.py 2013-11-12 22:29:11 +0000
17+++ tests/autopilot/ubuntu_weather_app/tests/test_locationmanager.py 2013-12-11 01:10:20 +0000
18@@ -26,10 +26,36 @@
19 self.assertThat(
20 self.get_qml_view().visible, Eventually(Equals(True)))
21
22- def search_for_city(self, city):
23- self.assertThat(lambda: self.main_window.select_single('TextField', objectName='SearchField'),
24- Eventually(Not(Is(None))))
25- searchField = self.main_window.select_single("TextField", objectName="SearchField")
26+ def _preload_database_and_relaunch(self):
27+ self.clean_db()
28+ self.launch_and_quit_app()
29+ # add one location to storage
30+ self.save_locations_to_storage(locations_data)
31+ super(TestLocationManager, self).setUp()
32+ self.assertThat(
33+ self.get_qml_view().visible, Eventually(Equals(True)))
34+
35+ def _open_location_manager(self):
36+ """Opens the location manager"""
37+ self.main_window.open_toolbar().click_button("EditButton")
38+
39+ def _swipe_first_location_to_remove(self):
40+ """Swipe right to delete the first location"""
41+ first_location = self.app.wait_select_single("Standard", objectName="existingLocationItem0")
42+ number_of_locations = self._get_number_of_locations()
43+
44+ x, y, w, h = first_location.globalRect
45+ tx = x + (w / 8)
46+ ty = y + (h / 2)
47+ self.pointing_device.drag(tx, ty, tx + w/4*3 , ty)
48+ self.assertThat(self._get_number_of_locations, Eventually(Equals(number_of_locations-1)))
49+
50+ def _get_number_of_locations(self):
51+ qqlw = self.app.select_single("ComposerSheet").select_single("QQuickListView")
52+ return qqlw.count
53+
54+ def _search_for_city(self, city):
55+ searchField = self.main_window.wait_select_single("TextField", objectName="SearchField")
56 #poll clicking for focus for lack of better method, due to screen switching animation
57 #is there a property we can use instead?
58 timeout = 0
59@@ -42,51 +68,39 @@
60 self.keyboard.press_and_release('Enter')
61 return searchField
62
63- def select_single_retry(self, object_type, **kwargs):
64- """Returns the item that is searched for with app.select_single
65- In case of the item was not found (not created yet) a second attempt is
66- taken 1 second later."""
67- item = self.app.select_single(object_type, **kwargs)
68- tries = 10
69- while item is None and tries > 0:
70- sleep(0.2)
71- item = self.app.select_single(object_type, **kwargs)
72- tries = tries - 1
73- return item
74+ def _add_location(self, location):
75+ self._open_add_location_page()
76+
77+ # insert city name to search for
78+ self._search_for_city(location)
79+
80+ # wait for results and click on the first item
81+ load_indicator = self.main_window.select_single('ActivityIndicator', objectName='SearchingSpinner')
82+ self.assertThat(load_indicator.running, Eventually(Equals(False), timeout=120))
83+ resultsList = self.main_window.select_single('QQuickListView', objectName='SearchResultList')
84+ self.assertThat(resultsList.visible, Eventually(Equals(True)))
85+ firstResult = self.main_window.wait_select_single('Label', objectName='searchResult0')
86+ self.pointing_device.move_to_object(firstResult)
87+ self.pointing_device.click()
88+
89+ # LocationManagerPage should be visible and location added
90+ addedItem = self.main_window.wait_select_single('Label', text=location)
91+ self.assertThat(addedItem.text, Eventually(Equals(location)))
92+ self._click_sheet_confirm()
93+
94+ # back to locations, wait till data is loaded
95+ load_indicator = self.main_window.select_single('ActivityIndicator', objectName='LoadingSpinner')
96+ self.assertThat(load_indicator.running, Eventually(Equals(False), timeout=120))
97+
98+ def _remove_location(self):
99+ self._open_location_manager()
100+ self._swipe_first_location_to_remove()
101+ self._click_sheet_confirm()
102
103 def test_add_location(self):
104 """Adds a location"""
105- self._open_add_location_page()
106-
107- # insert city name to search for
108- self.search_for_city("London")
109-
110- # wait for results and click on the first item
111- # http_failed = lambda: self.main_window.select_single('SplashComponent', objectName='HTTPFailedSplash').visible
112- # self.assertThat(http_failed, Eventually(NotEquals(True)))
113- load_indicator = self.main_window.select_single('ActivityIndicator', objectName='SearchingSpinner')
114- self.assertThat(load_indicator.running, Eventually(Equals(False), timeout=120))
115- resultsList = self.main_window.select_single('QQuickListView', objectName='SearchResultList')
116- self.assertThat(resultsList.visible, Eventually(Equals(True)))
117- self.assertThat(lambda: self.main_window.select_single('Label', objectName='searchResult0'),
118- Eventually(Not(Is(None))))
119- firstResult = self.main_window.select_single('Label', objectName='searchResult0')
120- self.pointing_device.move_to_object(firstResult)
121- self.pointing_device.click()
122-
123- # LocationManagerPage should be visible and "London" added
124- self.assertThat(lambda: self.main_window.select_single('QQuickListView', objectName='LocationList'),
125- Eventually(Not(Is(None))))
126- locationList = self.main_window.select_single('QQuickListView', objectName='LocationList')
127- self.assertThat(lambda: self.main_window.select_single('Label', objectName='existingLocation0'),
128- Eventually(Not(Is(None))))
129- addedItem = self.main_window.select_single('Label', objectName="existingLocation0")
130- self.assertThat(addedItem.text, Eventually(Equals("London")))
131- self._click_sheet_confirm()
132-
133- # back to locations, wait till data is loaded
134- load_indicator = self.main_window.select_single('ActivityIndicator', objectName='LoadingSpinner')
135- self.assertThat(load_indicator.running, Eventually(Equals(False), timeout=120))
136+
137+ self._add_location("Paris")
138
139 # only location is there
140 loadingPage = self.main_window.select_single("Tabs", objectName="rootTabs")
141@@ -100,19 +114,12 @@
142
143 resultsList = self.main_window.select_single('QQuickListView', objectName='SearchResultList')
144 self.assertThat(resultsList.visible, Eventually(Equals(True)))
145- self.assertThat(lambda: self.main_window.select_single('Label', objectName='searchResult4'),
146- Eventually(Not(Is(None))))
147- testResult = self.main_window.select_single('Label', objectName='searchResult4')
148+ testResult = self.main_window.wait_select_single('Label', objectName='searchResult4')
149 self.pointing_device.move_to_object(testResult)
150 self.pointing_device.click()
151
152 # LocationManagerPage should be visible and location added
153- self.assertThat(lambda: self.main_window.select_single('QQuickListView', objectName='LocationList'),
154- Eventually(Not(Is(None))))
155- locationList = self.main_window.select_single('QQuickListView', objectName='LocationList')
156- self.assertThat(lambda: self.main_window.select_single('Label', objectName='existingLocation0'),
157- Eventually(Not(Is(None))))
158- addedItem = self.main_window.select_single('Label', objectName="existingLocation0")
159+ addedItem = self.main_window.wait_select_single('Label', objectName="existingLocation0")
160 self.assertThat(addedItem.text, Eventually(Equals("Cairo")))
161 self._click_sheet_confirm()
162
163@@ -131,27 +138,20 @@
164 self._open_add_location_page()
165
166 # insert city name to search for
167- searchField = self.search_for_city("London")
168+ searchField = self._search_for_city("London")
169
170 # wait for results and click on the first item
171- #http_failed = lambda: self.main_window.select_single('SplashComponent', objectName='HTTPFailedSplash').visible
172- #self.assertThat(http_failed, Eventually(NotEquals(True)))
173 load_indicator = self.main_window.select_single('ActivityIndicator', objectName='SearchingSpinner')
174 self.assertThat(load_indicator.running, Eventually(Equals(False), timeout=120))
175 resultsList = self.main_window.select_single('QQuickListView', objectName='SearchResultList')
176 self.assertThat(resultsList.visible, Eventually(Equals(True)))
177- self.assertThat(lambda: self.main_window.select_single('Label', objectName='searchResult0'),
178- Eventually(Not(Is(None))))
179- firstResult = self.select_single_retry("Label", objectName="searchResult0")
180+ firstResult = self.main_window.wait_select_single("Label", objectName="searchResult0")
181 self.assertThat(firstResult.text, Eventually(Equals("London")))
182
183 # regain focus, clear search field and do another search
184- self.assertThat(lambda: self.main_window.select_single('TextField', objectName='SearchField'),
185- Eventually(Not(Is(None))))
186- searchField = self.main_window.select_single("TextField", objectName="SearchField")
187+ searchField = self.main_window.wait_select_single("TextField", objectName="SearchField")
188 self.pointing_device.click_object(searchField)
189- self.assertThat(lambda: self.main_window.select_single('AbstractButton'), Eventually(Not(Is(None))))
190- clear_button = searchField.select_single("AbstractButton")
191+ clear_button = searchField.wait_select_single("AbstractButton")
192 self.pointing_device.click_object(clear_button)
193 self.assertThat(searchField.text, Eventually(Equals("")))
194
195@@ -161,18 +161,14 @@
196 load_indicator = self.main_window.select_single('ActivityIndicator', objectName='SearchingSpinner')
197 self.assertThat(load_indicator.running, Eventually(Equals(False), timeout=120))
198 self.assertThat(resultsList.visible, Eventually(Equals(True)))
199- self.assertThat(lambda: self.main_window.select_single('Label', objectName='searchResult0'),
200- Eventually(Not(Is(None))))
201- firstResult = self.select_single_retry("Label", objectName="searchResult0")
202+ firstResult = self.main_window.wait_select_single("Label", objectName="searchResult0")
203 self.assertThat(firstResult.text, Eventually(Equals("Hamburg")))
204
205 def test_cancel_adding_location(self):
206 """Cancel the cities search"""
207 self._open_add_location_page()
208 self._click_sheet_cancel()
209- self.assertThat(lambda: self.main_window.select_single('QQuickListView', objectName='LocationList'),
210- Eventually(Not(Is(None))))
211- locationList = self.main_window.select_single('QQuickListView', objectName='LocationList')
212+ locationList = self.main_window.wait_select_single('QQuickListView', objectName='LocationList')
213 self.assertThat(locationList.visible, Eventually(Equals(True)))
214
215 def test_no_location_found(self):
216@@ -180,11 +176,9 @@
217 self._open_add_location_page()
218
219 # insert city name to search for
220- self.search_for_city("UbuntuCity")
221+ self._search_for_city("UbuntuCity")
222
223 # wait for result and look if label is shown
224- # http_failed = lambda: self.main_window.select_single('SplashComponent', objectName='HTTPFailedSearch').visible
225- # self.assertThat(http_failed, Eventually(NotEquals(True)))
226 load_indicator = self.main_window.select_single('ActivityIndicator', objectName='SearchingSpinner')
227 self.assertThat(load_indicator.running, Eventually(Equals(False), timeout=120))
228 errorLabel = self.main_window.select_single('Label', objectName='noCityError')
229@@ -193,9 +187,7 @@
230 def test_location_lookup(self):
231 """Tests the location lookup"""
232 # start lookup
233- self.assertThat(lambda: self.main_window.select_single('Standard', objectName='LocationLookupItem'),
234- Eventually(Not(Is(None))))
235- lookupItem = self.main_window.select_single('Standard', objectName='LocationLookupItem')
236+ lookupItem = self.main_window.wait_select_single('Standard', objectName='LocationLookupItem')
237 self.pointing_device.click_object(lookupItem)
238
239 # wait for result
240@@ -203,25 +195,16 @@
241 self.assertThat(load_indicator.running, Eventually(Equals(False), timeout=120))
242
243 # check a location was found
244- self.assertThat(lambda: self.main_window.select_single('Label', objectName='CurrentLocationLabel'),
245- Eventually(Not(Is(None))))
246- location = self.main_window.select_single('Label', objectName='CurrentLocationLabel')
247+ location = self.main_window.wait_select_single('Label', objectName='CurrentLocationLabel')
248 self.assertThat(location.text, Eventually(Not(Equals(""))))
249 location_name = location.text
250
251 # add location
252- self.assertThat(lambda: self.main_window.select_single('Button', objectName='LookupItemAddButton'),
253- Eventually(Not(Is(None))))
254- add_button = self.main_window.select_single('Button', objectName='LookupItemAddButton')
255+ add_button = self.main_window.wait_select_single('Button', objectName='LookupItemAddButton')
256 self.pointing_device.click_object(add_button)
257
258 # LocationManagerPage should be visible and location added
259- self.assertThat(lambda: self.main_window.select_single('QQuickListView', objectName='LocationList'),
260- Eventually(Not(Is(None))))
261- locationList = self.main_window.select_single('QQuickListView', objectName='LocationList')
262- self.assertThat(lambda: self.main_window.select_single('Label', objectName='existingLocation0'),
263- Eventually(Not(Is(None))))
264- addedItem = self.main_window.select_single('Label', objectName="existingLocation0")
265+ addedItem = self.main_window.wait_select_single('Label', objectName="existingLocation0")
266 self.assertThat(addedItem.text, Eventually(Equals(location_name)))
267 self._click_sheet_confirm()
268
269@@ -235,51 +218,10 @@
270 tabObjects = self.main_window.select_many('LocationTab', objectName='LocationTab')
271 self.assertEqual(1, len(tabObjects))
272
273-
274-
275-class TestLocationManagerWithLocation(WeatherTestCase, DatabaseMixin, SheetMixin, LocationManagerMixin):
276- def setUp(self):
277- self.clean_db()
278- self.launch_and_quit_app()
279- # add one location to storage
280- self.save_locations_to_storage(locations_data)
281- super(TestLocationManagerWithLocation, self).setUp()
282- self.assertThat(
283- self.get_qml_view().visible, Eventually(Equals(True)))
284-
285- def _open_location_manager(self):
286- """Opens the location manager"""
287- self.main_window.open_toolbar().click_button("EditButton")
288-
289- def _swipe_location_to_remove(self):
290- """Swipe right to delete the first location"""
291- number_of_locations = self._get_number_of_locations()
292- self.assertThat(lambda: self.app.select_single('Standard', objectName='existingLocationItem0'),
293- Eventually(Not(Is(None))))
294- first_location = self.app.select_single("Standard", objectName="existingLocationItem0")
295-
296- x, y, w, h = first_location.globalRect
297- tx = x + (w / 8)
298- ty = y + (h / 2)
299- self.pointing_device.drag(tx, ty, tx + w/4*3 , ty)
300-
301- self.assertThat(lambda: first_location.select_many('Label')[2].visible, Eventually(Not(Is(None))))
302- trashcanLabel = first_location.select_many('Label')[2]
303- timeout = 0
304- while timeout < 10 and first_location.select_many('Label') \
305- and self.app.select_single("Standard", objectName="existingLocationItem0"):
306- self.pointing_device.click_object(trashcanLabel)
307- sleep(1)
308- timeout += 1
309- self.assertThat(lambda: self._get_number_of_locations(), Eventually(Equals(number_of_locations-1)))
310-
311- def _get_number_of_locations(self):
312- qqlw = self.app.select_single("ComposerSheet").select_single("QQuickListView")
313- return qqlw.count
314-
315- @unittest.skip("https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1245651")
316 def test_remove_location(self):
317 """Removes location"""
318+ self._preload_database_and_relaunch()
319+
320 # wait till data is loaded
321 loadingPage = self.main_window.select_single("Tabs", objectName="rootTabs")
322 self.assertThat(loadingPage.visible, Eventually(Equals(True)))
323@@ -288,10 +230,8 @@
324 tabObjects = self.main_window.select_many('LocationTab', objectName='LocationTab')
325 tabsSumStart = len(tabObjects)
326
327- # go to the location manager and remove location
328- self._open_location_manager()
329- self._swipe_location_to_remove()
330- self._click_sheet_confirm()
331+ # go to the location manager and remove 1st location
332+ self._remove_location()
333
334 # back to locations, only one is left
335 load_indicator = self.main_window.select_single('ActivityIndicator', objectName='LoadingSpinner')
336@@ -299,9 +239,10 @@
337 tabObjects = self.main_window.select_many('LocationTab', objectName='LocationTab')
338 self.assertThat(lambda: tabsSumStart-1, Eventually(Equals(len(tabObjects))))
339
340- @unittest.skip("https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1245651")
341 def test_cancel_remove_location(self):
342 """Cancels removing of location"""
343+ self._preload_database_and_relaunch()
344+
345 # wait data is loaded
346 loadingPage = self.main_window.select_single("Tabs", objectName="rootTabs")
347 self.assertThat(loadingPage.visible, Eventually(Equals(True)))
348@@ -312,7 +253,7 @@
349
350 # go to the location manager, remove location, but click cancel
351 self._open_location_manager()
352- self._swipe_location_to_remove()
353+ self._swipe_first_location_to_remove()
354 self._click_sheet_cancel()
355
356 # back to locations, no loction is removed
357@@ -322,33 +263,19 @@
358 self.assertEqual(tabsSumStart, len(tabObjects))
359
360 def test_del_add_bug(self):
361- """Tests if remvoing and add ad loction in one action works
362+ """Tests if removing and add a location in one action works
363 https://bugs.launchpad.net/ubuntu-weather-app/+bug/1230297"""
364+
365+ self._preload_database_and_relaunch()
366+
367 # remove a location
368- self._open_location_manager()
369+ self._remove_location()
370+
371 number_of_locations = self._get_number_of_locations()
372- self._swipe_location_to_remove()
373- self._open_add_location_page()
374
375 # add a location
376- resultsList = self.main_window.select_single('QQuickListView', objectName='SearchResultList')
377- self.assertThat(resultsList.visible, Eventually(Equals(True)))
378- self.assertThat(lambda: self.main_window.select_single('Label', objectName='searchResult4'),
379- Eventually(Not(Is(None))))
380- testResult = self.main_window.select_single('Label', objectName='searchResult4')
381- self.pointing_device.move_to_object(testResult)
382- self.pointing_device.click()
383-
384- # LocationManagerPage should be visible and location added
385- self.assertThat(lambda: self.main_window.select_single('QQuickListView', objectName='LocationList'),
386- Eventually(Not(Is(None))))
387- locationList = self.main_window.select_single('QQuickListView', objectName='LocationList')
388- self.assertThat(lambda: self.main_window.select_single('Label', objectName='existingLocation1'),
389- Eventually(Not(Is(None))))
390- addedItem = self.main_window.select_single('Label', objectName="existingLocation1")
391- self.assertThat(addedItem.text, Eventually(Equals("Cairo")))
392- self.assertThat(lambda: self._get_number_of_locations(), Eventually(Equals(number_of_locations)))
393- self._click_sheet_confirm()
394+ self._open_location_manager()
395+ self._add_location("Cairo")
396
397 # back to locations, wait till data is loaded
398 load_indicator = self.main_window.select_single('ActivityIndicator', objectName='LoadingSpinner')
399@@ -356,7 +283,7 @@
400
401 # count the tabs
402 tabObjects = self.main_window.select_many('LocationTab', objectName='LocationTab')
403- self.assertThat(lambda: number_of_locations, Eventually(Equals(len(tabObjects))))
404+ self.assertThat(lambda: number_of_locations + 1, Eventually(Equals(len(tabObjects))))
405 self.assertThat(
406 self.main_window.select_single('LocationTab', index=1).title,
407 Eventually(Equals("Cairo")))

Subscribers

People subscribed via source and target branches