Merge lp:~nskaggs/ubuntu-weather-app/add-createdb into lp:ubuntu-weather-app/obsolete.trunk

Proposed by Nicholas Skaggs
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
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

To post a comment you must log in.
Revision history for this message
Sergio Schvezov (sergiusens) wrote : Posted in a previous version of this proposal

for readability I would prefer path.join to be used here
34 + db_path = os.path.expanduser(db_dir + db_file)

Revision history for this message
Sergio Schvezov (sergiusens) wrote : Posted in a previous version of this proposal

37 + subprocess.check_call([
38 + "mkdir",
39 + "-p",
40 + "~/.local/share/com.ubuntu.weather/"])

why aren't you usig os.makedirs?

review: Needs Fixing
Revision history for this message
Sergio Schvezov (sergiusens) wrote : Posted in a previous version of this proposal

32 + db_dir = "~/.local/share/com.ubuntu.weather/Databases/"
33 + db_file = "34e1e542f2f083ff18f537b07a380071.sqlite"
34 + db_path = os.path.expanduser(db_dir + db_file)
35 +
36 + if not os.path.exists(db_path):
37 + subprocess.check_call([
38 + "mkdir",
39 + "-p",
        You need the module path
40 + "~/.local/share/com.ubuntu.weather/"])
41 + shutil.copytree("ubuntu_weather_app/databases/", db_dir)

Approximation...
db_dir = "~/.local/share/com.ubuntu.weather/Databases/"
db_file = "34e1e542f2f083ff18f537b07a380071.sqlite"
db_path = os.path.join(os.path.expanduser(db_dir, db_file))
if not os.path.exists(db_path):
    # it's what we want
    os.makedirs(db_dir)
    # you'll need the python module location
    shutil.copytree("ubuntu_weather_app/Databases/", db_dir)

review: Needs Fixing
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : Posted in a previous version of this proposal
review: Approve (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : Posted in a previous version of this proposal
review: Approve (continuous-integration)
Revision history for this message
Nicholas Skaggs (nskaggs) wrote : Posted in a previous version of this proposal

Any concerns about the relative copy?

shutil.copytree("ubuntu_weather_app/Databases/", db_dir)

Revision history for this message
Nicholas Skaggs (nskaggs) wrote : Posted in a previous version of this proposal

Runs on my mako with and without existing db

Revision history for this message
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/autopilot/ubuntu_weather_app/tests/__init__.py'
--- tests/autopilot/ubuntu_weather_app/tests/__init__.py 2013-12-17 17:09:10 +0000
+++ tests/autopilot/ubuntu_weather_app/tests/__init__.py 2013-12-17 17:25:10 +0000
@@ -89,13 +89,14 @@
         return self.app.select_single("QQuickView")

     def ensure_db(self):
- db_dir = "~/.local/share/com.ubuntu.weather/Databases/"
+ weather_dir = os.path.expanduser(
+ "~/.local/share/com.ubuntu.weather")
+ db_dir = os.path.join(weather_dir, 'Databases')
         db_file = "34e1e542f2f083ff18f537b07a380071.sqlite"
- abs_path = os.path.expanduser(db_dir)
- db_path = os.path.join(abs_path, db_file)
+ db_path = os.path.join(db_dir, db_file)

         if not os.path.exists(db_path):
- os.makedirs(os.path.expanduser("~/.local/share/com.ubuntu.weather"))
+ os.makedirs(weather_dir)
             shutil.copytree("ubuntu_weather_app/Databases/", db_dir)
             self.assertThat(
                 lambda: os.path.exists(db_path),

Revision history for this message
Sergio Schvezov (sergiusens) wrote : Posted in a previous version of this proposal

And for the module path you'll need something like

        database_tmpl_dir = os.path.join(os.path.dirname(ubuntu_weather_app.__file__),
                                   'Databases')

Revision history for this message
Nicholas Skaggs (nskaggs) wrote : Posted in a previous version of this proposal

I agree with Sergio. Should be more robust that way. Thanks Sergio!

Revision history for this message
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 :-)

Revision history for this message
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.

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
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://code.launchpad.net/~sergiusens/ubuntu-weather-app/db_create/+merge/199333/+edit-commit-message

http://91.189.93.70:8080/job/ubuntu-weather-app-ci/106/
Executed test runs:
    UNSTABLE: http://91.189.93.70:8080/job/generic-mediumtests-trusty/487
    SUCCESS: http://91.189.93.70:8080/job/ubuntu-weather-app-raring-amd64-ci/104
    SUCCESS: http://91.189.93.70:8080/job/ubuntu-weather-app-saucy-amd64-ci/104
    SUCCESS: http://91.189.93.70:8080/job/ubuntu-weather-app-trusty-amd64-ci/18

Click here to trigger a rebuild:
http://91.189.93.70:8080/job/ubuntu-weather-app-ci/106/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Nicholas Skaggs (nskaggs) : Posted in a previous version of this proposal
review: Approve
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
Nicholas Skaggs (nskaggs) : Posted in a previous version of this proposal
review: Needs Fixing
Revision history for this message
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_locationmanager.py and test_settings.py too

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

I'm game

review: Approve
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
=== added directory 'tests/autopilot/ubuntu_weather_app/Databases'
=== added file 'tests/autopilot/ubuntu_weather_app/Databases/34e1e542f2f083ff18f537b07a380071.ini'
--- tests/autopilot/ubuntu_weather_app/Databases/34e1e542f2f083ff18f537b07a380071.ini 1970-01-01 00:00:00 +0000
+++ tests/autopilot/ubuntu_weather_app/Databases/34e1e542f2f083ff18f537b07a380071.ini 2013-12-17 19:01:06 +0000
@@ -0,0 +1,6 @@
1[General]
2Description=Default Ubuntu weather app
3Driver=QSQLITE
4EstimatedSize=100000
5Name=com.ubuntu.weather
6Version=0.3
07
=== added file 'tests/autopilot/ubuntu_weather_app/Databases/34e1e542f2f083ff18f537b07a380071.sqlite'
1Binary 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 differ8Binary 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
=== modified file 'tests/autopilot/ubuntu_weather_app/tests/__init__.py'
--- tests/autopilot/ubuntu_weather_app/tests/__init__.py 2013-12-13 15:30:46 +0000
+++ tests/autopilot/ubuntu_weather_app/tests/__init__.py 2013-12-17 19:01:06 +0000
@@ -14,6 +14,8 @@
14import sqlite314import sqlite3
15import time15import time
16import logging16import logging
17import os
18import shutil
1719
18from autopilot.input import Mouse, Touch, Pointer20from autopilot.input import Mouse, Touch, Pointer
19from autopilot.platform import model21from autopilot.platform import model
@@ -21,6 +23,8 @@
21from testtools.matchers import Equals23from testtools.matchers import Equals
22from autopilot.matchers import Eventually24from autopilot.matchers import Eventually
2325
26import ubuntu_weather_app
27
24from ubuntuuitoolkit import emulators as toolkit_emulators28from ubuntuuitoolkit import emulators as toolkit_emulators
25from ubuntu_weather_app.emulators import MainView29from ubuntu_weather_app.emulators import MainView
2630
@@ -126,12 +130,14 @@
126 Helper functions for dealing with sqlite databases130 Helper functions for dealing with sqlite databases
127 """131 """
128132
129 db_path = os.path.expanduser(133 app_dir = os.path.expanduser(
130 "~/.local/share/com.ubuntu.weather/Databases")134 "~/.local/share/com.ubuntu.weather")
135 db_dir = os.path.join(app_dir, 'Databases')
136 db_file = "34e1e542f2f083ff18f537b07a380071.sqlite"
137 db_path = os.path.join(db_dir, db_file)
131138
132 def _execute_sql(self, statement):139 def _execute_sql(self, statement):
133 path = self.find_db()140 conn = sqlite3.connect(self.db_path)
134 conn = sqlite3.connect(path)
135 cursor = conn.cursor()141 cursor = conn.cursor()
136 logger.debug("Executing sql")142 logger.debug("Executing sql")
137 logger.debug(statement)143 logger.debug(statement)
@@ -139,37 +145,10 @@
139 conn.commit()145 conn.commit()
140 conn.close()146 conn.close()
141147
142 def find_db(self):
143 if not os.path.exists(self.db_path):
144 logger.debug("Database not found in ~/.local/share/")
145 return None
146
147 logger.debug("Database found in ~/.local/share/")
148 files = [f for f in os.listdir(self.db_path)
149 if os.path.splitext(f)[1] == ".ini"]
150 for f in files:
151 ini_path = os.path.join(self.db_path, f)
152 with open(ini_path) as ini:
153 for line in ini:
154 if "=" in line:
155 key, val = line.strip().split("=")
156 if key == "Name" and val == "com.ubuntu.weather":
157 try:
158 logger.debug("Replaced ini com.ubuntu.weather key")
159 return ini_path.replace(".ini", ".sqlite")
160 except OSError:
161 logger.debug("No ini found to replace")
162 pass
163 return None
164
165 def clean_db(self):148 def clean_db(self):
166 logger.debug("Removing existing database")149 logger.debug("Removing existing database at %s" % self.db_dir)
167 path = self.find_db()
168 if path is None:
169 logger.debug("Existing database not found")
170 return
171 try:150 try:
172 os.remove(path)151 shutil.rmtree(self.db_dir)
173 except OSError:152 except OSError:
174 logger.debug("Could not remove existing database")153 logger.debug("Could not remove existing database")
175 pass154 pass
@@ -177,6 +156,18 @@
177 def create_blank_db(self):156 def create_blank_db(self):
178 self.clean_db()157 self.clean_db()
179158
159 #create blank db
160 database_tmpl_dir = os.path.join(
161 os.path.dirname(ubuntu_weather_app.__file__),
162 'Databases')
163 logger.debug("Creating blank db on filesystem %s" % self.db_dir)
164 if not os.path.exists(self.app_dir):
165 os.makedirs(self.app_dir)
166 shutil.copytree(database_tmpl_dir, self.db_dir)
167 self.assertThat(
168 lambda: os.path.exists(self.db_path),
169 Eventually(Equals(True)))
170
180 #this needs to stay in sync with Storage.qml enties171 #this needs to stay in sync with Storage.qml enties
181 logger.debug("Creating locations and settings tables")172 logger.debug("Creating locations and settings tables")
182 self._execute_sql("CREATE TABLE IF NOT EXISTS Locations(id INTEGER "173 self._execute_sql("CREATE TABLE IF NOT EXISTS Locations(id INTEGER "
@@ -186,8 +177,7 @@
186 "UNIQUE, value TEXT)")177 "UNIQUE, value TEXT)")
187178
188 def add_locations_to_database(self, locations):179 def add_locations_to_database(self, locations):
189 path = self.find_db()180 conn = sqlite3.connect(self.db_path)
190 conn = sqlite3.connect(path)
191 cursor = conn.cursor()181 cursor = conn.cursor()
192 logger.debug("Adding locations to database")182 logger.debug("Adding locations to database")
193 for loc_data in locations:183 for loc_data in locations:
194184
=== modified file 'tests/autopilot/ubuntu_weather_app/tests/test_locationmanager.py'
--- tests/autopilot/ubuntu_weather_app/tests/test_locationmanager.py 2013-12-11 20:24:42 +0000
+++ tests/autopilot/ubuntu_weather_app/tests/test_locationmanager.py 2013-12-17 19:01:06 +0000
@@ -23,13 +23,14 @@
23class TestLocationManager(WeatherTestCase, DatabaseMixin, SheetMixin, LocationManagerMixin):23class TestLocationManager(WeatherTestCase, DatabaseMixin, SheetMixin, LocationManagerMixin):
2424
25 def setUp(self):25 def setUp(self):
26 #we want to start with no database
26 self.clean_db()27 self.clean_db()
27 super(TestLocationManager, self).setUp()28 super(TestLocationManager, self).setUp()
28 self.assertThat(29 self.assertThat(
29 self.get_qml_view().visible, Eventually(Equals(True)))30 self.get_qml_view().visible, Eventually(Equals(True)))
3031
31 def _preload_database_and_launch(self):32 def _preload_database_and_launch(self):
32 #close app33 #we want to start with existing data
33 logger.debug("Closing app")34 logger.debug("Closing app")
34 self.doCleanups()35 self.doCleanups()
35 #wipe the existing database and create a new blank one36 #wipe the existing database and create a new blank one
3637
=== modified file 'tests/autopilot/ubuntu_weather_app/tests/test_mainview.py'
--- tests/autopilot/ubuntu_weather_app/tests/test_mainview.py 2013-12-11 20:24:42 +0000
+++ tests/autopilot/ubuntu_weather_app/tests/test_mainview.py 2013-12-17 19:01:06 +0000
@@ -27,12 +27,8 @@
27 """ This is needed to wait for the application to start.27 """ This is needed to wait for the application to start.
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."""
29 def setUp(self):29 def setUp(self):
30 #close app30 #we want to start with fake location data
31 #logger.debug("Closing app")
32 #self.doCleanups()
33 #wipe the existing database and create a new blank one
34 self.create_blank_db()31 self.create_blank_db()
35 # add settings to storage
36 logger.debug("Adding fake data to new database")32 logger.debug("Adding fake data to new database")
37 self.add_locations_to_database(locations_data)33 self.add_locations_to_database(locations_data)
38 logger.debug("Re-Launching app to introspect")34 logger.debug("Re-Launching app to introspect")
3935
=== modified file 'tests/autopilot/ubuntu_weather_app/tests/test_settings.py'
--- tests/autopilot/ubuntu_weather_app/tests/test_settings.py 2013-12-11 20:24:42 +0000
+++ tests/autopilot/ubuntu_weather_app/tests/test_settings.py 2013-12-17 19:01:06 +0000
@@ -20,16 +20,11 @@
2020
21class TestSettings(WeatherTestCase, DatabaseMixin, SheetMixin):21class TestSettings(WeatherTestCase, DatabaseMixin, SheetMixin):
22 def setUp(self):22 def setUp(self):
23 #close app23 #we want to start with fake settings data
24 #logger.debug("Closing app")
25 #self.doCleanups()
26 #wipe the existing database and create a new blank one
27 self.create_blank_db()24 self.create_blank_db()
28 # add settings to storage
29 logger.debug("Adding fake data to new database")25 logger.debug("Adding fake data to new database")
30 self.add_locations_to_database(locations_data)26 self.add_locations_to_database(locations_data)
31 self.add_units_to_database()27 self.add_units_to_database()
32 logger.debug("Re-Launching app to introspect")
33 super(TestSettings, self).setUp()28 super(TestSettings, self).setUp()
34 self.assertThat(29 self.assertThat(
35 self.get_qml_view().visible, Eventually(Equals(True)))30 self.get_qml_view().visible, Eventually(Equals(True)))

Subscribers

People subscribed via source and target branches