have themes update_check return the same ID in JSON response (bug 866482)
This commit is contained in:
Родитель
b10d91fc5a
Коммит
aefb3f48b0
|
@ -62,10 +62,12 @@ class TestWSGIApplication(amo.tests.TestCase):
|
||||||
|
|
||||||
class TestThemeUpdate(amo.tests.TestCase):
|
class TestThemeUpdate(amo.tests.TestCase):
|
||||||
fixtures = ['addons/persona']
|
fixtures = ['addons/persona']
|
||||||
good = {
|
|
||||||
|
def setUp(self):
|
||||||
|
self.good = {
|
||||||
'username': 'persona_author',
|
'username': 'persona_author',
|
||||||
'description': 'yolo',
|
'description': 'yolo',
|
||||||
'detailURL': settings.SITE_URL + '/en-US/addon/a15663/',
|
'detailURL': '/en-US/addon/a15663/',
|
||||||
'accentcolor': '#8d8d97',
|
'accentcolor': '#8d8d97',
|
||||||
'iconURL': '/15663/preview_small.jpg',
|
'iconURL': '/15663/preview_small.jpg',
|
||||||
'previewURL': '/15663/preview.jpg',
|
'previewURL': '/15663/preview.jpg',
|
||||||
|
@ -75,8 +77,9 @@ class TestThemeUpdate(amo.tests.TestCase):
|
||||||
'dataurl': '',
|
'dataurl': '',
|
||||||
'name': 'My Persona',
|
'name': 'My Persona',
|
||||||
'author': 'persona_author',
|
'author': 'persona_author',
|
||||||
'updateURL': settings.VAMO_URL + '/en-US/themes/update-check/15663',
|
'updateURL': (settings.VAMO_URL +
|
||||||
'version': '1.0',
|
'/en-US/themes/update-check/15663'),
|
||||||
|
'version': '1.1',
|
||||||
'footerURL': '/15663/BCBG_Persona_footer2.png'
|
'footerURL': '/15663/BCBG_Persona_footer2.png'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,8 +88,10 @@ class TestThemeUpdate(amo.tests.TestCase):
|
||||||
got = data[k]
|
got = data[k]
|
||||||
if k.endswith('URL'):
|
if k.endswith('URL'):
|
||||||
if k in ('detailURL', 'updateURL'):
|
if k in ('detailURL', 'updateURL'):
|
||||||
eq_(got.find('?'), -1,
|
assert got.startswith('http'), (
|
||||||
'"%s" should not contain "?"' % k)
|
'Expected absolute URL for "%s": %s' % (k, got))
|
||||||
|
assert got.endswith(v), (
|
||||||
|
'Expected "%s" to end with "%s". Got "%s".' % (k, v, got))
|
||||||
else:
|
else:
|
||||||
assert got.find('?') > -1, (
|
assert got.find('?') > -1, (
|
||||||
'"%s" must contain "?" for modified timestamp' % k)
|
'"%s" must contain "?" for modified timestamp' % k)
|
||||||
|
@ -96,8 +101,6 @@ class TestThemeUpdate(amo.tests.TestCase):
|
||||||
|
|
||||||
assert got.endswith(v), (
|
assert got.endswith(v), (
|
||||||
'Expected "%s" to end with "%s". Got "%s".' % (k, v, got))
|
'Expected "%s" to end with "%s". Got "%s".' % (k, v, got))
|
||||||
else:
|
|
||||||
eq_(got, v, 'Expected "%s" for "%s". Got "%s".' % (v, k, got))
|
|
||||||
|
|
||||||
def get_update(self, *args):
|
def get_update(self, *args):
|
||||||
update = theme_update.ThemeUpdate(*args)
|
update = theme_update.ThemeUpdate(*args)
|
||||||
|
@ -122,5 +125,11 @@ class TestThemeUpdate(amo.tests.TestCase):
|
||||||
json.loads(self.get_update('en-US', 15663).get_json()))
|
json.loads(self.get_update('en-US', 15663).get_json()))
|
||||||
|
|
||||||
# Testing `persona_id` from GP.
|
# Testing `persona_id` from GP.
|
||||||
|
self.good.update({
|
||||||
|
'id': '813',
|
||||||
|
'updateURL': (settings.VAMO_URL +
|
||||||
|
'/en-US/themes/update-check/813?src=gp')
|
||||||
|
})
|
||||||
|
|
||||||
self.check_good(
|
self.check_good(
|
||||||
json.loads(self.get_update('en-US', 813, 'src=gp').get_json()))
|
json.loads(self.get_update('en-US', 813, 'src=gp').get_json()))
|
||||||
|
|
|
@ -24,12 +24,13 @@ class ThemeUpdate(object):
|
||||||
|
|
||||||
def __init__(self, locale, id_, qs=None):
|
def __init__(self, locale, id_, qs=None):
|
||||||
self.conn, self.cursor = None, None
|
self.conn, self.cursor = None, None
|
||||||
|
self.from_gp = qs == 'src=gp'
|
||||||
self.data = {
|
self.data = {
|
||||||
'locale': locale,
|
'locale': locale,
|
||||||
'id': id_,
|
'id': id_,
|
||||||
# If we came from getpersonas.com, then look up by `persona_id`.
|
# If we came from getpersonas.com, then look up by `persona_id`.
|
||||||
# Otherwise, look up `addon_id`.
|
# Otherwise, look up `addon_id`.
|
||||||
'primary_key': 'persona_id' if qs == 'src=gp' else 'addon_id',
|
'primary_key': 'persona_id' if self.from_gp else 'addon_id',
|
||||||
'atype': base.ADDON_PERSONA,
|
'atype': base.ADDON_PERSONA,
|
||||||
'row': {}
|
'row': {}
|
||||||
}
|
}
|
||||||
|
@ -123,8 +124,11 @@ class ThemeUpdate(object):
|
||||||
row = self.data['row']
|
row = self.data['row']
|
||||||
accent = row.get('accentcolor')
|
accent = row.get('accentcolor')
|
||||||
text = row.get('textcolor')
|
text = row.get('textcolor')
|
||||||
return json.dumps({
|
|
||||||
'id': str(row['addon_id']),
|
id_ = str(row[self.data['primary_key']])
|
||||||
|
|
||||||
|
data = {
|
||||||
|
'id': id_,
|
||||||
'name': row.get('name'),
|
'name': row.get('name'),
|
||||||
'description': row.get('description'),
|
'description': row.get('description'),
|
||||||
# TODO: Change this to be `addons_users.user.username`.
|
# TODO: Change this to be `addons_users.user.username`.
|
||||||
|
@ -141,11 +145,18 @@ class ThemeUpdate(object):
|
||||||
'accentcolor': '#%s' % accent if accent else None,
|
'accentcolor': '#%s' % accent if accent else None,
|
||||||
'textcolor': '#%s' % text if text else None,
|
'textcolor': '#%s' % text if text else None,
|
||||||
'updateURL': self.locale_url(settings.VAMO_URL,
|
'updateURL': self.locale_url(settings.VAMO_URL,
|
||||||
'/themes/update-check/%s' % row['addon_id']),
|
'/themes/update-check/' + id_),
|
||||||
# TODO: Change this when we add versions (bug 851881).
|
# TODO: Change this when we add versions (bug 851881).
|
||||||
# 04-25-2013: Bumped for GP migration so we get new `updateURL`s.
|
# 04-25-2013: Bumped for GP migration so we get new `updateURL`s.
|
||||||
'version': '1.1'
|
'version': '1.1'
|
||||||
})
|
}
|
||||||
|
|
||||||
|
# If this theme was originally installed from getpersonas.com,
|
||||||
|
# we have to use the `<persona_id>?src=gp` version of the `updateURL`.
|
||||||
|
if self.from_gp:
|
||||||
|
data['updateURL'] += '?src=gp'
|
||||||
|
|
||||||
|
return json.dumps(data)
|
||||||
|
|
||||||
def image_path(self, filename):
|
def image_path(self, filename):
|
||||||
row = self.data['row']
|
row = self.data['row']
|
||||||
|
|
Загрузка…
Ссылка в новой задаче