return different rdf if valid addon but no updates (bug #655143)

This commit is contained in:
Andy McKay 2011-05-05 15:54:58 -07:00
Родитель 5a1fae9634
Коммит 5168f88453
2 изменённых файлов: 35 добавлений и 5 удалений

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

@ -408,7 +408,7 @@ class TestResponse(test_utils.TestCase):
data["appOS"] = self.mac.api_name
up = self.get(data)
eq_(up.get_rdf(), up.get_bad_rdf())
eq_(up.get_rdf(), up.get_no_updates_rdf())
def test_different_platform(self):
file = File.objects.get(pk=67442)
@ -572,3 +572,14 @@ class TestResponse(test_utils.TestCase):
eq_(up.data['row']['min'], '1.0')
eq_(up.data['row']['version'], '0.5.2')
assert rdf.find(data['appID']) > -1
def test_no_updates_at_all(self):
self.addon_one.versions.all().delete()
upd = self.get(self.good_data)
eq_(upd.get_rdf(), upd.get_no_updates_rdf())
def test_no_updates_my_fx(self):
data = self.good_data.copy()
data['appVersion'] = '5.0.1'
upd = self.get(data)
eq_(upd.get_rdf(), upd.get_no_updates_rdf())

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

@ -60,6 +60,18 @@ bad_rdf = """<?xml version="1.0"?>
</RDF:RDF>"""
no_updates_rdf = """<?xml version="1.0"?>
<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
<RDF:Description about="urn:mozilla:%(type)s:%(guid)s">
<em:updates>
<RDF:Seq>
</RDF:Seq>
</em:updates>
</RDF:Description>
</RDF:RDF>"""
timing_log = commonware.log.getLogger('z.timer')
@ -99,14 +111,14 @@ class Update(object):
if not data['app_id']:
return False
sql = """SELECT id, status FROM addons
sql = """SELECT id, status, addontype_id, guid FROM addons
WHERE guid = %(guid)s AND inactive = 0 LIMIT 1;"""
self.cursor.execute(sql, {'guid': self.data['id']})
result = self.cursor.fetchone()
if result is None:
return False
data['id'], data['addon_status'] = result
data['id'], data['addon_status'], data['type'], data['guid'] = result
data['version_int'] = version_int(data['appVersion'])
if 'appOS' in data:
@ -224,8 +236,11 @@ class Update(object):
return bad_rdf
def get_rdf(self):
if self.is_valid() and self.get_update():
rdf = self.get_good_rdf()
if self.is_valid():
if self.get_update():
rdf = self.get_good_rdf()
else:
rdf = self.get_no_updates_rdf()
else:
rdf = self.get_bad_rdf()
self.cursor.close()
@ -233,6 +248,10 @@ class Update(object):
self.conn.close()
return rdf
def get_no_updates_rdf(self):
name = ADDON_SLUGS_UPDATE[self.data['type']]
return no_updates_rdf % ({'guid': self.data['guid'], 'type': name})
def get_good_rdf(self):
data = self.data['row']
data['if_hash'] = ''