Merge lp:~osomon/notes-app/simplify-db-lookup into lp:notes-app

Proposed by Olivier Tilloy
Status: Merged
Approved by: Olivier Tilloy
Approved revision: 220
Merged at revision: 221
Proposed branch: lp:~osomon/notes-app/simplify-db-lookup
Merge into: lp:notes-app
Diff against target: 313 lines (+32/-98)
7 files modified
tests/autopilot/notes_app/tests/__init__.py (+9/-37)
tests/autopilot/notes_app/tests/test_create.py (+3/-9)
tests/autopilot/notes_app/tests/test_delete.py (+3/-10)
tests/autopilot/notes_app/tests/test_expand_collapse.py (+3/-10)
tests/autopilot/notes_app/tests/test_images.py (+3/-10)
tests/autopilot/notes_app/tests/test_parts.py (+3/-4)
tests/autopilot/notes_app/tests/test_quit.py (+8/-18)
To merge this branch: bzr merge lp:~osomon/notes-app/simplify-db-lookup
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Ugo Riboni (community) Approve
Review via email: mp+193750@code.launchpad.net

Commit message

Simplify database lookup in autopilot tests.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ugo Riboni (uriboni) wrote :

Code looks good and tests still pass when i run them

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Autolanding.
More details in the following jenkins job:
http://jenkins.qa.ubuntu.com/job/notes-app-autolanding/101/
Executed test runs:
    UNSTABLE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-trusty/368
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-trusty-touch/356/console
    SUCCESS: http://jenkins.qa.ubuntu.com/job/notes-app-trusty-amd64-autolanding/7
    SUCCESS: http://jenkins.qa.ubuntu.com/job/notes-app-trusty-armhf-autolanding/7
        deb: http://jenkins.qa.ubuntu.com/job/notes-app-trusty-armhf-autolanding/7/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/notes-app-trusty-i386-autolanding/7
    UNSTABLE: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-trusty/345
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-amd64/368
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-amd64/368/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-armhf/356
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-armhf/356/artifact/work/output/*zip*/output.zip
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-maguro/2938/console
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-mako/3022
    SUCCESS: http://10.97.0.26:8080/job/touch-flash-device/956
    SUCCESS: http://10.97.0.26:8080/job/touch-flash-device/954

review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) :
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/notes_app/tests/__init__.py'
2--- tests/autopilot/notes_app/tests/__init__.py 2013-10-25 16:37:21 +0000
3+++ tests/autopilot/notes_app/tests/__init__.py 2013-11-04 11:16:36 +0000
4@@ -12,6 +12,7 @@
5 import glob
6 import threading
7 import base64
8+import md5
9
10 from autopilot.input import Mouse, Touch, Pointer
11 from autopilot.matchers import Eventually
12@@ -95,6 +96,14 @@
13 # the process during regular test setup.
14 self.doCleanups()
15
16+ def ensure_db(self):
17+ path = os.path.expanduser("~/.local/share/com.ubuntu.notes/Databases")
18+ db = os.path.join(path, md5.md5("notes").hexdigest() + ".sqlite")
19+ if not os.path.exists(db):
20+ self.launch_and_quit_app()
21+ self.assertTrue(os.path.exists(db))
22+ return db
23+
24 def assert_osk_eventually_shown(self):
25 if model() != 'Desktop':
26 keyboardRectangle = self.main_window.get_keyboard_rectangle()
27@@ -177,40 +186,3 @@
28 def tearDown(self):
29 super(NotesTestCaseBaseWithHTTPServer, self).tearDown()
30 self.server.shutdown()
31-
32-
33-class DatabaseMixin(object):
34-
35- """
36- Helper functions for dealing with sqlite databases
37- """
38-
39- def _get_db_path(self):
40- db_path_list = [
41- "~/.local/share/com.ubuntu.notes/Databases",
42- "~/.local/share/Qt Project/QtQmlViewer/QML/OfflineStorage/"
43- "Databases/"]
44- for path in db_path_list:
45- path = os.path.expanduser(path)
46- if os.path.exists(path):
47- return path
48- return None
49-
50- def find_db(self):
51- dbs_path = self._get_db_path()
52- if not dbs_path:
53- return None
54- files = [f for f in os.listdir(dbs_path)
55- if os.path.splitext(f)[1] == ".ini"]
56- for f in files:
57- ini_path = os.path.join(dbs_path, f)
58- with open(ini_path) as ini:
59- for line in ini:
60- if "=" in line:
61- key, val = line.strip().split("=")
62- if key == "Name" and val == "notes":
63- try:
64- return ini_path.replace(".ini", ".sqlite")
65- except OSError:
66- pass
67- return None
68
69=== modified file 'tests/autopilot/notes_app/tests/test_create.py'
70--- tests/autopilot/notes_app/tests/test_create.py 2013-09-27 14:42:07 +0000
71+++ tests/autopilot/notes_app/tests/test_create.py 2013-11-04 11:16:36 +0000
72@@ -12,12 +12,12 @@
73 from testtools.matchers import Equals
74 from autopilot.matchers import Eventually
75
76-from notes_app.tests import NotesAppTestCase, DatabaseMixin
77+from notes_app.tests import NotesAppTestCase
78
79 import os
80
81
82-class TestCreate(NotesAppTestCase, DatabaseMixin):
83+class TestCreate(NotesAppTestCase):
84 """Tests creating notes"""
85
86 """ This is needed to wait for the application to start.
87@@ -29,13 +29,7 @@
88 super(TestCreate, self).setUp()
89
90 def clean_db(self):
91- path = self.find_db()
92- if path is None:
93- self.launch_and_quit_app()
94- path = self.find_db()
95- if path is None:
96- self.assertNotEquals(path, None)
97-
98+ path = self.ensure_db()
99 try:
100 os.remove(path)
101 except OSError:
102
103=== modified file 'tests/autopilot/notes_app/tests/test_delete.py'
104--- tests/autopilot/notes_app/tests/test_delete.py 2013-10-30 15:47:44 +0000
105+++ tests/autopilot/notes_app/tests/test_delete.py 2013-11-04 11:16:36 +0000
106@@ -12,12 +12,12 @@
107 from testtools.matchers import Equals, GreaterThan, LessThan
108 from autopilot.matchers import Eventually
109
110-from notes_app.tests import NotesAppTestCase, DatabaseMixin
111+from notes_app.tests import NotesAppTestCase
112
113 import sqlite3
114
115
116-class TestDelete(NotesAppTestCase, DatabaseMixin):
117+class TestDelete(NotesAppTestCase):
118 """Tests deleting notes"""
119
120 def setUp(self):
121@@ -29,14 +29,7 @@
122 note_data = """{ "elements" : [
123 {"content":"This is a note.","type":"text"}
124 ]}"""
125-
126- path = self.find_db()
127- if path is None:
128- self.launch_and_quit_app()
129- path = self.find_db()
130- if path is None:
131- self.assertNotEquals(path, None)
132-
133+ path = self.ensure_db()
134 conn = sqlite3.connect(path)
135 cursor = conn.cursor()
136 cursor.execute("DELETE FROM notes")
137
138=== modified file 'tests/autopilot/notes_app/tests/test_expand_collapse.py'
139--- tests/autopilot/notes_app/tests/test_expand_collapse.py 2013-10-01 07:42:44 +0000
140+++ tests/autopilot/notes_app/tests/test_expand_collapse.py 2013-11-04 11:16:36 +0000
141@@ -12,12 +12,12 @@
142 from testtools.matchers import Equals
143 from autopilot.matchers import Eventually
144
145-from notes_app.tests import NotesAppTestCase, DatabaseMixin
146+from notes_app.tests import NotesAppTestCase
147
148 import sqlite3
149
150
151-class TestExpandCollapse(NotesAppTestCase, DatabaseMixin):
152+class TestExpandCollapse(NotesAppTestCase):
153 """Tests deleting notes"""
154
155 def setUp(self):
156@@ -34,14 +34,7 @@
157 {"content":"This is another note.","type":"text"}
158 ]}"""
159 ]
160-
161- path = self.find_db()
162- if path is None:
163- self.launch_and_quit_app()
164- path = self.find_db()
165- if path is None:
166- self.assertNotEquals(path, None)
167-
168+ path = self.ensure_db()
169 conn = sqlite3.connect(path)
170 cursor = conn.cursor()
171 cursor.execute("DELETE FROM notes")
172
173=== modified file 'tests/autopilot/notes_app/tests/test_images.py'
174--- tests/autopilot/notes_app/tests/test_images.py 2013-10-07 10:10:40 +0000
175+++ tests/autopilot/notes_app/tests/test_images.py 2013-11-04 11:16:36 +0000
176@@ -12,12 +12,12 @@
177 from testtools.matchers import Equals
178 from autopilot.matchers import Eventually
179
180-from notes_app.tests import NotesTestCaseBaseWithHTTPServer, DatabaseMixin
181+from notes_app.tests import NotesTestCaseBaseWithHTTPServer
182
183 import sqlite3
184
185
186-class BaseForTestImages(NotesTestCaseBaseWithHTTPServer, DatabaseMixin):
187+class BaseForTestImages(NotesTestCaseBaseWithHTTPServer):
188 def setUp(self):
189 self.setup_db(self.IMAGE)
190 super(BaseForTestImages, self).setUp()
191@@ -26,14 +26,7 @@
192 note_data = """{ "elements" : [
193 {"content":"http://localhost:8129/""" + image + """","type":"image"}
194 ]}"""
195-
196- path = self.find_db()
197- if path is None:
198- self.launch_and_quit_app()
199- path = self.find_db()
200- if path is None:
201- self.assertNotEquals(path, None)
202-
203+ path = self.ensure_db()
204 conn = sqlite3.connect(path)
205 cursor = conn.cursor()
206 cursor.execute("DELETE FROM notes")
207
208=== modified file 'tests/autopilot/notes_app/tests/test_parts.py'
209--- tests/autopilot/notes_app/tests/test_parts.py 2013-10-07 10:21:27 +0000
210+++ tests/autopilot/notes_app/tests/test_parts.py 2013-11-04 11:16:36 +0000
211@@ -13,12 +13,12 @@
212 from autopilot.matchers import Eventually
213 from autopilot.platform import model
214
215-from notes_app.tests import NotesTestCaseBaseWithHTTPServer, DatabaseMixin
216+from notes_app.tests import NotesTestCaseBaseWithHTTPServer
217
218 import sqlite3
219
220
221-class TestFocus(NotesTestCaseBaseWithHTTPServer, DatabaseMixin):
222+class TestFocus(NotesTestCaseBaseWithHTTPServer):
223 """Tests focusing notes"""
224
225 """ This is needed to wait for the application to start.
226@@ -33,8 +33,7 @@
227 {"content":"foobar","type":"text"},
228 {"content":"http://localhost:8129/image.png","type":"image"}
229 ]}"""
230-
231- path = self.find_db()
232+ path = self.ensure_db()
233 conn = sqlite3.connect(path)
234 cursor = conn.cursor()
235 cursor.execute("DELETE FROM notes")
236
237=== modified file 'tests/autopilot/notes_app/tests/test_quit.py'
238--- tests/autopilot/notes_app/tests/test_quit.py 2013-10-01 07:42:44 +0000
239+++ tests/autopilot/notes_app/tests/test_quit.py 2013-11-04 11:16:36 +0000
240@@ -13,7 +13,7 @@
241 from autopilot.matchers import Eventually
242 from autopilot.introspection.dbus import StateNotFoundError
243
244-from notes_app.tests import NotesAppTestCase, DatabaseMixin
245+from notes_app.tests import NotesAppTestCase
246
247 import sqlite3
248 import json
249@@ -47,17 +47,8 @@
250 return True
251 return False
252
253- def get_db_path(self):
254- path = self.find_db()
255- if path is None:
256- self.launch_and_quit_app()
257- path = self.find_db()
258- if path is None:
259- self.assertNotEquals(path, None)
260- return path
261-
262-
263-class TestQuit(NotesAppTestCase, DatabaseMixin, UtilsMixin):
264+
265+class TestQuit(NotesAppTestCase, UtilsMixin):
266 """Tests save on quit"""
267
268 """ This is needed to wait for the application to start.
269@@ -71,8 +62,7 @@
270 note_data = """{ "elements" : [
271 {"content":"foobar","type":"text"}
272 ]}"""
273-
274- path = self.get_db_path()
275+ path = self.ensure_db()
276 conn = sqlite3.connect(path)
277 cursor = conn.cursor()
278 cursor.execute("DELETE FROM notes")
279@@ -92,7 +82,7 @@
280
281 self.assertThat(self.app_has_quit, Eventually(Equals(True)))
282
283- path = self.find_db()
284+ path = self.ensure_db()
285 conn = sqlite3.connect(path)
286 cursor = conn.cursor()
287
288@@ -105,7 +95,7 @@
289 self.assertEquals(data["elements"][0]["content"], "foobarxxx")
290
291
292-class TestQuitNoNote(NotesAppTestCase, DatabaseMixin, UtilsMixin):
293+class TestQuitNoNote(NotesAppTestCase, UtilsMixin):
294 """Tests save on quit with no notes"""
295
296 """ This is needed to wait for the application to start.
297@@ -116,7 +106,7 @@
298 super(TestQuitNoNote, self).setUp()
299
300 def setup_db(self):
301- path = self.get_db_path()
302+ path = self.ensure_db()
303 conn = sqlite3.connect(path)
304 cursor = conn.cursor()
305 cursor.execute("DELETE FROM notes")
306@@ -134,7 +124,7 @@
307
308 self.assertThat(self.app_has_quit, Eventually(Equals(True)))
309
310- path = self.find_db()
311+ path = self.ensure_db()
312 conn = sqlite3.connect(path)
313 cursor = conn.cursor()
314

Subscribers

People subscribed via source and target branches