From 7a4de10ba377a85ef93a11e04793480e912af878 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 15 Jan 2019 08:14:34 +0100 Subject: [PATCH] misc: use django handler for 404 pages (#30403) --- tests/test_publisher.py | 15 ++++++++------- wcs/qommon/publisher.py | 2 ++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/tests/test_publisher.py b/tests/test_publisher.py index d44715fdc..0894d28ac 100644 --- a/tests/test_publisher.py +++ b/tests/test_publisher.py @@ -13,6 +13,7 @@ import pytest from django.conf import settings from django.core.management import call_command from django.core.management.base import CommandError +from django.http import Http404 from django.test import override_settings from quixote import cleanup from wcs.qommon.http_request import HTTPRequest @@ -113,13 +114,13 @@ def test_finish_interrupted_request(): }) response = pub.process_request(req) assert 'Invalid request: multipart/form-data missing boundary' in str(response) - req = HTTPRequest(StringIO.StringIO(''), { - 'SERVER_NAME': 'example.net', - 'SCRIPT_NAME': '', - 'PATH_INFO': '/gloubiboulga', - }) - response = pub.process_request(req) - assert '

The requested link' in str(response) + with pytest.raises(Http404): + req = HTTPRequest(StringIO.StringIO(''), { + 'SERVER_NAME': 'example.net', + 'SCRIPT_NAME': '', + 'PATH_INFO': '/gloubiboulga', + }) + response = pub.process_request(req) def test_get_tenants(): pub = create_temporary_pub() diff --git a/wcs/qommon/publisher.py b/wcs/qommon/publisher.py index bae21fd15..68e9a9aea 100644 --- a/wcs/qommon/publisher.py +++ b/wcs/qommon/publisher.py @@ -173,6 +173,8 @@ class QommonPublisher(Publisher, object): if request.is_json(): request.response.set_content_type('application/json') return json.dumps({'err': 1, 'err_class': exc.title, 'err_desc': exc.public_msg}) + if isinstance(exc, errors.TraversalError): + raise Http404() output = self.format_publish_error(exc) self.session_manager.finish_successful_request() return output