From ebf9f0ca63026215ca72d6cb82753e490ecfabae Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Thu, 16 Sep 2021 10:59:00 +0200 Subject: [PATCH] stages/email: don't crash when testing stage does not exist Signed-off-by: Jens Langhammer --- authentik/stages/consent/tests.py | 5 +++-- authentik/stages/email/management/commands/test_email.py | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/authentik/stages/consent/tests.py b/authentik/stages/consent/tests.py index f1b10bc86..25f99d30a 100644 --- a/authentik/stages/consent/tests.py +++ b/authentik/stages/consent/tests.py @@ -1,7 +1,6 @@ """consent tests""" from time import sleep -from django.http.response import HttpResponse from django.urls import reverse from django.utils.encoding import force_str from rest_framework.test import APITestCase @@ -41,12 +40,14 @@ class TestConsentStage(APITestCase): session = self.client.session session[SESSION_KEY_PLAN] = plan session.save() - response: HttpResponse = self.client.post( + response = self.client.post( reverse("authentik_api:flow-executor", kwargs={"flow_slug": flow.slug}), {}, ) + # pylint: disable=no-member self.assertEqual(response.status_code, 200) self.assertJSONEqual( + # pylint: disable=no-member force_str(response.content), { "component": "xak-flow-redirect", diff --git a/authentik/stages/email/management/commands/test_email.py b/authentik/stages/email/management/commands/test_email.py index a2c36d545..3700d53c1 100644 --- a/authentik/stages/email/management/commands/test_email.py +++ b/authentik/stages/email/management/commands/test_email.py @@ -16,7 +16,11 @@ class Command(BaseCommand): # pragma: no cover """Send a test-email with global settings""" delete_stage = False if options["stage"]: - stage = EmailStage.objects.get(name=options["stage"]) + stages = EmailStage.objects.filter(name=options["stage"]) + if not stages.exists(): + print(f"Stage '{options['stage']}' does not exist") + return + stage = stages.first() else: stage = EmailStage.objects.create( name=f"temp-global-stage-{uuid4()}", use_global_settings=True