Skip to content

Commit

Permalink
fix: Find out Exception type
Browse files Browse the repository at this point in the history
  • Loading branch information
kovalch committed Jul 2, 2024
1 parent 3b37af1 commit 170ec0a
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions ckanext/subscribe/tests/test_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 170ec0a

Please sign in to comment.