Permalink
Browse files

make the 404 handler return a 404 status code + tests

  • Loading branch information...
1 parent 594ee9f commit 885a33e980d031e771bcaacf0b763427c3b3dca2 @mapleoin committed Sep 21, 2012
Showing with 18 additions and 1 deletion.
  1. +17 −0 popcorn/test/test_views.py
  2. +1 −1 popcorn/views.py
View
17 popcorn/test/test_views.py
@@ -199,3 +199,20 @@ def test_distro_doc_json(self):
})
self.assertEqual(response.headers['Content-Type'],
'application/json')
+
+ def test_404_json(self):
+ response = self.app.get('/notFound',
+ headers=[('Accept', 'application/json')])
+
+ self.assertEqual(json.loads(response.data), {
+ u'request': u'/notFound',
+ u'error': u'Not Found'})
+ self.assertEqual(response.headers['Content-Type'], 'application/json')
+ self.assertEqual(response.status_code, 404)
+
+ def test_404_html(self):
+ response = self.app.get('/notFound')
+
+ self.assertIn('Not Found', response.data)
+ self.assertIn('text/html', response.headers['Content-Type'])
+ self.assertEqual(response.status_code, 404)
View
2 popcorn/views.py
@@ -223,4 +223,4 @@ def faq():
def not_found(error):
"""Handle page not found error"""
error_msg = "Not Found"
- return dict(error=error_msg, code=404, request=request.path)
+ return dict(error=error_msg, status_code=404, request=request.path)

0 comments on commit 885a33e

Please sign in to comment.