Permalink
Browse files

Merge pull request #29 from bobsilverberg/moar_info

Add additional info to failure messages
  • Loading branch information...
2 parents a585001 + 26af59d commit e505f0c63183226628f45126f844bde3ce6b8e23 @retornam retornam committed Mar 27, 2013
Showing with 42 additions and 25 deletions.
  1. +9 −1 tests/base.py
  2. +33 −24 tests/test_redirects.py
View
@@ -4,8 +4,8 @@
# You can obtain one at http://mozilla.org/MPL/2.0/.
import requests
+import socket
from bs4 import BeautifulSoup
-from unittestzero import Assert
class Base:
@@ -21,3 +21,11 @@ def _head_request(self, url, user_agent=_user_agent_firefox, locale='en-US', par
def _parse_response(self, content):
return BeautifulSoup(content)
+
+ def response_info_failure_message(self, url, param, response):
+ return 'Failed on %s \nUsing %s.\n %s' % (url, param, self.response_info(response))
+
+ def response_info(self, response):
+ url = response.url
+ x_backend_server = response.headers['X-Backend-Server']
+ return 'Response URL: %s\n X-Backend-Server: %s' % (url, x_backend_server)
View
@@ -25,16 +25,17 @@ def test_that_checks_redirect_using_incorrect_query_values(self, testsetup):
url = testsetup.base_url
response = self._head_request(url, params=param)
- Assert.equal(response.status_code, requests.codes.not_found, 'Failed on %s \nUsing %s' % (url, param))
+ Assert.equal(response.status_code, requests.codes.not_found,
+ self.response_info_failure_message(url, param, response))
parsed_url = urlparse(response.url)
Assert.equal(parsed_url.scheme, 'http',
- 'Failed by redirected to HTTPS on %s \n \
- Using %s \n \
- Redirect to %s' % \
- (url, param, response.url))
- Assert.equal(parsed_url.netloc, urlparse(url).netloc, 'Failed on %s \nUsing %s' % (url, param))
- Assert.equal(parsed_url.query, urlencode(param), 'Failed on %s \nUsing %s' % (url, param))
+ 'Failed by redirected to incorrect scheme %s. \n %s' %
+ (parsed_url.scheme, self.response_info_failure_message(url, param, response)))
+ Assert.equal(parsed_url.netloc, urlparse(url).netloc,
+ self.response_info_failure_message(url, param, response))
+ Assert.equal(parsed_url.query, urlencode(param),
+ self.response_info_failure_message(url, param, response))
def test_that_checks_redirect_using_locales_and_os(self, testsetup, lang, os):
@@ -55,11 +56,11 @@ def test_that_checks_redirect_using_locales_and_os(self, testsetup, lang, os):
parsed_url = urlparse(response.url)
Assert.equal(response.status_code, requests.codes.ok,
- 'Redirect failed with HTTP status %s on %s \n \
- For %s\n \
- Redirected to %s' % \
- (response.status_code, url, param, response.url))
- Assert.equal(parsed_url.scheme, 'http', 'Failed on %s \nUsing %s' % (url, param))
+ 'Redirect failed with HTTP status %s. \n %s' %
+ (response.status_code, self.response_info_failure_message(url, param, response)))
+ Assert.equal(parsed_url.scheme, 'http',
+ 'Failed by redirected to incorrect scheme %s. \n %s' %
+ (parsed_url.scheme, self.response_info_failure_message(url, param, response)))
@pytest.mark.xfail(reason='there currently is not a stub installer -- xfailing until one lands in the wild')
def test_stub_installer_redirect_for_en_us_and_win(self, testsetup):
@@ -74,15 +75,21 @@ def test_stub_installer_redirect_for_en_us_and_win(self, testsetup):
parsed_url = urlparse(response.url)
- Assert.equal(response.status_code, requests.codes.ok, 'Failed on %s \nUsing %s' % (url, param))
- Assert.equal(parsed_url.scheme, 'https', 'Failed on %s \nUsing %s' % (url, param))
- Assert.equal(parsed_url.netloc, 'download-installer.cdn.mozilla.net', 'Failed on %s \nUsing %s' % (url, param))
+ Assert.equal(response.status_code, requests.codes.ok,
+ 'Redirect failed with HTTP status %s. \n %s' %
+ (response.status_code, self.response_info_failure_message(url, param, response)))
+ Assert.equal(parsed_url.scheme, 'https',
+ 'Failed by redirected to incorrect scheme %s. \n %s' %
+ (parsed_url.scheme, self.response_info_failure_message(url, param, response)))
+ Assert.equal(parsed_url.netloc, 'download-installer.cdn.mozilla.net',
+ 'Failed by redirected to incorrect host %s. \n %s' %
+ (parsed_url.netloc, self.response_info_failure_message(url, param, response)))
@pytest.mark.parametrize('product_alias', [
{'product_name': 'firefox-beta-latest', 'lang': 'en-US'},
{'product_name': 'firefox-latest-euballot', 'lang': 'en-GB'},
{'product_name': 'firefox-latest', 'lang': 'en-US'},
- ])
+ ])
def test_redirect_for_firefox_aliases(self, testsetup, product_alias):
if product_alias == {'product_name': 'firefox-latest', 'lang': 'en-US'}:
@@ -104,16 +111,18 @@ def test_redirect_for_firefox_aliases(self, testsetup, product_alias):
"download.allizom.org" in testsetup.base_url
):
Assert.equal(response.status_code, requests.codes.ok,
- 'Redirect failed with HTTP status %s on %s \n \
- For %s\n \
- Redirected to %s' % \
- (response.status_code, url, param, response.url))
- Assert.equal(parsed_url.scheme, 'http', 'Failed on %s \nUsing %s' % (url, param))
- Assert.equal(parsed_url.netloc, 'download.cdn.mozilla.net', 'Failed on %s \nUsing %s' % (url, param))
+ 'Redirect failed with HTTP status %s. \n %s' %
+ (response.status_code, self.response_info_failure_message(url, param, response)))
+ Assert.equal(parsed_url.scheme, 'http',
+ 'Failed by redirected to incorrect scheme %s. \n %s' %
+ (parsed_url.scheme, self.response_info_failure_message(url, param, response)))
+ Assert.equal(parsed_url.netloc, 'download.cdn.mozilla.net',
+ 'Failed by redirected to incorrect host %s. \n %s' %
+ (parsed_url.netloc, self.response_info_failure_message(url, param, response)))
if (
product_alias['product_name'] != 'firefox-nightly-latest' and
product_alias['product_name'] != 'firefox-aurora-latest' and
product_alias['product_name'] != 'firefox-latest-euballot'
):
- Assert.contains('/%s/' % 'win32', parsed_url.path)
-
+ Assert.contains('/%s/' % 'win32', parsed_url.path,
+ '\n %s' % self.response_info(response))

0 comments on commit e505f0c

Please sign in to comment.