serve developer-registration login not /firefox/users/login (bug 728465)

This commit is contained in:
Chris Van 2012-02-17 18:28:11 -08:00
Родитель 94ebd0b92f
Коммит e9155de126
10 изменённых файлов: 58 добавлений и 25 удалений

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

@ -4,7 +4,6 @@ Borrowed from: http://code.google.com/p/django-localeurl
Note: didn't make sense to use localeurl since we need to capture app as well
"""
import contextlib
import time
import urllib
from django.conf import settings
@ -38,9 +37,12 @@ class LocaleAndAppURLMiddleware(object):
def process_request(self, request):
# Find locale, app
prefixer = urlresolvers.Prefixer(request)
# Force en-US until we localize Marketplace.
if settings.APP_PREVIEW:
redirect_type = HttpResponsePermanentRedirect
if settings.MARKETPLACE:
# Force en-US until we localize Marketplace.
prefixer.locale = 'en-US'
# Use 302 redirects if these URLs are gonna change.
redirect_type = redirect
urlresolvers.set_url_prefix(prefixer)
full_path = prefixer.fix(prefixer.shortened_path)
@ -51,7 +53,7 @@ class LocaleAndAppURLMiddleware(object):
new_path = prefixer.fix(prefixer.shortened_path)
query = dict((smart_str(k), request.GET[k]) for k in request.GET)
query.pop('lang')
return HttpResponsePermanentRedirect(urlparams(new_path, **query))
return redirect_type(urlparams(new_path, **query))
if full_path != request.path:
query_string = request.META.get('QUERY_STRING', '')
@ -60,9 +62,9 @@ class LocaleAndAppURLMiddleware(object):
if query_string:
full_path = "%s?%s" % (full_path, query_string)
response = HttpResponsePermanentRedirect(full_path)
# Cache the redirect for a year.
if not settings.DEBUG:
response = redirect_type(full_path)
# Cache the redirect for a year. But not for Marketplace!
if not (settings.DEBUG or settings.MARKETPLACE):
patch_cache_control(response, max_age=60 * 60 * 24 * 365)
# Vary on Accept-Language or User-Agent if we changed the locale or

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

@ -239,9 +239,9 @@ class TestCase(RedisTest, test_utils.TestCase):
% (k, msg))
self.assertEquals(v.non_field_errors(), [])
def assertLoginRedirects(self, response, to):
def assertLoginRedirects(self, response, to, status_code=302):
self.assertRedirects(response,
'%s?to=%s' % (reverse('users.login'), to), 302)
'%s?to=%s' % (reverse('users.login'), to), status_code)
class AMOPaths(object):

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

@ -42,8 +42,8 @@ class MiddlewareTest(test.TestCase):
eq_(response.status_code, 301)
eq_(response['Location'], location)
@patch.object(settings, 'APP_PREVIEW', True) # To disable L10n detection.
@patch.object(settings, 'MARKETPLACE', True) # For /developers/ redirect.
# Patch for /developers/ redirect and l10n detection disabling.
@patch.object(settings, 'MARKETPLACE', True)
def test_marketplace_redirection(self):
# We're forcing en-US since Marketplace isn't localized yet.
redirections = {
@ -53,10 +53,11 @@ class MiddlewareTest(test.TestCase):
'/fr/developers': '/en-US/developers',
}
for path, location in redirections.items():
response = self.middleware.process_request(self.rf.get(path))
eq_(response.status_code, 301, 'Expected a 301 for %s' % path)
eq_(response['Location'], location,
'%s -> %s went to %s' % (path, location, response['Location']))
r = self.middleware.process_request(self.rf.get(path))
eq_(r.status_code, 302,
'Expected a 302 for %s. (Got a %s)' % (path, r.status_code))
eq_(r['Location'], location,
'%s -> %s went to %s' % (path, location, r['Location']))
def process(self, *args, **kwargs):
request = self.rf.get(*args, **kwargs)

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

@ -87,9 +87,17 @@ class AppHubTest(HubTest):
class TestHome(HubTest):
def test_login_redirects(self):
self.client.logout()
# Ensure these URLs get temporarily redirected to the login page.
sources = [self.url, reverse('home')]
for src in sources:
r = self.client.get(self.url)
self.assertLoginRedirects(r, '/en-US/developers/', 302)
def test_home(self):
for url in [self.url, reverse('home')]:
r = self.client.get(self.url, follow=True)
r = self.client.get(url, follow=True)
eq_(r.status_code, 200)
self.assertTemplateUsed(r, 'developers/index.html')

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

@ -524,7 +524,7 @@ class TestEditBasic(TestEdit):
Addon.objects.get(id=3615).update(default_locale='fr')
for url in self.get_l10n_urls():
url = '/id' + url[6:]
r = self.client.get(url)
r = self.client.get(url, follow=True)
eq_(pq(r.content)('#l10n-menu').attr('data-default'), 'fr',
'l10n menu not visible for %s' % url)

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

@ -1,4 +1,7 @@
"""Tests related to the ``mkt.developers.addons.owner`` view."""
from django.conf import settings
import mock
from nose.tools import eq_
from pyquery import PyQuery as pq
import waffle
@ -57,11 +60,17 @@ class TestEditPolicy(TestOwnership):
eq_(self.get_addon().eula, None)
def test_edit_eula_locale(self):
self.addon.eula = {'de': 'some eula', 'en-US': ''}
self.addon.save()
res = self.client.get(self.url.replace('en-US', 'it'), follow=True)
eq_(pq(res.content)('#id_has_eula').attr('checked'), 'checked')
@mock.patch.object(settings, 'MARKETPLACE', False)
def test_edit_eula_locale_with_l10n_detection(self):
self.addon.eula = {'de': 'some eula', 'en-US': ''}
self.addon.save()
res = self.client.get(self.url.replace('en-US', 'it'))
doc = pq(res.content)
eq_(doc('#id_has_eula').attr('checked'), 'checked')
eq_(pq(res.content)('#id_has_eula').attr('checked'), 'checked')
class TestEditLicense(TestOwnership):

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

@ -218,9 +218,6 @@ packager_patterns = patterns('',
urlpatterns = decorate(write, patterns('',
url('^$', views.index, name='mkt.developers.index'),
# Developer Registration Login.
url('^login/$', views.login, name='mkt.developers.login'),
# Redirect people who have /addons/ instead of /addon/.
('^addons/\d+/.*',
lambda r: redirect(r.path.replace('addons', 'addon', 1))),

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

@ -102,6 +102,12 @@ def login(request, template=None):
return _login(request, template='developers/login.html')
def home(request):
# This is a temporary redirect.
return redirect('mkt.developers.index')
@login_required
def index(request):
return jingo.render(request, 'developers/index.html')

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

@ -8,8 +8,8 @@ APP_PREVIEW = True
# So temporary. Allow us to link to new devhub URLs from `Addon.get_dev_url()`.
MARKETPLACE = True
# Pretty temporary. Set the correct home for Marketplace. Redirects are lame.
HOME = 'mkt.developers.views.index'
# Pretty temporary. Set the correct home for Marketplace. Redirects are sick!
HOME = 'mkt.developers.views.home'
ROOT_URLCONF = 'mkt.urls'
INSTALLED_APPS += (
@ -23,6 +23,7 @@ SUPPORTED_NONAPPS += (
'dev',
'hub',
'submit',
'login',
)
MIDDLEWARE_CLASSES += (

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

@ -2,6 +2,7 @@ from django.conf import settings
from django.conf.urls.defaults import patterns, url, include
from lib.urls_base import handler404, handler500, urlpatterns as base_urls
from mkt.developers.views import login
# These URLs take precedence over existing ones.
@ -13,11 +14,19 @@ urlpatterns = patterns('',
('^hub/', include('mkt.hub.urls')),
)
# Add our old patterns.
urlpatterns += base_urls
# Marketplace UI Experiments
# Override old patterns.
urlpatterns += patterns('',
# Developer Registration Login.
url('^login$', login, name='users.login'),
)
# Marketplace UI Experiments.
if getattr(settings, 'POTCH_MARKETPLACE_EXPERIMENTS', False):
urlpatterns += patterns('',
('^marketplace-experiments/', include('mkt.experiments.urls'))