mozillians-tests/tests/test_redirects.py

61 строка
2.1 KiB
Python
Исходник Обычный вид История

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:
_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):
urls = self.make_absolute_paths(mozwebqa.base_url, self._paths)
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-17 01:02:22 +04:00
@pytest.mark.nondestructive
def test_200_for_anonymous_users(self, mozwebqa):
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)
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