Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Commit

Permalink
add test for catching manifest viewer tracebacks - thanks, @robhudson!…
Browse files Browse the repository at this point in the history
… (bug 784000)
  • Loading branch information
cvan committed Aug 20, 2012
1 parent 1416938 commit edfee97
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
18 changes: 18 additions & 0 deletions mkt/reviewers/tests/test_views.py
Expand Up @@ -11,6 +11,7 @@
import waffle
from nose.tools import eq_, ok_
from pyquery import PyQuery as pq
import requests

This comment has been minimized.

Copy link
@robhudson

robhudson Aug 20, 2012

Member

alphabetical?

This comment has been minimized.

Copy link
@cvan

cvan Aug 20, 2012

Author Contributor

yes ;) I forgot you like from first then import

This comment has been minimized.

Copy link
@robhudson

robhudson Aug 20, 2012

Member

Actually, it's import first, then from. But it's not just me:
http://mozweb.readthedocs.org/en/latest/coding.html#import-statements

But with the addition of requests, the import waffle is no longer in the right spot. Our styles are conflicting!


import amo
import reviews
Expand Down Expand Up @@ -965,6 +966,23 @@ def test_manifest_json_unicode(self, mock_get):
eq_(json.loads(r.content), {'content': u'كك some foreign ish',
'headers': {}})

@mock.patch('mkt.reviewers.views.requests.get')
def test_manifest_json_traceback_in_response(self, mock_get):
m = mock.Mock()
m.content = {'name': 'Some name'}
m.headers = {}
mock_get.side_effect = requests.exceptions.SSLError
mock_get.return_value = m

# We should not 500 on a traceback.

r = self.client.get(reverse('reviewers.apps.review.manifest',
args=[self.app.app_slug]))
eq_(r.status_code, 200)
data = json.loads(r.content)
assert data['content'], 'There should be a content with the traceback'
eq_(data['headers'], {})

def test_abuse(self):
AbuseReport.objects.create(addon=self.app, message='!@#$')
res = self.client.get(self.url)
Expand Down
6 changes: 4 additions & 2 deletions mkt/reviewers/views.py
@@ -1,5 +1,7 @@
import datetime
import json
import sys
import traceback

from django.conf import settings
from django.db.models import Q
Expand Down Expand Up @@ -317,8 +319,8 @@ def app_view_manifest(request, addon):
try:
req = requests.get(addon.manifest_url, verify=False)
content, headers = req.content, req.headers
except Exception, e:
content = e
except Exception:
content = ''.join(traceback.format_exception(*sys.exc_info()))

try:
# Reindent the JSON.
Expand Down

0 comments on commit edfee97

Please sign in to comment.