Skip to content
This repository has been archived by the owner on Aug 26, 2022. It is now read-only.

Commit

Permalink
bug 1462475: fix tests/headless/test_cdn.py
Browse files Browse the repository at this point in the history
These tests were originally modified for the work
of removing zones, but those modifications were
made without realizing that some of the tests
related to the caching of the redirects for former
zone vanity URL's had to be asserted one way when
behind a CDN and another when not.
  • Loading branch information
escattone committed Jul 24, 2018
1 parent 82853c5 commit ee03db7
Showing 1 changed file with 51 additions and 32 deletions.
83 changes: 51 additions & 32 deletions tests/headless/test_cdn.py
Expand Up @@ -251,15 +251,7 @@ def test_cached_301(base_url, is_behind_cdn, is_local_url, slug):
'/en-US/Firefox',
'/en-US/Firefox$json',
'/en-US/Firefox$history',
'/en-US/Firefox$children',
'/en-US/Firefox$edit',
'/en-US/Firefox$move',
'/en-US/Firefox$files',
'/en-US/Firefox$purge',
'/en-US/Firefox$delete',
'/en-US/Firefox$translate',
'/en-US/Firefox$quick-review',
'/en-US/Firefox$revert/1284393'])
'/en-US/Firefox$children'])
def test_cached_302(base_url, is_behind_cdn, slug):
"""Ensure that these requests that should return 302 are cached."""
assert_cached(base_url + slug, 302, is_behind_cdn)
Expand All @@ -272,17 +264,7 @@ def test_cached_302(base_url, is_behind_cdn, slug):
'slug', ['/{}',
'/{}$json',
'/{}$history',
'/{}$children',
'/{}$edit',
'/{}$move',
'/{}$files',
'/{}$purge',
'/{}$delete',
'/{}$translate',
'/{}$quick-review',
'/{}$subscribe',
'/{}$subscribe_to_tree',
'/{}$revert/1284393'])
'/{}$children'])
def test_no_locale_cached_302(base_url, is_behind_cdn, slug, zone):
"""
Ensure that these zone requests without a locale that should return
Expand All @@ -292,18 +274,6 @@ def test_no_locale_cached_302(base_url, is_behind_cdn, slug, zone):
assert response.headers['location'].startswith('/docs/')


@pytest.mark.nondestructive
@pytest.mark.parametrize(
'slug', ['/en-US/Firefox$subscribe',
'/en-US/Firefox$subscribe_to_tree'])
def test_cached_302_post(base_url, is_behind_cdn, slug):
"""
Ensure that POST's to these endpoints that should return 403's are not
cached.
"""
assert_cached(base_url + slug, 302, is_behind_cdn, method='post')


@pytest.mark.nondestructive
def test_revisions_dashboard(base_url, is_behind_cdn, kuma_status):
"""
Expand Down Expand Up @@ -501,3 +471,52 @@ def test_locale_selection_not_cached(base_url, is_behind_cdn, is_local_url,
assert response.status_code == 302
expected = '/' + expected + '/'
assert response.headers['location'].startswith(expected)


@pytest.mark.nondestructive
@pytest.mark.parametrize('locale', [None, '/de'])
@pytest.mark.parametrize(
'zone', ['Add-ons', 'Apps', 'Firefox', 'Learn', 'Marketplace'])
@pytest.mark.parametrize(
'slug', ['{}/{}$edit',
'{}/{}$move',
'{}/{}$files',
'{}/{}$purge',
'{}/{}$delete',
'{}/{}$translate',
'{}/{}$quick-review',
'{}/{}$revert/1284393'])
def test_former_vanity_302(base_url, is_behind_cdn, slug, zone, locale):
"""
Ensure that these former zone vanity URL's that should return 302 are
cached (based on Cache-Control header) when not behind a CDN, and not
cached (based on a special CDN header) when behind a CDN. They are not
cached when behind a CDN simply because they fall into into a CDN behavior
that prevents caching, not because they shouldn't be cached.
"""
locale = locale or ''
url = base_url + slug.format(locale, zone)
assert_caching = assert_not_cached if is_behind_cdn else assert_cached
response = assert_caching(url, 302, is_behind_cdn)
assert response.headers['location'].startswith('{}/docs/'.format(locale))
assert response.headers['location'].endswith(slug.format('', zone))


@pytest.mark.nondestructive
@pytest.mark.parametrize('locale', [None, '/de'])
@pytest.mark.parametrize(
'zone', ['Add-ons', 'Apps', 'Firefox', 'Learn', 'Marketplace'])
@pytest.mark.parametrize(
'slug', ['{}/{}$subscribe',
'{}/{}$subscribe_to_tree'])
def test_former_vanity_302_post(base_url, is_behind_cdn, slug, zone, locale):
"""
Ensure that POST's to these former zone vanity URL's that should return
302 are cached (based on Cache-Control header) when not behind a CDN, and
not cached (based on a special CDN header) when behind a CDN. They are not
cached when behind a CDN simply because they fall into a CDN behavior that
prevents caching, not because they shouldn't be cached.
"""
url = base_url + slug.format(locale or '', zone)
assert_caching = assert_not_cached if is_behind_cdn else assert_cached
assert_caching(url, 302, is_behind_cdn, method='post')

0 comments on commit ee03db7

Please sign in to comment.