mozillians-tests/tests/test_redirects.py

53 строки
2.0 KiB
Python
Исходник Постоянная ссылка Обычный вид История

2013-04-10 03:45:03 +04:00
# 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
class TestRedirects:
@pytest.mark.nondestructive
2015-11-04 15:54:24 +03:00
def test_302_redirect_for_anonymous_users(self, base_url):
2013-04-17 19:17:38 +04:00
paths = ['/es/country/us/',
2015-05-21 13:46:42 +03:00
'/sq/country/doesnotexist/',
'/hu/country/us/region/California/',
'/pl/country/in/city/Gulbarga/',
'/zh-TW/group/webqa/',
'/zh-CN/group/258/join/',
'/sl/group/doesnotexit/',
'/pt-BR/u/moz.mozillians.unvouched/',
'/ca/u/UserDoesNotExist/',
'/nl/logout/',
'/lt/user/edit/',
'/en-US/invite/',
'/fr/register/']
2015-11-04 15:54:24 +03:00
urls = self.make_absolute_paths(base_url, paths)
error_list = self.verify_http_response_codes(urls, 302)
2016-02-18 14:12:31 +03:00
assert 0 == len(error_list), error_list
2013-04-17 01:02:22 +04:00
@pytest.mark.nondestructive
2015-11-04 15:54:24 +03:00
def test_200_for_anonymous_users(self, base_url):
paths = ['/pl/opensearch.xml', '/nl/u/Mozillians.User/']
2015-11-04 15:54:24 +03:00
urls = self.make_absolute_paths(base_url, paths)
2013-04-17 01:02:22 +04:00
error_list = self.verify_http_response_codes(urls, 200)
2016-02-18 14:12:31 +03:00
assert 0 == len(error_list), error_list
2013-04-17 01:02:22 +04:00
def make_absolute_paths(self, url, paths):
urls = []
for path in paths:
urls.append(url + path)
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