mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-01 03:48:04 +00:00
33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
from contextlib import nullcontext as does_not_raise
|
|
|
|
import pytest
|
|
from _pytest.python_api import RaisesContext
|
|
from django.test import Client
|
|
from django.test.utils import override_settings
|
|
from django.urls import reverse
|
|
|
|
|
|
@pytest.mark.django_db
|
|
@pytest.mark.parametrize(
|
|
("sentry_dsn", "sentry_env", "expected_error", "expected_return_code"),
|
|
[
|
|
# Working case
|
|
("something", "development", pytest.raises(ZeroDivisionError), None),
|
|
# View is disabled when DSN isn't defined or environment isn't development
|
|
("something", "production", does_not_raise(), 404),
|
|
("", "development", does_not_raise(), 404),
|
|
("", "production", does_not_raise(), 404),
|
|
],
|
|
)
|
|
def test_sentry_debug_endpoint(
|
|
client: Client,
|
|
sentry_dsn: str,
|
|
sentry_env: str,
|
|
expected_error: RaisesContext[ZeroDivisionError] | does_not_raise[None],
|
|
expected_return_code: int | None,
|
|
):
|
|
with expected_error, override_settings(
|
|
SENTRY_DSN=sentry_dsn, SENTRY_ENV=sentry_env
|
|
):
|
|
assert client.get(reverse("sentry-debug")).status_code == expected_return_code
|