Fixes bug where default webapp locale was overwritten
This commit is contained in:
Родитель
2ba07af997
Коммит
91251cc94a
|
@ -356,7 +356,10 @@ class Addon(amo.models.OnChangeMixin, amo.models.ModelBase):
|
|||
fields = cls._meta.get_all_field_names()
|
||||
addon = Addon(**dict((k, v) for k, v in data.items() if k in fields))
|
||||
addon.status = amo.STATUS_NULL
|
||||
addon.default_locale = to_language(translation.get_language())
|
||||
locale_is_set = (addon.default_locale and
|
||||
addon.default_locale != settings.LANGUAGE_CODE)
|
||||
if not locale_is_set:
|
||||
addon.default_locale = to_language(translation.get_language())
|
||||
if addon.is_webapp():
|
||||
addon.manifest_url = upload.name
|
||||
addon.save()
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from contextlib import nested
|
||||
import itertools
|
||||
import json
|
||||
import os
|
||||
from datetime import datetime, timedelta
|
||||
import tempfile
|
||||
from urlparse import urlparse
|
||||
|
||||
from django import forms
|
||||
|
@ -1328,6 +1331,10 @@ class TestAddonFromUpload(UploadTest):
|
|||
for version in ('3.0', '3.6.*'):
|
||||
AppVersion.objects.create(application_id=1, version=version)
|
||||
|
||||
def webapp(self):
|
||||
return os.path.join(settings.ROOT,
|
||||
'apps/devhub/tests/addons/mozball.webapp')
|
||||
|
||||
def test_blacklisted_guid(self):
|
||||
BlacklistedGuid.objects.create(guid='guid@xpi')
|
||||
with self.assertRaises(forms.ValidationError) as e:
|
||||
|
@ -1348,9 +1355,7 @@ class TestAddonFromUpload(UploadTest):
|
|||
eq_(addon.slug, 'xpi-name')
|
||||
|
||||
def test_manifest_url(self):
|
||||
path = os.path.join(settings.ROOT,
|
||||
'apps/devhub/tests/addons/mozball.webapp')
|
||||
upload = self.get_upload(abspath=path)
|
||||
upload = self.get_upload(abspath=self.webapp())
|
||||
addon = Addon.from_upload(upload, [self.platform])
|
||||
assert addon.is_webapp()
|
||||
eq_(addon.manifest_url, upload.name)
|
||||
|
@ -1409,6 +1414,17 @@ class TestAddonFromUpload(UploadTest):
|
|||
eq_(addon.default_locale, 'es-ES')
|
||||
translation.deactivate()
|
||||
|
||||
def test_webapp_default_locale_override(self):
|
||||
with nested(tempfile.NamedTemporaryFile('w', suffix='.webapp'),
|
||||
open(self.webapp())) as (tmp, mf):
|
||||
mf = json.load(mf)
|
||||
mf['default_locale'] = 'gb'
|
||||
tmp.write(json.dumps(mf))
|
||||
tmp.flush()
|
||||
upload = self.get_upload(abspath=tmp.name)
|
||||
addon = Addon.from_upload(upload, [self.platform])
|
||||
eq_(addon.default_locale, 'gb')
|
||||
|
||||
|
||||
REDIRECT_URL = 'http://outgoing.mozilla.org/v1/'
|
||||
|
||||
|
|
|
@ -627,18 +627,18 @@ class TestWebApps(amo.tests.TestCase):
|
|||
wp = WebAppParser().parse(self.webapp_path)
|
||||
eq_(wp['guid'], None)
|
||||
eq_(wp['type'], amo.ADDON_WEBAPP)
|
||||
eq_(wp['summary']['en-us'], u'Exciting Open Web development action!')
|
||||
eq_(wp['summary']['en-US'], u'Exciting Open Web development action!')
|
||||
eq_(wp['summary']['es'],
|
||||
u'¡Acción abierta emocionante del desarrollo del Web!')
|
||||
eq_(wp['summary']['it'],
|
||||
u'Azione aperta emozionante di sviluppo di fotoricettore!')
|
||||
eq_(wp['version'], '1.0')
|
||||
eq_(wp['default_locale'], 'en-us')
|
||||
eq_(wp['default_locale'], 'en-US')
|
||||
|
||||
def test_no_locales(self):
|
||||
wp = WebAppParser().parse(self.webapp(dict(name='foo', version='1.0',
|
||||
description='summary')))
|
||||
eq_(wp['summary']['en-us'], u'summary')
|
||||
eq_(wp['summary']['en-US'], u'summary')
|
||||
|
||||
def test_syntax_error(self):
|
||||
with self.assertRaises(forms.ValidationError) as exc:
|
||||
|
|
|
@ -25,6 +25,7 @@ import redisutils
|
|||
from tower import ugettext as _
|
||||
|
||||
import amo
|
||||
from amo.utils import to_language
|
||||
from applications.models import AppVersion
|
||||
from versions.compare import version_int as vint
|
||||
|
||||
|
@ -207,7 +208,7 @@ class WebAppParser(object):
|
|||
# 'en' might be the only one in need of translating.
|
||||
if locale == 'en':
|
||||
locale = 'en-us'
|
||||
return locale
|
||||
return to_language(locale)
|
||||
|
||||
def trans_all_locales(self, locale_dict):
|
||||
trans = {}
|
||||
|
|
Загрузка…
Ссылка в новой задаче