Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 1 addition & 44 deletions src/olympia/amo/tests/test_url_prefix.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,49 +100,6 @@ def test_no_redirect_with_script(self):
response = self.process('/services', SCRIPT_NAME='/oremj')
assert response is None

def test_get_app(self):
def check(url, expected, ua):
response = self.process(url, HTTP_USER_AGENT=ua)
assert response['Location'] == expected

check('/en-US/', '/en-US/firefox/', 'Firefox')

# Android can found by its user agent.
check('/en-US/', '/en-US/android/', 'Fennec/12.0.1')
check('/en-US/', '/en-US/android/', 'Fennec/12')
check('/en-US/', '/en-US/android/', 'Fennec/11.0')

# And the user agent changed again.
check(
'/en-US/',
'/en-US/android/',
'Mozilla/5.0 (Android; Mobile; rv:17.0) Gecko/17.0 Firefox/17.0',
)

# And the user agent yet changed again.
check(
'/en-US/',
'/en-US/android/',
'Mozilla/5.0 (Mobile; rv:18.0) Gecko/18.0 Firefox/18.0',
)

# And the tablet user agent yet changed again!
check(
'/en-US/',
'/en-US/android/',
'Mozilla/5.0 (Android; Tablet; rv:18.0) Gecko/18.0 Firefox/18.0',
)

# We can also set the application using the `app` query parameter.
check('/en-US/?app=android', '/en-US/android/', '')
check('/en-US/?app=firefox', '/en-US/firefox/', '')
check('/en-US/android?app=firefox', '/en-US/android/', '')
check('/en-US/android/?app=invalid', '/en-US/android/', '')
check('/en-US/android/?app=', '/en-US/android/', '')
check('/?app=android&lang=fr', '/fr/android/', '')
check('/?app=android&lang=', '/en-US/android/', '')
check('/?app=invalid&lang=', '/en-US/firefox/', '')

def test_get_lang(self):
def check(url, expected):
response = self.process(url)
Expand Down Expand Up @@ -227,7 +184,7 @@ def test_reverse(self):
client.get('/')
assert reverse('home') == '/en-US/firefox/'
client.get('/?app=android')
assert reverse('home') == '/en-US/android/'
assert reverse('home') == '/en-US/firefox/'
client.get('/?app=firefox')
assert reverse('home') == '/en-US/firefox/'
client.get('/?app=invalid')
Expand Down
20 changes: 1 addition & 19 deletions src/olympia/amo/urlresolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,6 @@ def split_path(path_):
else:
return '', '', path

def get_app(self):
"""
Return a valid application string based on the `app` query parameter or
the User Agent. Falls back to settings.DEFAULT_APP.
"""
if 'app' in self.request.GET:
app = self.request.GET['app'].lower()
if app in amo.APPS:
return app

ua = self.request.META.get('HTTP_USER_AGENT')
if ua:
for app in amo.APP_DETECT:
if app.matches_user_agent(ua):
return app.short

return settings.DEFAULT_APP

def get_language(self):
"""
Return a locale code that we support on the site using `lang` from GET,
Expand All @@ -115,7 +97,7 @@ def fix(self, path):
url_parts.append(self.locale or self.get_language())

if path.partition('/')[0] not in settings.SUPPORTED_NONAPPS:
url_parts.append(self.app or self.get_app())
url_parts.append(self.app or settings.DEFAULT_APP)

url_parts.append(path)
return '/'.join(url_parts)
Expand Down
22 changes: 1 addition & 21 deletions src/olympia/constants/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

from django.utils.translation import gettext_lazy as _

from olympia.versions.compare import version_int as vint

from .base import (
ADDON_DICT,
ADDON_EXTENSION,
Expand All @@ -15,9 +13,7 @@


class App:
@classmethod
def matches_user_agent(cls, user_agent):
return cls.user_agent_string in user_agent
pass


# Applications
Expand All @@ -34,13 +30,6 @@ class FIREFOX(App):
exclude_versions = (3.1, 3.7, 4.2)
user_agent_string = 'Firefox'

@classmethod
def matches_user_agent(cls, user_agent):
matches = cls.user_agent_string in user_agent
if 'Android' in user_agent or 'Mobile' in user_agent or 'Tablet' in user_agent:
matches = False
return matches


class THUNDERBIRD(App):
id = 18
Expand Down Expand Up @@ -122,14 +111,6 @@ class ANDROID(App):
]
latest_version = None

@classmethod
def matches_user_agent(cls, user_agent):
for user_agent_re in cls.user_agent_re:
match = user_agent_re.search(user_agent)
if match:
v = match.groups()[0]
return vint(cls.min_display_version) <= vint(v)


class MOZILLA(App):
"""Mozilla exists for completeness and historical purposes.
Expand All @@ -148,7 +129,6 @@ class MOZILLA(App):


# UAs will attempt to match in this order.
APP_DETECT = (ANDROID, FIREFOX)
APP_USAGE = (FIREFOX, ANDROID)
APPS = {app.short: app for app in APP_USAGE}
APP_OBSOLETE = (MOZILLA, SUNBIRD, MOBILE, THUNDERBIRD, SEAMONKEY)
Expand Down
Loading