Skip to content

Commit

Permalink
test(enrollment): add test coverage for non-HTTPError failure
Browse files Browse the repository at this point in the history
  • Loading branch information
angela-tran committed Feb 28, 2024
1 parent db3b081 commit a2e47a7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion benefits/enrollment/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def index(request):
analytics.returned_error(request, str(e))
raise Exception(f"{e}: {e.response.json()}")
except Exception as e:
analytics.returned_error(request, e)
analytics.returned_error(request, str(e))
raise e
else:
analytics.returned_success(request, eligibility.group_id)
Expand Down
15 changes: 14 additions & 1 deletion tests/pytest/enrollment/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def test_index_eligible_post_invalid_form(client, invalid_form_data):

@pytest.mark.django_db
@pytest.mark.usefixtures("mocked_session_agency", "mocked_session_eligibility")
def test_index_eligible_post_valid_form_failure(mocker, client, card_tokenize_form_data):
def test_index_eligible_post_valid_form_http_error(mocker, client, card_tokenize_form_data):
mock_client_cls = mocker.patch("benefits.enrollment.views.Client")
mock_client = mock_client_cls.return_value

Expand All @@ -145,6 +145,19 @@ def test_index_eligible_post_valid_form_failure(mocker, client, card_tokenize_fo
client.post(path, card_tokenize_form_data)


@pytest.mark.django_db
@pytest.mark.usefixtures("mocked_session_agency", "mocked_session_eligibility")
def test_index_eligible_post_valid_form_failure(mocker, client, card_tokenize_form_data):
mock_client_cls = mocker.patch("benefits.enrollment.views.Client")
mock_client = mock_client_cls.return_value

mock_client.link_concession_group_funding_source.side_effect = Exception("some other exception")

path = reverse(ROUTE_INDEX)
with pytest.raises(Exception, match=r"some other exception"):
client.post(path, card_tokenize_form_data)


@pytest.mark.django_db
@pytest.mark.usefixtures("mocked_session_agency", "mocked_session_verifier", "mocked_session_eligibility")
def test_index_eligible_post_valid_form_customer_already_enrolled(
Expand Down

0 comments on commit a2e47a7

Please sign in to comment.