remove UA testing from theme updates; add setting to disable serving migrated lwts (#9977)

This commit is contained in:
Andrew Williamson 2018-11-13 13:12:41 +00:00 коммит произвёл GitHub
Родитель c55c4ec00a
Коммит 8daf0e5383
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 24 добавлений и 58 удалений

Просмотреть файл

@ -4,8 +4,6 @@ import re
from time import time
from wsgiref.handlers import format_date_time
from six import text_type
from olympia.constants import base
from services.utils import (
@ -15,8 +13,6 @@ from services.utils import (
# This has to be imported after the settings (utils).
from django_statsd.clients import statsd
import olympia.core.logger
# Configure the log.
log_configure()
@ -229,13 +225,6 @@ class LWThemeUpdate(ThemeUpdate):
url_re = re.compile(r'(?P<locale>.+)?/themes/update-check/(?P<id>\d+)$')
def is_android_ua(user_agent):
return 'android' in text_type(user_agent).lower()
update_log = olympia.core.logger.getLogger('z.addons')
def application(environ, start_response):
"""
Developing locally?
@ -259,16 +248,14 @@ def application(environ, start_response):
query_string = environ.get('QUERY_STRING')
update = MigratedUpdate(locale, id_, query_string)
is_migrated = update.is_migrated
user_agent_string = environ.get('HTTP_USER_AGENT')
update_log.info(
"HTTP_USER_AGENT %s; is_migrated: %s, is_android_ua: %s",
user_agent_string, is_migrated,
is_android_ua(user_agent_string))
if not is_migrated:
if is_migrated:
output = (
update.get_json() if settings.MIGRATED_LWT_UPDATES_ENABLED
else None)
else:
update = LWThemeUpdate(locale, id_, query_string)
elif is_android_ua(user_agent_string):
update = None
output = update.get_json() if update else None
output = update.get_json()
if not output:
start_response('404 Not Found', [])
return ['']

Просмотреть файл

@ -6,6 +6,7 @@ from StringIO import StringIO
from django.conf import settings
from django.db import connection
from django.test.utils import override_settings
import mock
@ -18,32 +19,25 @@ from olympia.amo.tests import addon_factory, TestCase
from olympia.versions.models import Version
DESKTOP_UA = (
'Mozilla/5.0 (Windows NT x.y; Win64; x64; rv:10.0) Gecko/20100101 '
'Firefox/10.0')
ANDROID_UA = (
'Mozilla/5.0 (Android 4.4; Mobile; rv:41.0) Gecko/41.0 Firefox/41.0')
class TestWSGIApplication(TestCase):
def setUp(self):
super(TestWSGIApplication, self).setUp()
self.environ = {'wsgi.input': StringIO()}
self.start_response = mock.Mock()
self.urls = {
'/themes/update-check/5': ['en-US', 5, None],
'/en-US/themes/update-check/5': ['en-US', 5, None],
'/fr/themes/update-check/5': ['fr', 5, None]
}
@mock.patch('services.theme_update.MigratedUpdate')
@mock.patch('services.theme_update.LWThemeUpdate')
def test_wsgi_application_200(self, LWThemeUpdate_mock,
MigratedUpdate_mock):
urls = {
'/themes/update-check/5': ['en-US', 5, None],
'/en-US/themes/update-check/5': ['en-US', 5, None],
'/fr/themes/update-check/5': ['fr', 5, None]
}
MigratedUpdate_mock.return_value.is_migrated = False
# From AMO we consume the ID as the `addon_id`.
for path_info, call_args in urls.iteritems():
for path_info, call_args in self.urls.iteritems():
environ = dict(self.environ, PATH_INFO=path_info)
theme_update.application(environ, self.start_response)
LWThemeUpdate_mock.assert_called_with(*call_args)
@ -52,7 +46,7 @@ class TestWSGIApplication(TestCase):
# From getpersonas.com we append `?src=gp` so we know to consume
# the ID as the `persona_id`.
self.environ['QUERY_STRING'] = 'src=gp'
for path_info, call_args in urls.iteritems():
for path_info, call_args in self.urls.iteritems():
environ = dict(self.environ, PATH_INFO=path_info)
theme_update.application(environ, self.start_response)
call_args[2] = 'src=gp'
@ -62,16 +56,12 @@ class TestWSGIApplication(TestCase):
@mock.patch('services.theme_update.MigratedUpdate')
@mock.patch('services.theme_update.LWThemeUpdate')
@override_settings(MIGRATED_LWT_UPDATES_ENABLED=True)
def test_wsgi_application_200_migrated(self, LWThemeUpdate_mock,
MigratedUpdate_mock):
urls = {
'/themes/update-check/5': ['en-US', 5, None],
'/en-US/themes/update-check/5': ['en-US', 5, None],
'/fr/themes/update-check/5': ['fr', 5, None]
}
MigratedUpdate_mock.return_value.is_migrated = True
# From AMO we consume the ID as the `addon_id`.
for path_info, call_args in urls.iteritems():
for path_info, call_args in self.urls.iteritems():
environ = dict(self.environ, PATH_INFO=path_info)
theme_update.application(environ, self.start_response)
assert not LWThemeUpdate_mock.called
@ -81,7 +71,7 @@ class TestWSGIApplication(TestCase):
# From getpersonas.com we append `?src=gp` so we know to consume
# the ID as the `persona_id`.
self.environ['QUERY_STRING'] = 'src=gp'
for path_info, call_args in urls.iteritems():
for path_info, call_args in self.urls.iteritems():
environ = dict(self.environ, PATH_INFO=path_info)
theme_update.application(environ, self.start_response)
call_args[2] = 'src=gp'
@ -109,29 +99,16 @@ class TestWSGIApplication(TestCase):
@mock.patch('services.theme_update.MigratedUpdate')
@mock.patch('services.theme_update.LWThemeUpdate')
def test_404_for_migrated_but_android(
@override_settings(MIGRATED_LWT_UPDATES_ENABLED=False)
def test_404_for_migrated_but_updates_disabled(
self, LWThemeUpdate_mock, MigratedUpdate_mock):
urls = {
'/themes/update-check/5': ['en-US', 5, None],
'/en-US/themes/update-check/5': ['en-US', 5, None],
'/fr/themes/update-check/5': ['fr', 5, None]
}
MigratedUpdate_mock.return_value.is_migrated = True
for path_info, call_args in urls.iteritems():
environ = dict(self.environ, PATH_INFO=path_info,
HTTP_USER_AGENT=ANDROID_UA)
for path_info, call_args in self.urls.iteritems():
environ = dict(self.environ, PATH_INFO=path_info)
theme_update.application(environ, self.start_response)
assert not LWThemeUpdate_mock.called
MigratedUpdate_mock.assert_called_with(*call_args)
self.start_response.assert_called_with('404 Not Found', [])
# Then double check a desktop UA does still work
for path_info, call_args in urls.iteritems():
environ = dict(self.environ, PATH_INFO=path_info,
HTTP_USER_AGENT=DESKTOP_UA)
theme_update.application(environ, self.start_response)
assert not LWThemeUpdate_mock.called
MigratedUpdate_mock.assert_called_with(*call_args)
self.start_response.assert_called_with('200 OK', mock.ANY)
class TestThemeUpdate(TestCase):

Просмотреть файл

@ -1935,6 +1935,8 @@ GITHUB_API_TOKEN = env('GITHUB_API_TOKEN', default='')
MIGRATED_LWT_DEFAULT_OWNER_EMAIL = 'addons-team+landfill-account@mozilla.com'
MIGRATED_LWT_UPDATES_ENABLED = False
BASKET_URL = env('BASKET_URL', default='https://basket.allizom.org')
BASKET_API_KEY = env('BASKET_API_KEY', default=None)
# Default is 10, the API usually answers in 0.5 - 1.5 seconds.