Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F9341630
test_middlewares.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
test_middlewares.py
View Options
# Copyright (C) 2020 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU Affero General Public License version 3, or any later version
# See top-level LICENSE file for more information
import
pytest
from
django.test
import
modify_settings
from
swh.web.common.utils
import
reverse
@modify_settings
(
MIDDLEWARE
=
{
"remove"
:
[
"swh.web.common.middlewares.ExceptionMiddleware"
]}
)
def
test_exception_middleware_disabled
(
client
,
mocker
,
snapshot
):
mock_browse_snapshot_directory
=
mocker
.
patch
(
"swh.web.browse.views.snapshot.browse_snapshot_directory"
)
mock_browse_snapshot_directory
.
side_effect
=
Exception
(
"Something went wrong"
)
url
=
reverse
(
"browse-snapshot-directory"
,
url_args
=
{
"snapshot_id"
:
snapshot
})
with
pytest
.
raises
(
Exception
,
match
=
"Something went wrong"
):
client
.
get
(
url
)
def
test_exception_middleware_enabled
(
client
,
mocker
,
snapshot
):
mock_browse_snapshot_directory
=
mocker
.
patch
(
"swh.web.browse.views.snapshot.browse_snapshot_directory"
)
mock_browse_snapshot_directory
.
side_effect
=
Exception
(
"Something went wrong"
)
url
=
reverse
(
"browse-snapshot-directory"
,
url_args
=
{
"snapshot_id"
:
snapshot
})
resp
=
client
.
get
(
url
)
assert
resp
.
status_code
==
500
assert
hasattr
(
resp
,
"traceback"
)
assert
"Traceback"
in
getattr
(
resp
,
"traceback"
)
File Metadata
Details
Attached
Mime Type
text/x-python
Expires
Fri, Jul 4, 12:12 PM (2 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3240568
Attached To
rDWAPPS Web applications
Event Timeline
Log In to Comment