have themes update_check return the same ID in JSON response (bug 866482)

This commit is contained in:
Chris Van 2013-04-28 13:33:08 -07:00
Родитель b10d91fc5a
Коммит aefb3f48b0
2 изменённых файлов: 50 добавлений и 30 удалений

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

@ -62,42 +62,45 @@ class TestWSGIApplication(amo.tests.TestCase):
class TestThemeUpdate(amo.tests.TestCase):
fixtures = ['addons/persona']
good = {
'username': 'persona_author',
'description': 'yolo',
'detailURL': settings.SITE_URL + '/en-US/addon/a15663/',
'accentcolor': '#8d8d97',
'iconURL': '/15663/preview_small.jpg',
'previewURL': '/15663/preview.jpg',
'textcolor': '#ffffff',
'id': '15663',
'headerURL': '/15663/BCBG_Persona_header2.png',
'dataurl': '',
'name': 'My Persona',
'author': 'persona_author',
'updateURL': settings.VAMO_URL + '/en-US/themes/update-check/15663',
'version': '1.0',
'footerURL': '/15663/BCBG_Persona_footer2.png'
}
def setUp(self):
self.good = {
'username': 'persona_author',
'description': 'yolo',
'detailURL': '/en-US/addon/a15663/',
'accentcolor': '#8d8d97',
'iconURL': '/15663/preview_small.jpg',
'previewURL': '/15663/preview.jpg',
'textcolor': '#ffffff',
'id': '15663',
'headerURL': '/15663/BCBG_Persona_header2.png',
'dataurl': '',
'name': 'My Persona',
'author': 'persona_author',
'updateURL': (settings.VAMO_URL +
'/en-US/themes/update-check/15663'),
'version': '1.1',
'footerURL': '/15663/BCBG_Persona_footer2.png'
}
def check_good(self, data):
for k, v in self.good.iteritems():
got = data[k]
if k.endswith('URL'):
if k in ('detailURL', 'updateURL'):
eq_(got.find('?'), -1,
'"%s" should not contain "?"' % k)
assert got.startswith('http'), (
'Expected absolute URL for "%s": %s' % (k, got))
assert got.endswith(v), (
'Expected "%s" to end with "%s". Got "%s".' % (k, v, got))
else:
assert got.find('?') > -1, (
'"%s" must contain "?" for modified timestamp' % k)
# Strip `?<modified>` timestamps.
got = got.rsplit('?')[0]
# Strip `?<modified>` timestamps.
got = got.rsplit('?')[0]
assert got.endswith(v), (
'Expected "%s" to end with "%s". Got "%s".' % (k, v, got))
else:
eq_(got, v, 'Expected "%s" for "%s". Got "%s".' % (v, k, got))
assert got.endswith(v), (
'Expected "%s" to end with "%s". Got "%s".' % (k, v, got))
def get_update(self, *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()))
# 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(
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):
self.conn, self.cursor = None, None
self.from_gp = qs == 'src=gp'
self.data = {
'locale': locale,
'id': id_,
# If we came from getpersonas.com, then look up by `persona_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,
'row': {}
}
@ -123,8 +124,11 @@ class ThemeUpdate(object):
row = self.data['row']
accent = row.get('accentcolor')
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'),
'description': row.get('description'),
# TODO: Change this to be `addons_users.user.username`.
@ -141,11 +145,18 @@ class ThemeUpdate(object):
'accentcolor': '#%s' % accent if accent else None,
'textcolor': '#%s' % text if text else None,
'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).
# 04-25-2013: Bumped for GP migration so we get new `updateURL`s.
'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):
row = self.data['row']