Permalink
Browse files

Fix traceback on revision compare with bad params

* Catch exceptions in parsing to/from revision parameters

* Re-enable CompareRevisionTests, with a couple of fixes

* Added test_bad_parameters
  • Loading branch information...
1 parent 5cdfaab commit 136ba15c11b3f8bd48ae416fd9433a5dca5191e4 @lmorchard lmorchard committed Feb 15, 2013
Showing with 17 additions and 5 deletions.
  1. +11 −3 apps/wiki/tests/test_templates.py
  2. +6 −2 apps/wiki/views.py
View
14 apps/wiki/tests/test_templates.py
@@ -968,15 +968,15 @@ def test_review_translation_of_rejected_parent(self):
doc('details .warning-box').text())
-class CompareRevisionTests(SkippedTestCase):
+class CompareRevisionTests(TestCaseBase):
"""Tests for Review Revisions"""
fixtures = ['test_users.json']
def setUp(self):
super(CompareRevisionTests, self).setUp()
self.document = _create_document()
self.revision1 = self.document.current_revision
- user = User.objects.get(pk=118533)
+ user = User.objects.get(username='testuser')
self.revision2 = Revision(summary="lipsum",
content='<div>Lorem Ipsum Dolor</div>',
keywords='kw1 kw2',
@@ -985,6 +985,14 @@ def setUp(self):
self.client.login(username='admin', password='testpass')
+ def test_bad_parameters(self):
+ """Ensure badly-formed revision parameters do not cause errors"""
+ url = reverse('wiki.compare_revisions', args=[self.document.slug])
+ query = {'from': '1e309', 'to': u'1e309'}
+ url = urlparams(url, **query)
+ response = self.client.get(url)
+ eq_(404, response.status_code)
+
def test_compare_revisions(self):
"""Compare two revisions"""
url = reverse('wiki.compare_revisions', args=[self.document.slug])
@@ -993,7 +1001,7 @@ def test_compare_revisions(self):
response = self.client.get(url)
eq_(200, response.status_code)
doc = pq(response.content)
- eq_('Dolor', doc('div.revision-diff span.diff_add').text())
+ eq_('Dolor', doc('span.diff_add').text())
def test_compare_revisions_invalid_to_int(self):
"""Provide invalid 'to' int for revision ids."""
View
8 apps/wiki/views.py
@@ -1418,8 +1418,12 @@ def compare_revisions(request, document_slug, document_locale):
if 'from' not in request.GET or 'to' not in request.GET:
raise Http404
- from_id = smart_int(request.GET.get('from'))
- to_id = smart_int(request.GET.get('to'))
+ try:
+ from_id = smart_int(request.GET.get('from'))
+ to_id = smart_int(request.GET.get('to'))
+ except:
+ # Punt any errors in parameter handling to a 404
+ raise Http404
revision_from = get_object_or_404(Revision, id=from_id)
revision_to = get_object_or_404(Revision, id=to_id)

0 comments on commit 136ba15

Please sign in to comment.