Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add additional info to failure messages #29

Merged
merged 1 commit into from

5 participants

@bobsilverberg

This addresses issue #28

@superawesome

I'm unqualified to review this, leaving for others

@m8ttyB m8ttyB commented on the diff
tests/base.py
@@ -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):
@m8ttyB Owner
m8ttyB added a note

What does param correspond to? Is that the expected result?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@m8ttyB m8ttyB commented on the diff
tests/base.py
@@ -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']
@m8ttyB Owner
m8ttyB added a note

perhaps add a code comment about why we're interested in this particular header.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@m8ttyB
Owner

Nice job cleaning up the code! lgtm and purrs (aka runs) like a kitten doing avalanche control work in the high mountains.

py.test -n 4 tests/test_redirects.py --baseurl=http://download.mozilla.org
==================== 273 passed, 2 xfailed in 6.67 seconds =====================

py.test -n 5 tests/test_redirects.py --baseurl=http://download.allizom.org
==================== 272 passed, 3 xfailed in 18.97 seconds ====================

kitten

@retornam retornam merged commit e505f0c into mozilla:master
@m8ttyB m8ttyB commented on the diff
tests/test_redirects.py
((7 lines not shown))
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' %
@m8ttyB Owner
m8ttyB added a note

Suggestion:
s/Failed by redirected to incorrect scheme/Failed: redirected to incorrect scheme/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@m8ttyB m8ttyB commented on the diff
tests/test_redirects.py
@@ -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' %
@m8ttyB Owner
m8ttyB added a note

Suggestion:
s/Redirect failed with HTTP status/Failed: redirect failed with HTTP status/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 27, 2013
  1. @bobsilverberg
This page is out of date. Refresh to see the latest.
Showing with 42 additions and 25 deletions.
  1. +9 −1 tests/base.py
  2. +33 −24 tests/test_redirects.py
View
10 tests/base.py
@@ -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):
@m8ttyB Owner
m8ttyB added a note

What does param correspond to? Is that the expected result?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ 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']
@m8ttyB Owner
m8ttyB added a note

perhaps add a code comment about why we're interested in this particular header.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ return 'Response URL: %s\n X-Backend-Server: %s' % (url, x_backend_server)
View
57 tests/test_redirects.py
@@ -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' %
@m8ttyB Owner
m8ttyB added a note

Suggestion:
s/Failed by redirected to incorrect scheme/Failed: redirected to incorrect scheme/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ (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' %
@m8ttyB Owner
m8ttyB added a note

Suggestion:
s/Redirect failed with HTTP status/Failed: redirect failed with HTTP status/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ (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))
Something went wrong with that request. Please try again.