2013-04-10 03:45:03 +04:00
|
|
|
#!/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 unittestzero import Assert
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skip_selenium
|
|
|
|
class TestRedirects:
|
|
|
|
|
2013-04-17 19:13:42 +04:00
|
|
|
_paths = ['/es/country/us/',
|
2013-04-10 03:45:03 +04:00
|
|
|
'/sq/country/doesnotexist/',
|
|
|
|
'/ar/country/us/region/California/',
|
|
|
|
'/pl/country/us/city/',
|
|
|
|
'/zh-TW/group/webqa/',
|
|
|
|
'/zh-CN/group/258-l10n/toggle/',
|
|
|
|
'/sl/group/doesnotexit/',
|
|
|
|
'/rl/u/MozilliansUser/',
|
|
|
|
'/pt-BR/u/moz.mozillians.unvouched/',
|
|
|
|
'/ca/u/UserDoesNotExist',
|
|
|
|
'/nl/logout/',
|
|
|
|
'/lt/user/edit/',
|
|
|
|
'/en-US/invite/']
|
|
|
|
|
2013-04-17 01:02:05 +04:00
|
|
|
@pytest.mark.xfail(reason='Disabled until Bug 846039 is fixed')
|
2013-04-10 03:45:03 +04:00
|
|
|
@pytest.mark.nondestructive
|
|
|
|
def test_302_redirect_for_anonomous_users(self, mozwebqa):
|
2013-04-17 19:13:42 +04:00
|
|
|
urls = self.make_absolute_paths(mozwebqa.base_url, self._paths)
|
2013-04-13 01:25:36 +04:00
|
|
|
error_list = self.verify_http_response_codes(urls, 302)
|
2013-04-10 03:45:03 +04:00
|
|
|
|
|
|
|
Assert.equal(0, len(error_list), error_list)
|
2013-04-13 01:25:36 +04:00
|
|
|
|
2013-04-17 01:02:22 +04:00
|
|
|
@pytest.mark.nondestructive
|
|
|
|
def test_200_for_anonymous_users(self, mozwebqa):
|
2013-04-17 19:13:42 +04:00
|
|
|
paths = ['/pl/opensearch.xml', '/nl/u/MozilliansUser/']
|
|
|
|
urls = self.make_absolute_paths(mozwebqa.base_url, paths)
|
2013-04-17 01:02:22 +04:00
|
|
|
error_list = self.verify_http_response_codes(urls, 200)
|
|
|
|
|
|
|
|
Assert.equal(len(error_list), 0, error_list)
|
|
|
|
|
2013-04-13 01:25:36 +04:00
|
|
|
def make_absolute_paths(self, url, dirs):
|
|
|
|
urls = []
|
|
|
|
for dir in dirs:
|
|
|
|
urls.append(url + dir)
|
|
|
|
return urls
|
|
|
|
|
|
|
|
def verify_http_response_codes(self, urls, expected_http_value):
|
|
|
|
error_list = []
|
|
|
|
for url in urls:
|
|
|
|
# prevent redirects, we only want the value of the 1st HTTP status
|
|
|
|
response = requests.get(url, allow_redirects=False)
|
|
|
|
http_status = response.status_code
|
|
|
|
if http_status != expected_http_value:
|
|
|
|
error_list.append('Expected %s but got %s. %s' %
|
|
|
|
(expected_http_value, http_status, url))
|
|
|
|
return error_list
|