Skip to content

Commit

Permalink
Bug 874982: All buttons should offer stub for enabled builds.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmac committed Jun 27, 2013
1 parent 58b06ce commit 617da0c
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 35 deletions.
2 changes: 1 addition & 1 deletion bedrock/firefox/templates/firefox/channel.html
Expand Up @@ -30,7 +30,7 @@
<h2 class="channel-title channel-title-beta"><img src="{{ media('/img/firefox/channel/title-beta.png') }}" alt="Firefox Beta" /></h2>
<h3>The latest features in a more stable environment</h3>
<div class="download-box" id="beta-desktop">
{{ download_firefox('beta', icon=False, small=True, force_stub_installer=True) }}
{{ download_firefox('beta', icon=False, small=True) }}
</div>
<div class="download-box mobile" id="beta-mobile">
{{ download_firefox('beta', icon=False, mobile=True, small=True) }}
Expand Down
25 changes: 11 additions & 14 deletions bedrock/mozorg/helpers/download_buttons.py
Expand Up @@ -102,7 +102,7 @@ def make_aurora_link(product, version, platform, locale,

def make_download_link(product, build, version, platform, locale,
force_direct=False, force_full_installer=False,
force_funnelcake=False, force_stub_installer=False):
force_funnelcake=False):
# Aurora has a special download link format
if build == 'aurora':
return make_aurora_link(product, version, platform, locale,
Expand All @@ -115,15 +115,16 @@ def make_download_link(product, build, version, platform, locale,
'os_osx': 'osx'
}[platform]

# en-US windows exceptions
# stub installer exceptions
# TODO: NUKE FROM ORBIT!
if force_funnelcake or force_full_installer or force_stub_installer:
if locale.lower() == 'en-us' and platform == 'win':
stub_langs = settings.STUB_INSTALLER_LOCALES.get(platform, [])
if stub_langs and (stub_langs == settings.STUB_INSTALLER_ALL or
locale.lower() in stub_langs):
suffix = 'stub'
if force_funnelcake or force_full_installer:
suffix = 'latest'
if force_stub_installer:
suffix = 'stub'

version = ('beta-' if build == 'beta' else '') + suffix
version = ('beta-' if build == 'beta' else '') + suffix

# Figure out the base url. certain locales have a transitional
# thankyou-style page (most do)
Expand All @@ -143,7 +144,7 @@ def make_download_link(product, build, version, platform, locale,
def download_firefox(ctx, build='release', small=False, icon=True,
mobile=None, dom_id=None, locale=None,
force_direct=False, force_full_installer=False,
force_funnelcake=False, force_stub_installer=False):
force_funnelcake=False):
""" Output a "download firefox" button.
:param ctx: context from calling template.
Expand All @@ -160,8 +161,6 @@ def download_firefox(ctx, build='release', small=False, icon=True,
the stub installer (for aurora).
:param force_funnelcake: Force the download version for en-US Windows to be
'latest', which bouncer will translate to the funnelcake build.
:param force_stub_installer: Force the download link for en-US windows to
be for the stub installer (for release and beta).
:return: The button html.
"""
alt_build = '' if build == 'release' else build
Expand Down Expand Up @@ -201,8 +200,7 @@ def latest(locale):
# And generate all the info
download_link = make_download_link(
'firefox', build, version, plat_os,
_locale, force_direct, force_full_installer, force_funnelcake,
force_stub_installer)
_locale, force_direct, force_full_installer, force_funnelcake)

# If download_link_direct is False the data-direct-link attr
# will not be output, and the JS won't attempt the IE popup.
Expand All @@ -212,8 +210,7 @@ def latest(locale):
else:
download_link_direct = make_download_link(
'firefox', build, version, plat_os,
_locale, True, force_full_installer, force_funnelcake,
force_stub_installer)
_locale, True, force_full_installer, force_funnelcake)
if download_link_direct == download_link:
download_link_direct = False

Expand Down
84 changes: 64 additions & 20 deletions bedrock/mozorg/tests/test_helper_download_buttons.py
Expand Up @@ -3,12 +3,12 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

from django.conf import settings
from django.test.utils import override_settings
from django.utils import unittest
from test_utils import RequestFactory

import jingo
from mock import patch
from nose.tools import assert_not_equal, eq_, ok_
from nose.tools import eq_, ok_
from product_details import product_details
from pyquery import PyQuery as pq

Expand All @@ -27,10 +27,18 @@ def latest_version(self):

def check_desktop_links(self, links):
"""Desktop links should have the correct firefox version"""
key = 'firefox-%s' % self.latest_version()
# valid product strings
keys = [
'firefox-%s' % self.latest_version(),
'firefox-stub',
'firefox-latest',
'firefox-beta-stub',
'firefox-beta-latest',
]

for link in links:
assert_not_equal(pq(link).attr('href').find(key), -1)
url = pq(link).attr('href')
ok_(any(key in url for key in keys))

def check_dumb_button(self, doc):
# Make sure 4 links are present
Expand Down Expand Up @@ -101,7 +109,7 @@ def test_button_has_data_attr_if_not_direct(self):
# The fourth link is mobile and should not have the attr
ok_(pq(links[3]).attr('data-direct-link') is None)

@patch.object(settings, 'AURORA_STUB_INSTALLER', True)
@override_settings(AURORA_STUB_INSTALLER=True)
def test_stub_aurora_installer_enabled_en_us(self):
"""Check that only the windows link goes to stub with en-US"""
rf = RequestFactory()
Expand All @@ -115,7 +123,7 @@ def test_stub_aurora_installer_enabled_en_us(self):
for link in links[1:]:
ok_('stub' not in pq(link).attr('href'))

@patch.object(settings, 'AURORA_STUB_INSTALLER', True)
@override_settings(AURORA_STUB_INSTALLER=True)
def test_stub_aurora_installer_enabled_locales(self):
"""Check that the stub is not served to locales"""
rf = RequestFactory()
Expand All @@ -128,7 +136,7 @@ def test_stub_aurora_installer_enabled_locales(self):
for link in links:
ok_('stub' not in pq(link).attr('href'))

@patch.object(settings, 'AURORA_STUB_INSTALLER', False)
@override_settings(AURORA_STUB_INSTALLER=False)
def test_stub_aurora_installer_disabled_en_us(self):
rf = RequestFactory()
get_request = rf.get('/fake')
Expand All @@ -140,7 +148,7 @@ def test_stub_aurora_installer_disabled_en_us(self):
for link in links:
ok_('stub' not in pq(link).attr('href'))

@patch.object(settings, 'AURORA_STUB_INSTALLER', False)
@override_settings(AURORA_STUB_INSTALLER=False)
def test_stub_aurora_installer_disabled_locale(self):
rf = RequestFactory()
get_request = rf.get('/fake')
Expand All @@ -152,7 +160,7 @@ def test_stub_aurora_installer_disabled_locale(self):
for link in links:
ok_('stub' not in pq(link).attr('href'))

@patch.object(settings, 'AURORA_STUB_INSTALLER', True)
@override_settings(AURORA_STUB_INSTALLER=True)
def test_stub_aurora_installer_override_en_us(self):
rf = RequestFactory()
get_request = rf.get('/fake')
Expand All @@ -165,7 +173,7 @@ def test_stub_aurora_installer_override_en_us(self):
for link in links:
ok_('stub' not in pq(link).attr('href'))

@patch.object(settings, 'AURORA_STUB_INSTALLER', True)
@override_settings(AURORA_STUB_INSTALLER=True)
def test_stub_aurora_installer_override_locale(self):
rf = RequestFactory()
get_request = rf.get('/fake')
Expand All @@ -189,6 +197,7 @@ def test_download_transition_link_contains_locale(self):
'os=osx&lang={locale}').format(locale=locale)
eq_(url, good_url)

@override_settings(STUB_INSTALLER_LOCALES={'win': ['en-us']})
def test_force_funnelcake(self):
"""
force_funnelcake should force the product to be 'firefox-latest'
Expand All @@ -203,9 +212,10 @@ def test_force_funnelcake(self):
'en-US', force_funnelcake=True)
ok_('product=firefox-beta-latest&' in url)

@override_settings(STUB_INSTALLER_LOCALES={'win': ['en-us']})
def test_force_funnelcake_en_us_win_only(self):
"""
Ensure that force_funnelcake doesn't affect non en-US Windows urls
Ensure that force_funnelcake doesn't affect non configured locale urls
"""
url = make_download_link('firefox', 'release', 19.0, 'os_osx',
'en-US', force_funnelcake=True)
Expand All @@ -215,10 +225,11 @@ def test_force_funnelcake_en_us_win_only(self):
'fr', force_funnelcake=True)
ok_('product=firefox-beta-latest&' not in url)

@override_settings(STUB_INSTALLER_LOCALES={'win': ['en-us']})
def test_force_full_installer(self):
"""
force_full_installer should force the product to be 'firefox-latest'
for en-US windows release downloads, and 'firefox-beta-latest' for
for configured locale release downloads, and 'firefox-beta-latest' for
beta.
"""
url = make_download_link('firefox', 'release', 19.0, 'os_windows',
Expand All @@ -229,9 +240,10 @@ def test_force_full_installer(self):
'en-US', force_full_installer=True)
ok_('product=firefox-beta-latest&' in url)

@override_settings(STUB_INSTALLER_LOCALES={'win': ['en-us']})
def test_force_full_installer_en_us_win_only(self):
"""
Ensure that force_full_installer doesn't affect non en-US Windows urls
Ensure that force_full_installer doesn't affect non configured locales
"""
url = make_download_link('firefox', 'release', 19.0, 'os_osx',
'en-US', force_full_installer=True)
Expand All @@ -241,23 +253,55 @@ def test_force_full_installer_en_us_win_only(self):
'fr', force_full_installer=True)
ok_('product=firefox-beta-latest&' not in url)

def test_force_stub_installer(self):
@override_settings(STUB_INSTALLER_LOCALES={
'win': ['en-us'], 'osx': ['fr', 'de'], 'linux': []})
def test_stub_installer(self):
"""Button should give stub for builds in the setting always."""
url = make_download_link('firefox', 'release', 19.0, 'os_windows',
'en-US')
ok_('product=firefox-stub&' in url)

url = make_download_link('firefox', 'release', 19.0, 'os_osx',
'fr')
ok_('product=firefox-stub&' in url)

url = make_download_link('firefox', 'release', 19.0, 'os_osx',
'de')
ok_('product=firefox-stub&' in url)

url = make_download_link('firefox', 'beta', '20.0b4', 'os_windows',
'en-US')
ok_('product=firefox-beta-stub&' in url)

@override_settings(STUB_INSTALLER_LOCALES={
'win': settings.STUB_INSTALLER_ALL})
def test_stub_installer_all(self):
"""Button should give stub for all langs when ALL is set."""
url = make_download_link('firefox', 'release', 19.0, 'os_windows',
'en-US')
ok_('product=firefox-stub&' in url)

url = make_download_link('firefox', 'release', 19.0, 'os_windows',
'fr')
ok_('product=firefox-stub&' in url)

url = make_download_link('firefox', 'release', 19.0, 'os_windows',
'en-US', force_stub_installer=True)
'de')
ok_('product=firefox-stub&' in url)

url = make_download_link('firefox', 'beta', '20.0b4', 'os_windows',
'en-US', force_stub_installer=True)
'es-ES')
ok_('product=firefox-beta-stub&' in url)

def test_force_stub_installer_en_us_win_only(self):
@override_settings(STUB_INSTALLER_LOCALES={'win': ['en-us']})
def test_stub_installer_en_us_win_only(self):
"""
Ensure that force_funnelcake doesn't affect non en-US Windows urls
Ensure that builds not in the setting don't get stub.
"""
url = make_download_link('firefox', 'release', 19.0, 'os_osx',
'en-US', force_stub_installer=True)
'en-US')
ok_('product=firefox-stub&' not in url)

url = make_download_link('firefox', 'beta', '20.0b4', 'os_windows',
'fr', force_stub_installer=True)
'fr')
ok_('product=firefox-beta-stub&' not in url)
10 changes: 10 additions & 0 deletions bedrock/settings/base.py
Expand Up @@ -697,6 +697,16 @@ def lazy_email_backend():

AURORA_STUB_INSTALLER = False

# special value that means all locales are enabled.
STUB_INSTALLER_ALL = '__ALL__'
# values should be a list of lower case locales per platform for which a
# stub installer is available. Hopefully this can all be moved to bouncer.
STUB_INSTALLER_LOCALES = {
'win': STUB_INSTALLER_ALL,
'osx': [],
'linux': [],
}

# Google Analytics
GA_ACCOUNT_CODE = ''

Expand Down

0 comments on commit 617da0c

Please sign in to comment.