<commit_before># 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


LINK_TEMPLATE = '<link rel="canonical" hreflang="{lang}" href="{url}">'


@pytest.mark.headless
@pytest.mark.nondestructive
@pytest.mark.parametrize('url,locales', [
    ('/firefox/new/', ('en-US', 'de', 'id')),
    ('/firefox/', ('en-US', 'de', 'id')),
    ('/', ('en-US', 'de', 'id')),
])
def test_link_hreflang_tags(url, locales, base_url):
    for locale in locales:
        lang = locale if locale != 'en-US' else 'en'
        full_url = '{}/{}{}'.format(base_url, locale, url)
        link_url = '{}/{}{}'.format('https://www.mozilla.org', locale, url)
        resp = requests.get(full_url, timeout=5)
        assert LINK_TEMPLATE.format(lang=lang, url=link_url) in resp.content<commit_msg>[bug 1442327] Update hreflang headless tests<commit_after># 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


LINK_TEMPLATE = '<link rel="canonical" href="{url}">'


@pytest.mark.headless
@pytest.mark.nondestructive
@pytest.mark.parametrize('url,locales', [
    ('/firefox/new/', ('en-US', 'de', 'id')),
    ('/firefox/', ('en-US', 'de', 'id')),
    ('/', ('en-US', 'de', 'id')),
])
def test_link_hreflang_tags(url, locales, base_url):
    for locale in locales:
        full_url = '{}/{}{}'.format(base_url, locale, url)
        link_url = '{}/{}{}'.format('https://www.mozilla.org', locale, url)
        resp = requests.get(full_url, timeout=5)
        assert LINK_TEMPLATE.format(url=link_url) in resp.content
{'fraction_non_alphanumeric': 0.18474114441416895, 'fraction_numerical': 0.009264305177111716, 'mean_word_length': 3.806282722513089, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7310299', 'n_tokens_mistral': 674, 'n_tokens_neox': 650, 'n_words': 173}