fix KeyError at source, not in test

pull/1/head
eric 2013-06-26 14:36:04 -04:00
parent b063fe6c3f
commit f2f02237a8
2 changed files with 4 additions and 9 deletions

View File

@ -697,14 +697,9 @@ class DownloadPageTest(TestCase):
eb2.save() eb2.save()
anon_client = Client() anon_client = Client()
try: response = anon_client.get("/work/%s/download/" % w.id, follow=True)
response = anon_client.get("/work/%s/download/" % w.id, follow=True) self.assertContains(response, "/download_ebook/%s/"% eb1.id, count=9)
except KeyError: self.assertContains(response, "/download_ebook/%s/"% eb2.id, count=4)
# user agent testing in views.download fails with anon client,
# but isn't relevant to this bit of functionality
pass
self.assertContains(response, "/download_ebook/%s/"% eb1.id, count=3) # no extra now, readmill not for google books?
self.assertContains(response, "/download_ebook/%s/"% eb2.id, count=3)
class LocaldatetimeTest(TestCase): class LocaldatetimeTest(TestCase):

View File

@ -2428,7 +2428,7 @@ def download(request, work_id):
readmill_epub_url = readmill_epub_ebook.url readmill_epub_url = readmill_epub_ebook.url
except: except:
readmill_epub_url = None readmill_epub_url = None
agent = request.META['HTTP_USER_AGENT'] agent = request.META.get('HTTP_USER_AGENT','')
iOS = 'iPad' in agent or 'iPhone' in agent or 'iPod' in agent iOS = 'iPad' in agent or 'iPhone' in agent or 'iPod' in agent
iOS_app = iOS and not 'Safari' in agent iOS_app = iOS and not 'Safari' in agent
android = 'Android' in agent android = 'Android' in agent