From ea6ca23f5711aa55d09d5aeae924a209f679b87a Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sun, 13 Dec 2020 18:41:43 +0100 Subject: [PATCH] lib: add tests for sentry integration --- .../lib/templatetags/authentik_is_active.py | 55 ------------------- authentik/lib/tests/test_sentry.py | 14 +++++ 2 files changed, 14 insertions(+), 55 deletions(-) delete mode 100644 authentik/lib/templatetags/authentik_is_active.py create mode 100644 authentik/lib/tests/test_sentry.py diff --git a/authentik/lib/templatetags/authentik_is_active.py b/authentik/lib/templatetags/authentik_is_active.py deleted file mode 100644 index a99e34bbd..000000000 --- a/authentik/lib/templatetags/authentik_is_active.py +++ /dev/null @@ -1,55 +0,0 @@ -"""authentik lib navbar Templatetag""" -from django import template -from django.http import HttpRequest -from structlog import get_logger - -register = template.Library() - -LOGGER = get_logger() -ACTIVE_STRING = "pf-m-current" - - -@register.simple_tag(takes_context=True) -def is_active(context, *args: str, **_) -> str: - """Return whether a navbar link is active or not.""" - request: HttpRequest = context.get("request") - if not request.resolver_match: - return "" - match = request.resolver_match - for url in args: - if ":" in url: - app_name, url = url.split(":") - if match.app_name == app_name and match.url_name == url: - return ACTIVE_STRING - else: - if match.url_name == url: - return ACTIVE_STRING - return "" - - -@register.simple_tag(takes_context=True) -def is_active_url(context, view: str) -> str: - """Return whether a navbar link is active or not.""" - request: HttpRequest = context.get("request") - if not request.resolver_match: - return "" - - match = request.resolver_match - current_full_url = f"{match.app_name}:{match.url_name}" - - if current_full_url == view: - return ACTIVE_STRING - return "" - - -@register.simple_tag(takes_context=True) -def is_active_app(context, *args: str) -> str: - """Return True if current link is from app""" - - request: HttpRequest = context.get("request") - if not request.resolver_match: - return "" - for app_name in args: - if request.resolver_match.app_name == app_name: - return ACTIVE_STRING - return "" diff --git a/authentik/lib/tests/test_sentry.py b/authentik/lib/tests/test_sentry.py new file mode 100644 index 000000000..0637c510c --- /dev/null +++ b/authentik/lib/tests/test_sentry.py @@ -0,0 +1,14 @@ +"""test sentry integration""" +from django.test import TestCase +from authentik.lib.sentry import before_send, SentryIgnoredException + +class TestSentry(TestCase): + """test sentry integration""" + + def error_not_sent(self): + """Test SentryIgnoredError not sent""" + self.assertIsNone(before_send(None, {"exc_info": (0, SentryIgnoredException(), 0)})) + + def error_sent(self): + """Test error sent""" + self.assertIsNone(before_send(None, {"exc_info": (0, ValueError(), 0)}))