Bug 1290850 - Force local update URL for software update unit tests. r=maja_zf

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

--HG--
extra : rebase_source : 85900716de5c868efd8f0411e0c577f317d98d25
This commit is contained in:
Henrik Skupin 2017-04-24 15:09:25 +02:00
parent f588ac7e28
commit 56bc9b1cb8
4 changed files with 26 additions and 15 deletions

View File

@ -0,0 +1,3 @@
<?xml version="1.0"?>
<updates>
</updates>

View File

@ -8,7 +8,6 @@ tags = local
[test_security.py]
tags = remote
[test_software_update.py]
tags = remote
[test_utils.py]
# UI tests

View File

@ -32,16 +32,24 @@ class TestSoftwareUpdate(PuppeteerMixin, MarionetteTestCase):
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')
@ -95,6 +103,7 @@ class TestUpdateChannel(PuppeteerMixin, MarionetteTestCase):
# 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)

View File

@ -5,6 +5,7 @@
import ConfigParser
import os
import re
import sys
import mozinfo
@ -359,15 +360,14 @@ class SoftwareUpdate(BaseLib):
: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.