Ignoring non ints for addon_type in list api.

This commit is contained in:
Dave Dash 2010-03-19 10:27:12 -07:00
Родитель 6bd85c43d9
Коммит 6b4183aae0
2 изменённых файлов: 17 добавлений и 5 удалений

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

@ -26,7 +26,7 @@ class No500ErrorsTest(TestCase):
"""
A series of unfortunate urls that have caused 500 errors in the past.
"""
def test_bad_type(self):
def test_search_bad_type(self):
"""
For search/:term/:addon_type <-- addon_type should be an integer.
"""
@ -35,6 +35,13 @@ class No500ErrorsTest(TestCase):
# is good. We just don't want 500 errors.
assert response.status_code != 500, "We recieved a 500 error, wtf?"
def test_list_bad_type(self):
"""
For list/new/:addon_type <-- addon_type should be an integer.
"""
response = make_call('/list/new/extension')
assert response.status_code != 500, "We recieved a 500 error, wtf?"
def test_utf_redirect(self):
"""Test that urls with unicode redirect propperly."""
response = make_call(u'search/ツールバー', version=1.5)

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

@ -184,10 +184,15 @@ class ListView(APIView):
else:
qs = Addon.objects.featured(self.request.APP)
if addon_type.lower() != 'all':
addon_type = int(addon_type)
if addon_type:
qs = qs.filter(type=addon_type)
if addon_type.upper() != 'ALL':
try:
addon_type = int(addon_type)
if addon_type:
qs = qs.filter(type=addon_type)
except ValueError:
# `addon_type` is ALL or a type id. Otherwise we ignore it.
pass
if platform.lower() != 'all':
qs = (qs.distinct() &