From 710d718bac3e3ff78b5a31e895fc6a3e1a818cdf Mon Sep 17 00:00:00 2001 From: Ashish Dubey Date: Wed, 9 Nov 2011 00:25:27 +0530 Subject: [PATCH] return license information in add-on API (bug 644968) --- apps/api/templates/api/includes/addon.xml | 14 ++++++++-- apps/api/tests/test_views.py | 31 ++++++++++++++++++++++- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/apps/api/templates/api/includes/addon.xml b/apps/api/templates/api/includes/addon.xml index 7e688a41c4..f11c0e2068 100644 --- a/apps/api/templates/api/includes/addon.xml +++ b/apps/api/templates/api/includes/addon.xml @@ -22,9 +22,19 @@ {% endif %} {{ addon.summary|strip_html(new_api) }} - {{ addon.description|strip_html(new_api) }} - + {%- if addon.current_version.license -%} + + {{ addon.current_version.license.name }} + + {%- if not addon.current_version.license.url -%} + {{ addon.current_version.license_url()|absolutify }} + {%- else -%} + {{ addon.current_version.license.url|absolutify }} + {%- endif -%} + + + {%- endif -%} {{ addon.get_icon_url(32, use_default=False) }} {%- if addon.current_version -%} diff --git a/apps/api/tests/test_views.py b/apps/api/tests/test_views.py index 581f5f0dd5..a924da3437 100644 --- a/apps/api/tests/test_views.py +++ b/apps/api/tests/test_views.py @@ -252,6 +252,35 @@ class APITest(TestCase): """hash="sha256:3808b13ef8341378b9c8305ca64820095""" '4ee7dcd8dce09fef55f2673458bc31f"') + def test_addon_license(self): + """Test for license information in response.""" + addon = Addon.objects.get(id=3615) + license = addon.current_version.license + license.name = 'My License' + license.url = 'someurl' + license.save() + api_url = '/en-US/firefox/api/%.1f/addon/3615' % api.CURRENT_VERSION + response = self.client.get(api_url) + doc = pq(response.content) + eq_(doc('license').length, 1) + eq_(doc('license name').length, 1) + eq_(doc('license url').length, 1) + eq_(doc('license name').text(), unicode(license.name)) + eq_(doc('license url').text(), helpers.absolutify(license.url)) + + license.url = '' + license.save() + addon.save() + response = self.client.get(api_url) + doc = pq(response.content) + license_url = addon.current_version.license_url() + eq_(doc('license url').text(), helpers.absolutify(license_url)) + + license.delete() + response = self.client.get(api_url) + doc = pq(response.content) + eq_(doc('license').length, 0) + def test_whitespace(self): """Whitespace is apparently evil for learnmore and install.""" r = make_call('addon/3615') @@ -465,7 +494,7 @@ class APITest(TestCase): '') def test_performance_data(self): - with self.assertNumQueries(23): + with self.assertNumQueries(26): response = self.client.get('/en-US/firefox/api/%.1f/addon/3615' % api.CURRENT_VERSION) doc = pq(response.content)