Example #1
0
def test_post_fork_with_package_env():
    flask_integration = object()  # unique object to check for equality
    with patch(
        "sentry_sdk.integrations.flask.FlaskIntegration", new=lambda: flask_integration
    ):
        with patch("sentry_sdk.init") as sentry_sdk_init:
            with patch.dict(
                os.environ,
                {
                    "SWH_SENTRY_DSN": "test_dsn",
                    "SWH_SENTRY_ENVIRONMENT": "tests",
                    "SWH_MAIN_PACKAGE": "swh.core",
                },
            ):
                gunicorn_config.post_fork(None, None)

    version = pkg_resources.get_distribution("swh.core").version

    sentry_sdk_init.assert_called_once_with(
        dsn="test_dsn",
        integrations=[flask_integration],
        debug=False,
        release="swh.core@" + version,
        environment="tests",
    )
Example #2
0
def test_post_fork_no_flask():
    with patch("sentry_sdk.init") as sentry_sdk_init:
        with patch.dict(os.environ, {"SWH_SENTRY_DSN": "test_dsn"}):
            gunicorn_config.post_fork(None, None, flask=False)

    sentry_sdk_init.assert_called_once_with(
        dsn="test_dsn", integrations=[], debug=False, release=None, environment=None,
    )
Example #3
0
def test_post_fork_with_dsn_env():
    flask_integration = object()  # unique object to check for equality
    with patch(
        "sentry_sdk.integrations.flask.FlaskIntegration", new=lambda: flask_integration
    ):
        with patch("sentry_sdk.init") as sentry_sdk_init:
            with patch.dict(os.environ, {"SWH_SENTRY_DSN": "test_dsn"}):
                gunicorn_config.post_fork(None, None)

    sentry_sdk_init.assert_called_once_with(
        dsn="test_dsn",
        integrations=[flask_integration],
        debug=False,
        release=None,
        environment=None,
    )
Example #4
0
def test_post_fork_no_flask():
    logging_integration = object()

    with patch("sentry_sdk.init") as sentry_sdk_init, patch(
            "sentry_sdk.integrations.logging.LoggingIntegration",
            new=lambda event_level: logging_integration,
    ), patch.dict(os.environ, {"SWH_SENTRY_DSN": "test_dsn"}):
        gunicorn_config.post_fork(None, None, flask=False)

    sentry_sdk_init.assert_called_once_with(
        dsn="test_dsn",
        integrations=[logging_integration],
        debug=False,
        release=None,
        environment=None,
    )
Example #5
0
def test_post_fork_override_logging_events_envvar():

    with patch("sentry_sdk.init") as sentry_sdk_init, patch.dict(
            os.environ,
        {
            "SWH_SENTRY_DSN": "test_dsn",
            "SWH_SENTRY_DISABLE_LOGGING_EVENTS": "false"
        },
    ):
        gunicorn_config.post_fork(None, None, flask=False)

    sentry_sdk_init.assert_called_once_with(
        dsn="test_dsn",
        integrations=[],
        debug=False,
        release=None,
        environment=None,
    )
Example #6
0
def test_post_fork_extras():
    flask_integration = object()  # unique object to check for equality
    with patch(
        "sentry_sdk.integrations.flask.FlaskIntegration", new=lambda: flask_integration
    ):
        with patch("sentry_sdk.init") as sentry_sdk_init:
            with patch.dict(os.environ, {"SWH_SENTRY_DSN": "test_dsn"}):
                gunicorn_config.post_fork(
                    None,
                    None,
                    sentry_integrations=["foo"],
                    extra_sentry_kwargs={"bar": "baz"},
                )

    sentry_sdk_init.assert_called_once_with(
        dsn="test_dsn",
        integrations=["foo", flask_integration],
        debug=False,
        bar="baz",
        release=None,
        environment=None,
    )
Example #7
0
def test_post_fork_debug():
    flask_integration = object()
    logging_integration = object()

    with patch("sentry_sdk.integrations.flask.FlaskIntegration",
               new=lambda: flask_integration), patch(
                   "sentry_sdk.integrations.logging.LoggingIntegration",
                   new=lambda event_level: logging_integration,
               ), patch("sentry_sdk.init") as sentry_sdk_init, patch.dict(
                   os.environ, {
                       "SWH_SENTRY_DSN": "test_dsn",
                       "SWH_SENTRY_DEBUG": "1"
                   }):
        gunicorn_config.post_fork(None, None)

    sentry_sdk_init.assert_called_once_with(
        dsn="test_dsn",
        integrations=[flask_integration, logging_integration],
        debug=True,
        release=None,
        environment=None,
    )
Example #8
0
def test_post_fork_default():
    with patch("sentry_sdk.init") as sentry_sdk_init:
        gunicorn_config.post_fork(None, None)

    sentry_sdk_init.assert_not_called()