Bug 1290850 - Force local update URL for software update unit tests. r=maja_zf a=test-only
authorHenrik Skupin <mail@hskupin.info>
Mon, 24 Apr 2017 15:09:25 +0200
changeset 393688 b310658e45376956c28bc43905a5490c5f495804
parent 393687 ca3c6131b6eadf753445b3cd7a54e29b41ab11aa
child 393689 a11c3d6524f962856911c253d51063dc07274934
push id7233
push usercbook@mozilla.com
push dateTue, 25 Apr 2017 12:42:17 +0000
treeherdermozilla-beta@8619db383886 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmaja_zf, test-only
bugs1290850
milestone54.0
Bug 1290850 - Force local update URL for software update unit tests. r=maja_zf a=test-only The unit tests for the software update class should not rely on the remote update URL being reachable. Instead a locally served URL has to be used. MozReview-Commit-ID: 8WNoEb0PUWz
testing/firefox-ui/resources/update/snippet_empty.xml
testing/firefox-ui/tests/puppeteer/manifest.ini
testing/firefox-ui/tests/puppeteer/test_software_update.py
testing/marionette/puppeteer/firefox/firefox_puppeteer/api/software_update.py
new file mode 100644
--- /dev/null
+++ b/testing/firefox-ui/resources/update/snippet_empty.xml
@@ -0,0 +1,3 @@
+<?xml version="1.0"?>
+<updates>
+</updates>
--- a/testing/firefox-ui/tests/puppeteer/manifest.ini
+++ b/testing/firefox-ui/tests/puppeteer/manifest.ini
@@ -3,17 +3,16 @@ tags = local
 
 # API tests
 [test_appinfo.py]
 [test_l10n.py]
 [test_places.py]
 [test_security.py]
 tags = remote
 [test_software_update.py]
-tags = remote
 [test_utils.py]
 
 # UI tests
 [test_about_window.py]
 [test_menubar.py]
 [test_notifications.py]
 [test_page_info_window.py]
 [test_tabbar.py]
--- a/testing/firefox-ui/tests/puppeteer/test_software_update.py
+++ b/testing/firefox-ui/tests/puppeteer/test_software_update.py
@@ -27,26 +27,34 @@ class TestSoftwareUpdate(PuppeteerMixin,
 
     def test_abi(self):
         self.assertTrue(self.software_update.ABI)
 
     def test_allowed(self):
         self.assertTrue(self.software_update.allowed)
 
     def test_build_info(self):
-        build_info = self.software_update.build_info
-        self.assertEqual(build_info['disabled_addons'], None)
-        self.assertIn('Mozilla/', build_info['user_agent'])
-        self.assertEqual(build_info['mar_channels'], set(['expected', 'channels']))
-        self.assertTrue(build_info['version'])
-        self.assertTrue(build_info['buildid'].isdigit())
-        self.assertTrue(build_info['locale'])
-        self.assertIn('force=1', build_info['update_url'])
-        self.assertIn('xml', build_info['update_snippet'])
-        self.assertEqual(build_info['channel'], self.software_update.update_channel)
+        self.software_update.update_url = self.marionette.absolute_url(
+            'update/snippet_empty.xml?product=%PRODUCT%&version=%VERSION%&'
+            'buildid=%BUILD_ID%&locale=%LOCALE%&channel=%CHANNEL%')
+
+        try:
+            build_info = self.software_update.build_info
+            self.assertEqual(build_info['disabled_addons'], None)
+            self.assertIn('Mozilla/', build_info['user_agent'])
+            self.assertEqual(build_info['mar_channels'], set(['expected', 'channels']))
+            self.assertTrue(build_info['version'])
+            self.assertTrue(build_info['buildid'].isdigit())
+            self.assertTrue(build_info['locale'])
+            self.assertIn('force=1', build_info['update_url'])
+            self.assertIn('xml', build_info['update_snippet'])
+            self.assertEqual(build_info['channel'], self.software_update.update_channel)
+        finally:
+            # Restart Firefox to reset the custom update url
+            self.restart(clean=True)
 
     def test_force_fallback(self):
         status_file = os.path.join(self.software_update.staging_directory, 'update.status')
 
         try:
             self.software_update.force_fallback()
             with open(status_file, 'r') as f:
                 content = f.read()
@@ -90,16 +98,17 @@ class TestUpdateChannel(PuppeteerMixin, 
         self.assertEqual(self.software_update.update_channel, self.saved_channel)
 
     def test_update_channel_set_channel(self):
         try:
             # Use the clean option to force a non in_app restart, which would allow
             # Firefox to dump the logs to the console.
             self.restart(clean=True)
             self.assertEqual(self.software_update.update_channel, 'expected_channel')
+            self.assertEqual(self.software_update.patch_info['channel'], 'expected_channel')
         finally:
             self.software_update.update_channel = self.saved_channel
             self.restart(clean=True)
 
 
 class TestMARChannels(PuppeteerMixin, MarionetteTestCase):
 
     def setUp(self):
--- a/testing/marionette/puppeteer/firefox/firefox_puppeteer/api/software_update.py
+++ b/testing/marionette/puppeteer/firefox/firefox_puppeteer/api/software_update.py
@@ -1,15 +1,16 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
 # You can obtain one at http://mozilla.org/MPL/2.0/.
 
 import ConfigParser
 import os
 import re
+import sys
 
 import mozinfo
 
 from firefox_puppeteer.base import BaseLib
 from firefox_puppeteer.api.appinfo import AppInfo
 
 
 class ActiveUpdate(BaseLib):
@@ -354,25 +355,24 @@ class SoftwareUpdate(BaseLib):
         with open(os.path.join(self.staging_directory, 'update.status'), 'w') as f:
             f.write('failed: 6\n')
 
     def get_update_snippet(self, update_url):
         """Retrieve contents of the update snippet.
 
         :param update_url: URL to the update snippet
         """
-        snippet = None
         try:
             import urllib2
             response = urllib2.urlopen(update_url)
-            snippet = response.read()
+            return response.read()
         except Exception:
-            pass
+            exc, val, tb = sys.exc_info()
 
-        return snippet
+            raise exc, "Failed to retrieve update snippet: {}".format(val.reason), tb
 
     def get_formatted_update_url(self, force=False):
         """Retrieve the formatted AUS update URL the update snippet is retrieved from.
 
         :param force: Boolean flag to force an update check
 
         :returns: The URL of the update snippet
         """