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: 173
Merged at revision: 164
Proposed branch: lp:~nskaggs/ubuntu-weather-app/swipe-delete-ap-tests
Merge into: lp:ubuntu-weather-app/obsolete.trunk
Diff against target: 340 lines (+95/-51)
4 files modified
tests/autopilot/ubuntu_weather_app/tests/__init__.py (+48/-26)
tests/autopilot/ubuntu_weather_app/tests/test_locationmanager.py (+19/-14)
tests/autopilot/ubuntu_weather_app/tests/test_mainview.py (+13/-5)
tests/autopilot/ubuntu_weather_app/tests/test_settings.py (+15/-6)
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+198627@code.launchpad.net

Commit message

Further tweaks to enable mako and maguro to run the tests properly, transitioned to load db at startup, added logging

Description of the change

Further tweaks to enable mako and maguro to run the tests properly, transitioned to load db at startup, added logging

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) :
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-12-11 01:03:53 +0000
3+++ tests/autopilot/ubuntu_weather_app/tests/__init__.py 2013-12-11 20:25:12 +0000
4@@ -13,16 +13,19 @@
5 import glob
6 import sqlite3
7 import time
8+import logging
9
10 from autopilot.input import Mouse, Touch, Pointer
11 from autopilot.platform import model
12 from autopilot.testcase import AutopilotTestCase
13-from testtools.matchers import Equals, NotEquals, Is, Not
14+from testtools.matchers import Equals
15 from autopilot.matchers import Eventually
16
17 from ubuntuuitoolkit import emulators as toolkit_emulators
18 from ubuntu_weather_app.emulators import MainView
19
20+logger = logging.getLogger(__name__)
21+
22
23 class WeatherTestCase(AutopilotTestCase):
24
25@@ -50,10 +53,13 @@
26
27 def launch_app(self):
28 if os.path.exists(self.local_location):
29+ logger.debug("Running via local installation")
30 self.launch_test_local()
31 elif os.path.exists(self.installed_location):
32+ logger.debug("Running via installed debian package")
33 self.launch_test_installed()
34 else:
35+ logger.debug("Running via click package")
36 self.launch_test_click()
37
38 def launch_test_local(self):
39@@ -77,18 +83,6 @@
40 "com.ubuntu.weather",
41 emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
42
43- def launch_and_quit_app(self):
44- self.launch_app()
45- self.get_qml_view().visible.wait_for(True)
46-
47- # When calling launch_app an instance of the spawned process
48- # control object will be stored in self.app.process, and a cleanup
49- # handler will be registered that essentially kills the process.
50- # Therefore, by triggering the cleanup handler here we're killing the
51- # process and removing the handler, which allows a clean launch of
52- # the process during regular test setup.
53- self.doCleanups()
54-
55 def get_qml_view(self):
56 return self.app.select_single("QQuickView")
57
58@@ -132,44 +126,76 @@
59 Helper functions for dealing with sqlite databases
60 """
61
62+ db_path = os.path.expanduser(
63+ "~/.local/share/com.ubuntu.weather/Databases")
64+
65+ def _execute_sql(self, statement):
66+ path = self.find_db()
67+ conn = sqlite3.connect(path)
68+ cursor = conn.cursor()
69+ logger.debug("Executing sql")
70+ logger.debug(statement)
71+ cursor.execute(statement)
72+ conn.commit()
73+ conn.close()
74+
75 def find_db(self):
76- dbs_path = os.path.expanduser(
77- "~/.local/share/com.ubuntu.weather/Databases/")
78- if not os.path.exists(dbs_path):
79+ if not os.path.exists(self.db_path):
80+ logger.debug("Database not found in ~/.local/share/")
81 return None
82
83- files = [f for f in os.listdir(dbs_path)
84+ logger.debug("Database found in ~/.local/share/")
85+ files = [f for f in os.listdir(self.db_path)
86 if os.path.splitext(f)[1] == ".ini"]
87 for f in files:
88- ini_path = os.path.join(dbs_path, f)
89+ ini_path = os.path.join(self.db_path, f)
90 with open(ini_path) as ini:
91 for line in ini:
92 if "=" in line:
93 key, val = line.strip().split("=")
94 if key == "Name" and val == "com.ubuntu.weather":
95 try:
96+ logger.debug("Replaced ini com.ubuntu.weather key")
97 return ini_path.replace(".ini", ".sqlite")
98 except OSError:
99+ logger.debug("No ini found to replace")
100 pass
101 return None
102
103 def clean_db(self):
104+ logger.debug("Removing existing database")
105 path = self.find_db()
106 if path is None:
107+ logger.debug("Database not found to clean")
108 self.launch_and_quit_app()
109 path = self.find_db()
110 if path is None:
111+ logger.debug("Database still not found after app launch")
112 self.assertNotEquals(path, None)
113
114 try:
115+ logger.debug("Removing existing database")
116 os.remove(path)
117 except OSError:
118+ logger.debug("Could not remove existing database")
119 pass
120
121- def save_locations_to_storage(self, locations):
122+ def create_blank_db(self):
123+ self.clean_db()
124+
125+ #this needs to stay in sync with Storage.qml enties
126+ logger.debug("Creating locations and settings tables")
127+ self._execute_sql("CREATE TABLE IF NOT EXISTS Locations(id INTEGER "
128+ "PRIMARY KEY AUTOINCREMENT, data TEXT, date TEXT)")
129+
130+ self._execute_sql("CREATE TABLE IF NOT EXISTS settings(key TEXT "
131+ "UNIQUE, value TEXT)")
132+
133+ def add_locations_to_database(self, locations):
134 path = self.find_db()
135 conn = sqlite3.connect(path)
136 cursor = conn.cursor()
137+ logger.debug("Adding locations to database")
138 for loc_data in locations:
139 db_exec = "INSERT INTO Locations(date, data) VALUES('{}', '{}')"
140 cursor.execute(db_exec.format(
141@@ -177,13 +203,9 @@
142 conn.commit()
143 conn.close()
144
145- def save_units_to_storage(self):
146- path = self.find_db()
147- conn = sqlite3.connect(path)
148- cursor = conn.cursor()
149- cursor.execute("INSERT INTO settings(key, value) "
150+ def add_units_to_database(self):
151+ logger.debug("Adding units to database")
152+ self._execute_sql("INSERT INTO settings(key, value) "
153 "VALUES('units', 'metric'), "
154 "('wind_units', 'kmh'), "
155 "('precip_units', 'mm')")
156- conn.commit()
157- conn.close()
158
159=== modified file 'tests/autopilot/ubuntu_weather_app/tests/test_locationmanager.py'
160--- tests/autopilot/ubuntu_weather_app/tests/test_locationmanager.py 2013-12-11 01:09:53 +0000
161+++ tests/autopilot/ubuntu_weather_app/tests/test_locationmanager.py 2013-12-11 20:25:12 +0000
162@@ -9,14 +9,16 @@
163
164 from __future__ import absolute_import
165
166-from testtools.matchers import Equals, NotEquals, Is, Not
167+from testtools.matchers import Equals, Not
168 from autopilot.matchers import Eventually
169
170 from ubuntu_weather_app.tests import WeatherTestCase, DatabaseMixin, SheetMixin, LocationManagerMixin
171 from ubuntu_weather_app.tests.weatherdata import locations_data
172
173 from time import sleep
174-import unittest
175+import logging
176+
177+logger = logging.getLogger(__name__)
178
179 class TestLocationManager(WeatherTestCase, DatabaseMixin, SheetMixin, LocationManagerMixin):
180
181@@ -26,11 +28,16 @@
182 self.assertThat(
183 self.get_qml_view().visible, Eventually(Equals(True)))
184
185- def _preload_database_and_relaunch(self):
186- self.clean_db()
187- self.launch_and_quit_app()
188- # add one location to storage
189- self.save_locations_to_storage(locations_data)
190+ def _preload_database_and_launch(self):
191+ #close app
192+ logger.debug("Closing app")
193+ self.doCleanups()
194+ #wipe the existing database and create a new blank one
195+ self.create_blank_db()
196+ # add locations to storage
197+ logger.debug("Adding fake data to new database")
198+ self.add_locations_to_database(locations_data)
199+ logger.debug("Re-Launching app to introspect")
200 super(TestLocationManager, self).setUp()
201 self.assertThat(
202 self.get_qml_view().visible, Eventually(Equals(True)))
203@@ -51,7 +58,7 @@
204 self.assertThat(self._get_number_of_locations, Eventually(Equals(number_of_locations-1)))
205
206 def _get_number_of_locations(self):
207- qqlw = self.app.select_single("ComposerSheet").select_single("QQuickListView")
208+ qqlw = self.app.wait_select_single("ComposerSheet").wait_select_single("QQuickListView")
209 return qqlw.count
210
211 def _search_for_city(self, city):
212@@ -220,7 +227,7 @@
213
214 def test_remove_location(self):
215 """Removes location"""
216- self._preload_database_and_relaunch()
217+ self._preload_database_and_launch()
218
219 # wait till data is loaded
220 loadingPage = self.main_window.select_single("Tabs", objectName="rootTabs")
221@@ -241,7 +248,7 @@
222
223 def test_cancel_remove_location(self):
224 """Cancels removing of location"""
225- self._preload_database_and_relaunch()
226+ self._preload_database_and_launch()
227
228 # wait data is loaded
229 loadingPage = self.main_window.select_single("Tabs", objectName="rootTabs")
230@@ -266,13 +273,11 @@
231 """Tests if removing and add a location in one action works
232 https://bugs.launchpad.net/ubuntu-weather-app/+bug/1230297"""
233
234- self._preload_database_and_relaunch()
235+ self._preload_database_and_launch()
236
237 # remove a location
238 self._remove_location()
239
240- number_of_locations = self._get_number_of_locations()
241-
242 # add a location
243 self._open_location_manager()
244 self._add_location("Cairo")
245@@ -283,7 +288,7 @@
246
247 # count the tabs
248 tabObjects = self.main_window.select_many('LocationTab', objectName='LocationTab')
249- self.assertThat(lambda: number_of_locations + 1, Eventually(Equals(len(tabObjects))))
250+ self.assertThat(lambda: len(tabObjects), Eventually(Equals(2)))
251 self.assertThat(
252 self.main_window.select_single('LocationTab', index=1).title,
253 Eventually(Equals("Cairo")))
254
255=== modified file 'tests/autopilot/ubuntu_weather_app/tests/test_mainview.py'
256--- tests/autopilot/ubuntu_weather_app/tests/test_mainview.py 2013-11-05 23:27:52 +0000
257+++ tests/autopilot/ubuntu_weather_app/tests/test_mainview.py 2013-12-11 20:25:12 +0000
258@@ -11,23 +11,31 @@
259
260 from __future__ import absolute_import
261
262-from testtools.matchers import NotEquals, Equals, Is, Not
263+from testtools.matchers import Equals, Is, Not
264 from autopilot.matchers import Eventually
265
266-import unittest
267+import logging
268
269 from ubuntu_weather_app.tests import WeatherTestCase, DatabaseMixin
270 from ubuntu_weather_app.tests.weatherdata import locations_data
271
272+logger = logging.getLogger(__name__)
273+
274 class TestMainView(WeatherTestCase, DatabaseMixin):
275 """Tests creating weather"""
276
277 """ This is needed to wait for the application to start.
278 In the testfarm, the application may take some time to show up."""
279 def setUp(self):
280- self.clean_db()
281- self.launch_and_quit_app()
282- self.save_locations_to_storage(locations_data)
283+ #close app
284+ #logger.debug("Closing app")
285+ #self.doCleanups()
286+ #wipe the existing database and create a new blank one
287+ self.create_blank_db()
288+ # add settings to storage
289+ logger.debug("Adding fake data to new database")
290+ self.add_locations_to_database(locations_data)
291+ logger.debug("Re-Launching app to introspect")
292 super(TestMainView, self).setUp()
293 self.assertThat(
294 self.get_qml_view().visible, Eventually(Equals(True)))
295
296=== modified file 'tests/autopilot/ubuntu_weather_app/tests/test_settings.py'
297--- tests/autopilot/ubuntu_weather_app/tests/test_settings.py 2013-11-06 19:40:17 +0000
298+++ tests/autopilot/ubuntu_weather_app/tests/test_settings.py 2013-12-11 20:25:12 +0000
299@@ -9,18 +9,27 @@
300
301 from __future__ import absolute_import
302
303-from testtools.matchers import Equals, NotEquals, Is, Not
304+from testtools.matchers import Equals, Is, Not
305 from autopilot.matchers import Eventually
306+import logging
307
308 from ubuntu_weather_app.tests import WeatherTestCase, DatabaseMixin, SheetMixin
309 from ubuntu_weather_app.tests.weatherdata import locations_data
310
311+logger = logging.getLogger(__name__)
312+
313 class TestSettings(WeatherTestCase, DatabaseMixin, SheetMixin):
314 def setUp(self):
315- self.clean_db()
316- self.launch_and_quit_app()
317- self.save_locations_to_storage(locations_data)
318- self.save_units_to_storage()
319+ #close app
320+ #logger.debug("Closing app")
321+ #self.doCleanups()
322+ #wipe the existing database and create a new blank one
323+ self.create_blank_db()
324+ # add settings to storage
325+ logger.debug("Adding fake data to new database")
326+ self.add_locations_to_database(locations_data)
327+ self.add_units_to_database()
328+ logger.debug("Re-Launching app to introspect")
329 super(TestSettings, self).setUp()
330 self.assertThat(
331 self.get_qml_view().visible, Eventually(Equals(True)))
332@@ -257,7 +266,7 @@
333 current_option = units_selector.select_many('ShapeItem')[1]
334 self.pointing_device.click_object(current_option)
335
336- # choose second option, inch
337+ # choose second option, inch
338 self._move_pointer_around()
339 self.assertThat(lambda: units_selector.select_many('ShapeItem')[2], Eventually(Not(Is(None))))
340 in_option = units_selector.select_many('ShapeItem')[2]

Subscribers

People subscribed via source and target branches