This repository has been archived by the owner on Aug 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
test_redirects.py
112 lines (90 loc) · 4.27 KB
/
test_redirects.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env python
# 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 pytest
import requests
from urlparse import urlparse
from urllib import urlencode
from unittestzero import Assert
from base import Base
class TestRedirects(Base):
def test_that_checks_redirect_using_incorrect_query_values(self, testsetup):
param = {
'product': 'firefox-16.0b6',
'lang': 'kitty_language',
'os': 'stella'
}
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))
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))
def test_that_checks_redirect_using_locales_and_os(self, testsetup, lang, os):
url = testsetup.base_url
# Ja locale has a special code for mac
if lang == 'ja' and os == 'osx':
lang = 'ja-JP-mac'
param = {
'product': 'firefox-16.0b6',
'lang': lang,
'os': os
}
response = self._head_request(url, params=param)
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))
@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):
url = testsetup.base_url
param = {
'product': testsetup.product,
'lang': 'en-US',
'os': 'win'
}
response = self._head_request(url, params=param)
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))
@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):
url = testsetup.base_url
param = {
'product': product_alias['product_name'],
'os': 'win',
'lang': product_alias['lang']
}
response = self._head_request(url, params=param)
parsed_url = urlparse(response.url)
if not (
product_alias['product_name'] == 'firefox-latest-euballot' and
"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))
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)