Changeset View
Changeset View
Standalone View
Standalone View
swh/core/api/tests/test_gunicorn.py
Show All 24 Lines | with patch('sentry_sdk.integrations.flask.FlaskIntegration', | ||||
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=[flask_integration], | integrations=[flask_integration], | ||||
debug=False, | debug=False, | ||||
release=None, | release=None, | ||||
environment=None, | |||||
) | ) | ||||
def test_post_fork_with_package_env(): | def test_post_fork_with_package_env(): | ||||
flask_integration = object() # unique object to check for equality | flask_integration = object() # unique object to check for equality | ||||
with patch('sentry_sdk.integrations.flask.FlaskIntegration', | with patch('sentry_sdk.integrations.flask.FlaskIntegration', | ||||
new=lambda: flask_integration): | new=lambda: flask_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_ENVIRONMENT': 'tests', | |||||
'SWH_MAIN_PACKAGE': 'swh.core'}): | 'SWH_MAIN_PACKAGE': 'swh.core'}): | ||||
gunicorn_config.post_fork(None, None) | gunicorn_config.post_fork(None, None) | ||||
version = pkg_resources.get_distribution('swh.core').version | version = pkg_resources.get_distribution('swh.core').version | ||||
sentry_sdk_init.assert_called_once_with( | sentry_sdk_init.assert_called_once_with( | ||||
dsn='test_dsn', | dsn='test_dsn', | ||||
integrations=[flask_integration], | integrations=[flask_integration], | ||||
debug=False, | debug=False, | ||||
release='swh.core@' + version, | release='swh.core@' + version, | ||||
environment='tests', | |||||
) | ) | ||||
def test_post_fork_debug(): | def test_post_fork_debug(): | ||||
flask_integration = object() # unique object to check for equality | flask_integration = object() # unique object to check for equality | ||||
with patch('sentry_sdk.integrations.flask.FlaskIntegration', | with patch('sentry_sdk.integrations.flask.FlaskIntegration', | ||||
new=lambda: flask_integration): | new=lambda: flask_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=[flask_integration], | integrations=[flask_integration], | ||||
debug=True, | debug=True, | ||||
release=None, | release=None, | ||||
environment=None, | |||||
) | ) | ||||
def test_post_fork_no_flask(): | def test_post_fork_no_flask(): | ||||
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, flask=False) | gunicorn_config.post_fork(None, None, flask=False) | ||||
sentry_sdk_init.assert_called_once_with( | sentry_sdk_init.assert_called_once_with( | ||||
dsn='test_dsn', | dsn='test_dsn', | ||||
integrations=[], | integrations=[], | ||||
debug=False, | debug=False, | ||||
release=None, | release=None, | ||||
environment=None, | |||||
) | ) | ||||
def test_post_fork_extras(): | def test_post_fork_extras(): | ||||
flask_integration = object() # unique object to check for equality | flask_integration = object() # unique object to check for equality | ||||
with patch('sentry_sdk.integrations.flask.FlaskIntegration', | with patch('sentry_sdk.integrations.flask.FlaskIntegration', | ||||
new=lambda: flask_integration): | new=lambda: flask_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'}): | ||||
gunicorn_config.post_fork( | gunicorn_config.post_fork( | ||||
None, None, sentry_integrations=['foo'], | None, None, sentry_integrations=['foo'], | ||||
extra_sentry_kwargs={'bar': 'baz'}) | extra_sentry_kwargs={'bar': 'baz'}) | ||||
sentry_sdk_init.assert_called_once_with( | sentry_sdk_init.assert_called_once_with( | ||||
dsn='test_dsn', | dsn='test_dsn', | ||||
integrations=['foo', flask_integration], | integrations=['foo', flask_integration], | ||||
debug=False, | debug=False, | ||||
bar='baz', | bar='baz', | ||||
release=None, | release=None, | ||||
environment=None, | |||||
) | ) |