This repository has been archived by the owner on Apr 25, 2020. It is now read-only.
forked from mozilla/mcom-tests
-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_l10n_download_links.py
executable file
·72 lines (64 loc) · 3.01 KB
/
test_l10n_download_links.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
#!/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 bs4 import BeautifulSoup
from unittestzero import Assert
@pytest.mark.skip_selenium
@pytest.mark.nondestructive
class TestLocalisedDownloadLinks:
def get_language_rows(self, mozwebqa, link='/firefox/all.html'):
'''
Get all links for each locale on the page under test.
The default page under test is /firefox/all.html .
'''
url = "%s/%s" % (mozwebqa.base_url, link)
page_response = requests.get(url)
html = BeautifulSoup(page_response.content)
language_rows = html.findAll('tr', id=True)
return language_rows
def get_locale_code_from_links(self, mozwebqa, language_rows):
'''
Check that bouncer links have the right locale code.
'''
bad_links = []
for language in language_rows:
links = language.findAll('a')
for link in links:
url = link['href']
response = requests.head(url, allow_redirects=True)
if language['id'] not in response.url:
bad_links.append("Lang '%s' not in response: %s \n"
% (language['id'], response.url))
return bad_links
def get_302_response_code_from_links(self, mozwebqa, language_rows):
'''
Check that download links return a status 302.
'''
bad_links = []
for language in language_rows:
links = language.findAll('a')
for link in links:
url = link['href']
response = requests.head(url, allow_redirects=False)
status = response.status_code
if not (300 < status <= 302):
bad_links.append("Lang '%s' %s link: status %s"
% (language['id'], link['href'], status))
return bad_links
def test_links_on_firefox_all(self, mozwebqa):
language_rows = self.get_language_rows(mozwebqa)
result = self.get_locale_code_from_links(mozwebqa, language_rows)
Assert.equal(0, len(result), " ".join(result))
second_result = self.get_302_response_code_from_links(mozwebqa, language_rows)
Assert.equal(0, len(second_result),
"Expected status code 302. " + ", ".join(second_result))
def test_links_on_firefox_organization_all(self, mozwebqa):
language_rows = self.get_language_rows(mozwebqa, link='/firefox/organizations/all.html')
result = self.get_locale_code_from_links(mozwebqa, language_rows)
Assert.equal(0, len(result), " ".join(result))
second_result = self.get_302_response_code_from_links(mozwebqa, language_rows)
Assert.equal(0, len(second_result),
"Expected status code 302. " + ", ".join(second_result))