diff mbox

[Branch,~linaro-image-tools/linaro-image-tools/trunk] Rev 409: Modifications that change the fetch image library unit tests to use local files, not downloaded o...

Message ID 20110818092915.1732.43382.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

James Tunnicliffe Aug. 18, 2011, 9:29 a.m. UTC
Merge authors:
  James Tunnicliffe (dooferlad)
Related merge proposals:
  https://code.launchpad.net/~dooferlad/linaro-image-tools/fetch_image_unit_tests_use_local_files/+merge/71243
  proposed by: James Tunnicliffe (dooferlad)
  review: Approve - James Westby (james-w)
------------------------------------------------------------
revno: 409 [merge]
committer: James Tunnicliffe <james.tunnicliffe@linaro.org>
branch nick: linaro-image-tools
timestamp: Thu 2011-08-18 10:28:12 +0100
message:
  Modifications that change the fetch image library unit tests to use local files, not downloaded ones.
added:
  linaro_image_tools/tests/test_server_index.sqlite
modified:
  linaro_image_tools/tests/test_fetch_image.py


--
lp:linaro-image-tools
https://code.launchpad.net/~linaro-image-tools/linaro-image-tools/trunk

You are subscribed to branch lp:linaro-image-tools.
To unsubscribe from this branch go to https://code.launchpad.net/~linaro-image-tools/linaro-image-tools/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'linaro_image_tools/tests/test_fetch_image.py'
--- linaro_image_tools/tests/test_fetch_image.py	2011-07-26 15:40:32 +0000
+++ linaro_image_tools/tests/test_fetch_image.py	2011-08-17 13:18:37 +0000
@@ -16,28 +16,34 @@ 
 #
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-import wx
-import unittest
+import os
+from linaro_image_tools.testing import TestCaseWithFixtures
 import re
 import linaro_image_tools.fetch_image as fetch_image
 
 
-class TestURLLookupFunctions(unittest.TestCase):
+class TestURLLookupFunctions(TestCaseWithFixtures):
 
     def setUp(self):
+        # We use local files for testing, so get paths sorted.
+        this_file = os.path.abspath(__file__)
+        this_dir = os.path.dirname(this_file)
+        yaml_file_location = os.path.join(this_dir, "../"
+                                          "fetch_image_settings.yaml")
+        sample_db_location = os.path.join(this_dir, "test_server_index.sqlite")
         self.file_handler   = fetch_image.FileHandler()
-        self.file_handler.update_files_from_server()
         self.config         = fetch_image.FetchImageConfig()
         self.config.settings["force_download"] = False
 
         # Load settings YAML, which defines the parameters we ask for and
         # acceptable responses from the user
-        self.config.read_config(self.file_handler.settings_file)
+        self.config.read_config(yaml_file_location)
 
         # Using the config we have, look up URLs to download data from in the
         # server index
-        self.db = fetch_image.DB(self.file_handler.index_file)
+        self.db = fetch_image.DB(sample_db_location)
+
+        super(TestURLLookupFunctions, self).setUp()
 
     def test_url_lookup(self):
         self.settings = self.config.settings
@@ -45,10 +51,14 @@ 
 
         #--- Test first with a snapshot build lookup ---
         # -- Fix a build date --
-        # We only need to look up a single snapshot date. Start with today and
-        # go with the day in the DB, build 0
-        today = wx.DateTime()
-        today.SetToCurrent()
+        # We only need to look up a single snapshot date. We just use the
+        # latest in the database (we could use today and search from it, but
+        # the database is just one that is checked in, so it could be old
+        # and db.get_next_prev_day_with_builds may give up before finding it).
+        date = self.db.execute_return_list(
+                          "SELECT MAX(date) FROM snapshot_binaries")[0][0]
+        d = re.search("(\d{4})(\d{2})(\d{2})", date)
+        date = (d.group(1) + "-" + d.group(2) + "-" + d.group(3))
 
         # -- Don't iterate through platforms for snapshot --
 
@@ -61,7 +71,7 @@ 
 
             future_date, past_date = self.db.get_next_prev_day_with_builds(
                                         "linaro-alip",
-                                        today.FormatISODate().encode('ascii'),
+                                        date,
                                         compatable_hwpacks)
 
             if past_date == None:

=== added file 'linaro_image_tools/tests/test_server_index.sqlite'
Binary files linaro_image_tools/tests/test_server_index.sqlite	1970-01-01 00:00:00 +0000 and linaro_image_tools/tests/test_server_index.sqlite	2011-08-11 16:18:34 +0000 differ