# HG changeset patch # User neko259 # Date 2014-11-20 15:46:52 # Node ID dec155c19dd28be7f38034b71abaf4391d20872e # Parent ab1b39f35400083649aab3d4dea7e4186c463685 404 page now returns the 404 status for real. Fixed some tests related to this. Excluded ban view from the view tests because it returns 404 if the user is not banned diff --git a/boards/tests/test_pages.py b/boards/tests/test_pages.py --- a/boards/tests/test_pages.py +++ b/boards/tests/test_pages.py @@ -7,12 +7,10 @@ NEW_THREAD_PAGE = '/' THREAD_PAGE_ONE = '/thread/1/' THREAD_PAGE = '/thread/' TAG_PAGE = '/tag/' -HTTP_CODE_REDIRECT = 302 +HTTP_CODE_REDIRECT = 301 HTTP_CODE_OK = 200 HTTP_CODE_NOT_FOUND = 404 -PAGE_404 = 'boards/404.html' - class PagesTest(TestCase): @@ -33,7 +31,7 @@ class PagesTest(TestCase): response_not_existing = client.get(THREAD_PAGE + str( existing_post_id + 1) + '/') - self.assertEqual(PAGE_404, response_not_existing.templates[0].name, + self.assertEqual(HTTP_CODE_NOT_FOUND, response_not_existing.status_code, 'Not existing thread is opened') response_existing = client.get(TAG_PAGE + tag_name + '/') @@ -42,8 +40,7 @@ class PagesTest(TestCase): 'Cannot open existing tag') response_not_existing = client.get(TAG_PAGE + 'not_tag' + '/') - self.assertEqual(PAGE_404, - response_not_existing.templates[0].name, + self.assertEqual(HTTP_CODE_NOT_FOUND, response_not_existing.status_code, 'Not existing tag is opened') reply_id = Post.objects.create_post('', TEST_TEXT, @@ -51,6 +48,5 @@ class PagesTest(TestCase): .get_thread()) response_not_existing = client.get(THREAD_PAGE + str( reply_id) + '/') - self.assertEqual(PAGE_404, - response_not_existing.templates[0].name, + self.assertEqual(HTTP_CODE_REDIRECT, response_not_existing.status_code, 'Reply is opened as a thread') diff --git a/boards/tests/test_views.py b/boards/tests/test_views.py --- a/boards/tests/test_views.py +++ b/boards/tests/test_views.py @@ -8,6 +8,10 @@ logger = logging.getLogger(__name__) HTTP_CODE_OK = 200 +EXCLUDED_VIEWS = { + 'banned', +} + class ViewTest(TestCase): @@ -21,13 +25,17 @@ class ViewTest(TestCase): for url in urls.urlpatterns: try: view_name = url.name + if view_name in EXCLUDED_VIEWS: + logger.debug('View {} is excluded.'.format(view_name)) + continue + logger.debug('Testing view %s' % view_name) try: response = client.get(reverse(view_name)) self.assertEqual(HTTP_CODE_OK, response.status_code, - '%s view not opened' % view_name) + 'View not opened: {}'.format(view_name)) except NoReverseMatch: # This view just needs additional arguments pass diff --git a/boards/views/not_found.py b/boards/views/not_found.py --- a/boards/views/not_found.py +++ b/boards/views/not_found.py @@ -12,4 +12,7 @@ class NotFoundView(BaseBoardView): context = self.get_context_data(request=request) # TODO Use dict here - return render(request, 'boards/404.html', context_instance=context) + response = render(request, 'boards/404.html', context_instance=context) + response.status_code = 404 + + return response