From 170ec0ac8fcf5a5ef38d622b2566cc27da52df7d Mon Sep 17 00:00:00 2001 From: kovalch Date: Tue, 2 Jul 2024 10:43:18 +0200 Subject: [PATCH] fix: Find out Exception type --- ckanext/subscribe/tests/test_action.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/ckanext/subscribe/tests/test_action.py b/ckanext/subscribe/tests/test_action.py index afc8d60..60af1ca 100644 --- a/ckanext/subscribe/tests/test_action.py +++ b/ckanext/subscribe/tests/test_action.py @@ -288,17 +288,21 @@ def test_verify_recaptcha_failure( dataset_id=dataset["id"], g_recaptcha_response="invalid-recaptcha-response", ) - except ValidationError as cm: + except Exception as cm: + print("Exception type: {}".format(type(cm).__name__)) + print("Exception message: {}".format(cm)) # Asserting that the error is raised due to invalid reCAPTCHA - assert_in( - 'Invalid reCAPTCHA response: "g_recaptcha_response"', - str(cm.exception.error_dict), - ) - - assert not send_request_email.called - - # Ensuring the email is not sent due to invalid reCAPTCHA - assert not send_request_email.called + if isinstance(cm, ValidationError): + assert_in( + 'Invalid reCAPTCHA response: "g_recaptcha_response"', + str(cm.exception.error_dict), + ) + + # Ensuring the email is not sent due to invalid reCAPTCHA + assert not send_request_email.called + else: + # Re-raise the exception if it's not a ValidationError + raise else: assert False, "ValidationError not raised"