Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/tests/test_gunicorn_config.py
# Copyright (C) 2019 The Software Heritage developers | # Copyright (C) 2019-2020 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import os | import os | ||||
from unittest.mock import patch | from unittest.mock import patch | ||||
import swh.deposit.gunicorn_config as gunicorn_config | import swh.deposit.gunicorn_config as gunicorn_config | ||||
Show All 13 Lines | with patch('swh.deposit.gunicorn_config.DjangoIntegration', | ||||
with patch('sentry_sdk.init') as sentry_sdk_init: | with patch('sentry_sdk.init') as sentry_sdk_init: | ||||
with patch.dict(os.environ, {'SWH_SENTRY_DSN': 'test_dsn'}): | with patch.dict(os.environ, {'SWH_SENTRY_DSN': 'test_dsn'}): | ||||
gunicorn_config.post_fork(None, None) | gunicorn_config.post_fork(None, None) | ||||
sentry_sdk_init.assert_called_once_with( | sentry_sdk_init.assert_called_once_with( | ||||
dsn='test_dsn', | dsn='test_dsn', | ||||
integrations=[django_integration], | integrations=[django_integration], | ||||
debug=False, | debug=False, | ||||
release=None, | |||||
) | ) | ||||
def test_post_fork_debug(): | def test_post_fork_debug(): | ||||
django_integration = object() # unique object to check for equality | django_integration = object() # unique object to check for equality | ||||
with patch('swh.deposit.gunicorn_config.DjangoIntegration', | with patch('swh.deposit.gunicorn_config.DjangoIntegration', | ||||
new=lambda: django_integration): | new=lambda: django_integration): | ||||
with patch('sentry_sdk.init') as sentry_sdk_init: | with patch('sentry_sdk.init') as sentry_sdk_init: | ||||
with patch.dict(os.environ, {'SWH_SENTRY_DSN': 'test_dsn', | with patch.dict(os.environ, {'SWH_SENTRY_DSN': 'test_dsn', | ||||
'SWH_SENTRY_DEBUG': '1'}): | 'SWH_SENTRY_DEBUG': '1'}): | ||||
gunicorn_config.post_fork(None, None) | gunicorn_config.post_fork(None, None) | ||||
sentry_sdk_init.assert_called_once_with( | sentry_sdk_init.assert_called_once_with( | ||||
dsn='test_dsn', | dsn='test_dsn', | ||||
integrations=[django_integration], | integrations=[django_integration], | ||||
debug=True, | debug=True, | ||||
release=None, | |||||
) | ) |