Merge lp:~nskaggs/ubuntu-weather-app/add-createdb into lp:ubuntu-weather-app/obsolete.trunk
- add-createdb
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Nicholas Skaggs |
Approved revision: | 169 |
Merged at revision: | 168 |
Proposed branch: | lp:~nskaggs/ubuntu-weather-app/add-createdb |
Merge into: | lp:ubuntu-weather-app/obsolete.trunk |
Diff against target: |
183 lines (+35/-47) 5 files modified
tests/autopilot/ubuntu_weather_app/Databases/34e1e542f2f083ff18f537b07a380071.ini (+6/-0) tests/autopilot/ubuntu_weather_app/tests/__init__.py (+25/-35) tests/autopilot/ubuntu_weather_app/tests/test_locationmanager.py (+2/-1) tests/autopilot/ubuntu_weather_app/tests/test_mainview.py (+1/-5) tests/autopilot/ubuntu_weather_app/tests/test_settings.py (+1/-6) |
To merge this branch: | bzr merge lp:~nskaggs/ubuntu-weather-app/add-createdb |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ubuntu Phone Apps Jenkins Bot | continuous-integration | Approve | |
Sergio Schvezov (community) | Approve | ||
Nicholas Skaggs | Pending | ||
Review via email: mp+199341@code.launchpad.net |
This proposal supersedes a proposal from 2013-12-17.
Commit message
Redo create blank db, ensure it's being used across all tests
Description of the change
Redo create blank db, ensure it's being used across all tests
Fix weather failures; Sergio's enhancements
Sergio Schvezov (sergiusens) wrote : Posted in a previous version of this proposal | # |
Sergio Schvezov (sergiusens) wrote : Posted in a previous version of this proposal | # |
37 + subprocess.
38 + "mkdir",
39 + "-p",
40 + "~/.local/
why aren't you usig os.makedirs?
Sergio Schvezov (sergiusens) wrote : Posted in a previous version of this proposal | # |
32 + db_dir = "~/.local/
33 + db_file = "34e1e542f2f083
34 + db_path = os.path.
35 +
36 + if not os.path.
37 + subprocess.
38 + "mkdir",
39 + "-p",
You need the module path
40 + "~/.local/
41 + shutil.
Approximation...
db_dir = "~/.local/
db_file = "34e1e542f2f083
db_path = os.path.
if not os.path.
# it's what we want
os.
# you'll need the python module location
shutil.
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : Posted in a previous version of this proposal | # |
PASSED: Continuous integration, rev:170
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : Posted in a previous version of this proposal | # |
PASSED: Continuous integration, rev:171
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Nicholas Skaggs (nskaggs) wrote : Posted in a previous version of this proposal | # |
Any concerns about the relative copy?
shutil.
Nicholas Skaggs (nskaggs) wrote : Posted in a previous version of this proposal | # |
Runs on my mako with and without existing db
Sergio Schvezov (sergiusens) wrote : Posted in a previous version of this proposal | # |
Personally I would of done something closer to (only one hardcoded path)
=== modified file 'tests/
--- tests/autopilot
+++ tests/autopilot
@@ -89,13 +89,14 @@
return self.app.
def ensure_db(self):
- db_dir = "~/.local/
+ weather_dir = os.path.expanduser(
+ "~/.local/
+ db_dir = os.path.
db_file = "34e1e542f2f083
- abs_path = os.path.
- db_path = os.path.
+ db_path = os.path.
if not os.path.
- os.makedirs(
+ os.makedirs(
Sergio Schvezov (sergiusens) wrote : Posted in a previous version of this proposal | # |
And for the module path you'll need something like
Nicholas Skaggs (nskaggs) wrote : Posted in a previous version of this proposal | # |
I agree with Sergio. Should be more robust that way. Thanks Sergio!
Nicholas Skaggs (nskaggs) wrote : Posted in a previous version of this proposal | # |
I would also add a logger line saying you are creating the database when you do it :-)
Omer Akram (om26er) wrote : Posted in a previous version of this proposal | # |
Not creating the dir in the test code. shutil.copytree calls makedirs so no need.
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : Posted in a previous version of this proposal | # |
FAILED: Continuous integration, rev:172
http://
Executed test runs:
UNSTABLE: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : Posted in a previous version of this proposal | # |
FAILED: Continuous integration, rev:172
http://
Executed test runs:
UNSTABLE: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : Posted in a previous version of this proposal | # |
FAILED: Continuous integration, rev:173
http://
Executed test runs:
UNSTABLE: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : Posted in a previous version of this proposal | # |
FAILED: Continuous integration, rev:173
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https:/
http://
Executed test runs:
UNSTABLE: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Nicholas Skaggs (nskaggs) : Posted in a previous version of this proposal | # |
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : Posted in a previous version of this proposal | # |
FAILED: Autolanding.
More details in the following jenkins job:
http://
Executed test runs:
UNSTABLE: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
Nicholas Skaggs (nskaggs) : Posted in a previous version of this proposal | # |
Nicholas Skaggs (nskaggs) wrote : Posted in a previous version of this proposal | # |
split out the createdb logic into a new function, then we need to modify test_del_add_bug to use the createdb function.
Also, we need to call ensuredb in test_locationma
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
FAILED: Continuous integration, rev:169
http://
Executed test runs:
None: http://
None: http://
None: http://
Click here to trigger a rebuild:
http://
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
PASSED: Continuous integration, rev:169
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) : | # |
Preview Diff
1 | === added directory 'tests/autopilot/ubuntu_weather_app/Databases' | |||
2 | === added file 'tests/autopilot/ubuntu_weather_app/Databases/34e1e542f2f083ff18f537b07a380071.ini' | |||
3 | --- tests/autopilot/ubuntu_weather_app/Databases/34e1e542f2f083ff18f537b07a380071.ini 1970-01-01 00:00:00 +0000 | |||
4 | +++ tests/autopilot/ubuntu_weather_app/Databases/34e1e542f2f083ff18f537b07a380071.ini 2013-12-17 19:01:06 +0000 | |||
5 | @@ -0,0 +1,6 @@ | |||
6 | 1 | [General] | ||
7 | 2 | Description=Default Ubuntu weather app | ||
8 | 3 | Driver=QSQLITE | ||
9 | 4 | EstimatedSize=100000 | ||
10 | 5 | Name=com.ubuntu.weather | ||
11 | 6 | Version=0.3 | ||
12 | 0 | 7 | ||
13 | === added file 'tests/autopilot/ubuntu_weather_app/Databases/34e1e542f2f083ff18f537b07a380071.sqlite' | |||
14 | 1 | Binary files tests/autopilot/ubuntu_weather_app/Databases/34e1e542f2f083ff18f537b07a380071.sqlite 1970-01-01 00:00:00 +0000 and tests/autopilot/ubuntu_weather_app/Databases/34e1e542f2f083ff18f537b07a380071.sqlite 2013-12-17 19:01:06 +0000 differ | 8 | Binary files tests/autopilot/ubuntu_weather_app/Databases/34e1e542f2f083ff18f537b07a380071.sqlite 1970-01-01 00:00:00 +0000 and tests/autopilot/ubuntu_weather_app/Databases/34e1e542f2f083ff18f537b07a380071.sqlite 2013-12-17 19:01:06 +0000 differ |
15 | === modified file 'tests/autopilot/ubuntu_weather_app/tests/__init__.py' | |||
16 | --- tests/autopilot/ubuntu_weather_app/tests/__init__.py 2013-12-13 15:30:46 +0000 | |||
17 | +++ tests/autopilot/ubuntu_weather_app/tests/__init__.py 2013-12-17 19:01:06 +0000 | |||
18 | @@ -14,6 +14,8 @@ | |||
19 | 14 | import sqlite3 | 14 | import sqlite3 |
20 | 15 | import time | 15 | import time |
21 | 16 | import logging | 16 | import logging |
22 | 17 | import os | ||
23 | 18 | import shutil | ||
24 | 17 | 19 | ||
25 | 18 | from autopilot.input import Mouse, Touch, Pointer | 20 | from autopilot.input import Mouse, Touch, Pointer |
26 | 19 | from autopilot.platform import model | 21 | from autopilot.platform import model |
27 | @@ -21,6 +23,8 @@ | |||
28 | 21 | from testtools.matchers import Equals | 23 | from testtools.matchers import Equals |
29 | 22 | from autopilot.matchers import Eventually | 24 | from autopilot.matchers import Eventually |
30 | 23 | 25 | ||
31 | 26 | import ubuntu_weather_app | ||
32 | 27 | |||
33 | 24 | from ubuntuuitoolkit import emulators as toolkit_emulators | 28 | from ubuntuuitoolkit import emulators as toolkit_emulators |
34 | 25 | from ubuntu_weather_app.emulators import MainView | 29 | from ubuntu_weather_app.emulators import MainView |
35 | 26 | 30 | ||
36 | @@ -126,12 +130,14 @@ | |||
37 | 126 | Helper functions for dealing with sqlite databases | 130 | Helper functions for dealing with sqlite databases |
38 | 127 | """ | 131 | """ |
39 | 128 | 132 | ||
42 | 129 | db_path = os.path.expanduser( | 133 | app_dir = os.path.expanduser( |
43 | 130 | "~/.local/share/com.ubuntu.weather/Databases") | 134 | "~/.local/share/com.ubuntu.weather") |
44 | 135 | db_dir = os.path.join(app_dir, 'Databases') | ||
45 | 136 | db_file = "34e1e542f2f083ff18f537b07a380071.sqlite" | ||
46 | 137 | db_path = os.path.join(db_dir, db_file) | ||
47 | 131 | 138 | ||
48 | 132 | def _execute_sql(self, statement): | 139 | def _execute_sql(self, statement): |
51 | 133 | path = self.find_db() | 140 | conn = sqlite3.connect(self.db_path) |
50 | 134 | conn = sqlite3.connect(path) | ||
52 | 135 | cursor = conn.cursor() | 141 | cursor = conn.cursor() |
53 | 136 | logger.debug("Executing sql") | 142 | logger.debug("Executing sql") |
54 | 137 | logger.debug(statement) | 143 | logger.debug(statement) |
55 | @@ -139,37 +145,10 @@ | |||
56 | 139 | conn.commit() | 145 | conn.commit() |
57 | 140 | conn.close() | 146 | conn.close() |
58 | 141 | 147 | ||
59 | 142 | def find_db(self): | ||
60 | 143 | if not os.path.exists(self.db_path): | ||
61 | 144 | logger.debug("Database not found in ~/.local/share/") | ||
62 | 145 | return None | ||
63 | 146 | |||
64 | 147 | logger.debug("Database found in ~/.local/share/") | ||
65 | 148 | files = [f for f in os.listdir(self.db_path) | ||
66 | 149 | if os.path.splitext(f)[1] == ".ini"] | ||
67 | 150 | for f in files: | ||
68 | 151 | ini_path = os.path.join(self.db_path, f) | ||
69 | 152 | with open(ini_path) as ini: | ||
70 | 153 | for line in ini: | ||
71 | 154 | if "=" in line: | ||
72 | 155 | key, val = line.strip().split("=") | ||
73 | 156 | if key == "Name" and val == "com.ubuntu.weather": | ||
74 | 157 | try: | ||
75 | 158 | logger.debug("Replaced ini com.ubuntu.weather key") | ||
76 | 159 | return ini_path.replace(".ini", ".sqlite") | ||
77 | 160 | except OSError: | ||
78 | 161 | logger.debug("No ini found to replace") | ||
79 | 162 | pass | ||
80 | 163 | return None | ||
81 | 164 | |||
82 | 165 | def clean_db(self): | 148 | def clean_db(self): |
88 | 166 | logger.debug("Removing existing database") | 149 | logger.debug("Removing existing database at %s" % self.db_dir) |
84 | 167 | path = self.find_db() | ||
85 | 168 | if path is None: | ||
86 | 169 | logger.debug("Existing database not found") | ||
87 | 170 | return | ||
89 | 171 | try: | 150 | try: |
91 | 172 | os.remove(path) | 151 | shutil.rmtree(self.db_dir) |
92 | 173 | except OSError: | 152 | except OSError: |
93 | 174 | logger.debug("Could not remove existing database") | 153 | logger.debug("Could not remove existing database") |
94 | 175 | pass | 154 | pass |
95 | @@ -177,6 +156,18 @@ | |||
96 | 177 | def create_blank_db(self): | 156 | def create_blank_db(self): |
97 | 178 | self.clean_db() | 157 | self.clean_db() |
98 | 179 | 158 | ||
99 | 159 | #create blank db | ||
100 | 160 | database_tmpl_dir = os.path.join( | ||
101 | 161 | os.path.dirname(ubuntu_weather_app.__file__), | ||
102 | 162 | 'Databases') | ||
103 | 163 | logger.debug("Creating blank db on filesystem %s" % self.db_dir) | ||
104 | 164 | if not os.path.exists(self.app_dir): | ||
105 | 165 | os.makedirs(self.app_dir) | ||
106 | 166 | shutil.copytree(database_tmpl_dir, self.db_dir) | ||
107 | 167 | self.assertThat( | ||
108 | 168 | lambda: os.path.exists(self.db_path), | ||
109 | 169 | Eventually(Equals(True))) | ||
110 | 170 | |||
111 | 180 | #this needs to stay in sync with Storage.qml enties | 171 | #this needs to stay in sync with Storage.qml enties |
112 | 181 | logger.debug("Creating locations and settings tables") | 172 | logger.debug("Creating locations and settings tables") |
113 | 182 | self._execute_sql("CREATE TABLE IF NOT EXISTS Locations(id INTEGER " | 173 | self._execute_sql("CREATE TABLE IF NOT EXISTS Locations(id INTEGER " |
114 | @@ -186,8 +177,7 @@ | |||
115 | 186 | "UNIQUE, value TEXT)") | 177 | "UNIQUE, value TEXT)") |
116 | 187 | 178 | ||
117 | 188 | def add_locations_to_database(self, locations): | 179 | def add_locations_to_database(self, locations): |
120 | 189 | path = self.find_db() | 180 | conn = sqlite3.connect(self.db_path) |
119 | 190 | conn = sqlite3.connect(path) | ||
121 | 191 | cursor = conn.cursor() | 181 | cursor = conn.cursor() |
122 | 192 | logger.debug("Adding locations to database") | 182 | logger.debug("Adding locations to database") |
123 | 193 | for loc_data in locations: | 183 | for loc_data in locations: |
124 | 194 | 184 | ||
125 | === modified file 'tests/autopilot/ubuntu_weather_app/tests/test_locationmanager.py' | |||
126 | --- tests/autopilot/ubuntu_weather_app/tests/test_locationmanager.py 2013-12-11 20:24:42 +0000 | |||
127 | +++ tests/autopilot/ubuntu_weather_app/tests/test_locationmanager.py 2013-12-17 19:01:06 +0000 | |||
128 | @@ -23,13 +23,14 @@ | |||
129 | 23 | class TestLocationManager(WeatherTestCase, DatabaseMixin, SheetMixin, LocationManagerMixin): | 23 | class TestLocationManager(WeatherTestCase, DatabaseMixin, SheetMixin, LocationManagerMixin): |
130 | 24 | 24 | ||
131 | 25 | def setUp(self): | 25 | def setUp(self): |
132 | 26 | #we want to start with no database | ||
133 | 26 | self.clean_db() | 27 | self.clean_db() |
134 | 27 | super(TestLocationManager, self).setUp() | 28 | super(TestLocationManager, self).setUp() |
135 | 28 | self.assertThat( | 29 | self.assertThat( |
136 | 29 | self.get_qml_view().visible, Eventually(Equals(True))) | 30 | self.get_qml_view().visible, Eventually(Equals(True))) |
137 | 30 | 31 | ||
138 | 31 | def _preload_database_and_launch(self): | 32 | def _preload_database_and_launch(self): |
140 | 32 | #close app | 33 | #we want to start with existing data |
141 | 33 | logger.debug("Closing app") | 34 | logger.debug("Closing app") |
142 | 34 | self.doCleanups() | 35 | self.doCleanups() |
143 | 35 | #wipe the existing database and create a new blank one | 36 | #wipe the existing database and create a new blank one |
144 | 36 | 37 | ||
145 | === modified file 'tests/autopilot/ubuntu_weather_app/tests/test_mainview.py' | |||
146 | --- tests/autopilot/ubuntu_weather_app/tests/test_mainview.py 2013-12-11 20:24:42 +0000 | |||
147 | +++ tests/autopilot/ubuntu_weather_app/tests/test_mainview.py 2013-12-17 19:01:06 +0000 | |||
148 | @@ -27,12 +27,8 @@ | |||
149 | 27 | """ This is needed to wait for the application to start. | 27 | """ This is needed to wait for the application to start. |
150 | 28 | In the testfarm, the application may take some time to show up.""" | 28 | In the testfarm, the application may take some time to show up.""" |
151 | 29 | def setUp(self): | 29 | def setUp(self): |
156 | 30 | #close app | 30 | #we want to start with fake location data |
153 | 31 | #logger.debug("Closing app") | ||
154 | 32 | #self.doCleanups() | ||
155 | 33 | #wipe the existing database and create a new blank one | ||
157 | 34 | self.create_blank_db() | 31 | self.create_blank_db() |
158 | 35 | # add settings to storage | ||
159 | 36 | logger.debug("Adding fake data to new database") | 32 | logger.debug("Adding fake data to new database") |
160 | 37 | self.add_locations_to_database(locations_data) | 33 | self.add_locations_to_database(locations_data) |
161 | 38 | logger.debug("Re-Launching app to introspect") | 34 | logger.debug("Re-Launching app to introspect") |
162 | 39 | 35 | ||
163 | === modified file 'tests/autopilot/ubuntu_weather_app/tests/test_settings.py' | |||
164 | --- tests/autopilot/ubuntu_weather_app/tests/test_settings.py 2013-12-11 20:24:42 +0000 | |||
165 | +++ tests/autopilot/ubuntu_weather_app/tests/test_settings.py 2013-12-17 19:01:06 +0000 | |||
166 | @@ -20,16 +20,11 @@ | |||
167 | 20 | 20 | ||
168 | 21 | class TestSettings(WeatherTestCase, DatabaseMixin, SheetMixin): | 21 | class TestSettings(WeatherTestCase, DatabaseMixin, SheetMixin): |
169 | 22 | def setUp(self): | 22 | def setUp(self): |
174 | 23 | #close app | 23 | #we want to start with fake settings data |
171 | 24 | #logger.debug("Closing app") | ||
172 | 25 | #self.doCleanups() | ||
173 | 26 | #wipe the existing database and create a new blank one | ||
175 | 27 | self.create_blank_db() | 24 | self.create_blank_db() |
176 | 28 | # add settings to storage | ||
177 | 29 | logger.debug("Adding fake data to new database") | 25 | logger.debug("Adding fake data to new database") |
178 | 30 | self.add_locations_to_database(locations_data) | 26 | self.add_locations_to_database(locations_data) |
179 | 31 | self.add_units_to_database() | 27 | self.add_units_to_database() |
180 | 32 | logger.debug("Re-Launching app to introspect") | ||
181 | 33 | super(TestSettings, self).setUp() | 28 | super(TestSettings, self).setUp() |
182 | 34 | self.assertThat( | 29 | self.assertThat( |
183 | 35 | self.get_qml_view().visible, Eventually(Equals(True))) | 30 | self.get_qml_view().visible, Eventually(Equals(True))) |
for readability I would prefer path.join to be used here expanduser( db_dir + db_file)
34 + db_path = os.path.