diff --git a/benefits/eligibility/forms.py b/benefits/eligibility/forms.py index cd9233d5d..ae16efa3a 100644 --- a/benefits/eligibility/forms.py +++ b/benefits/eligibility/forms.py @@ -26,7 +26,7 @@ class EnrollmentFlowSelectionForm(forms.Form): def __init__(self, agency: models.TransitAgency, *args, **kwargs): super().__init__(*args, **kwargs) - flows = agency.enrollment_flows.all() + flows = agency.enrollment_flows.filter(supported_enrollment_methods__contains=models.EnrollmentMethods.DIGITAL) self.classes = "col-lg-8" # second element is not used since we render the whole label using selection_label_template, diff --git a/benefits/in_person/forms.py b/benefits/in_person/forms.py index 752ffd3bf..e2b09b31b 100644 --- a/benefits/in_person/forms.py +++ b/benefits/in_person/forms.py @@ -24,7 +24,7 @@ class InPersonEligibilityForm(forms.Form): def __init__(self, agency: models.TransitAgency, *args, **kwargs): super().__init__(*args, **kwargs) - flows = agency.enrollment_flows.all() + flows = agency.enrollment_flows.filter(supported_enrollment_methods__contains=models.EnrollmentMethods.IN_PERSON) self.classes = "checkbox-parent" flow_field = self.fields["flow"] diff --git a/tests/pytest/eligibility/test_views.py b/tests/pytest/eligibility/test_views.py index fd4329df8..f3e5e3c6f 100644 --- a/tests/pytest/eligibility/test_views.py +++ b/tests/pytest/eligibility/test_views.py @@ -2,6 +2,7 @@ import pytest +from benefits.core import models from benefits.routes import routes from benefits.core.middleware import TEMPLATE_USER_ERROR import benefits.core.session @@ -71,6 +72,36 @@ def model_EnrollmentFlow_with_form_class(mocker, model_EnrollmentFlow): return model_EnrollmentFlow +@pytest.mark.django_db +def test_index_filtering_flows(mocker, model_TransitAgency, client): + digital = models.EnrollmentFlow.objects.create( + transit_agency=model_TransitAgency, + supported_enrollment_methods=[models.EnrollmentMethods.DIGITAL], + label="Digital", + selection_label_template="eligibility/includes/selection-label.html", + ) + in_person = models.EnrollmentFlow.objects.create( + transit_agency=model_TransitAgency, + supported_enrollment_methods=[models.EnrollmentMethods.IN_PERSON], + label="In-Person", + selection_label_template="eligibility/includes/selection-label.html", + ) + both = models.EnrollmentFlow.objects.create( + transit_agency=model_TransitAgency, + supported_enrollment_methods=[models.EnrollmentMethods.DIGITAL, models.EnrollmentMethods.IN_PERSON], + label="Both", + selection_label_template="eligibility/includes/selection-label.html", + ) + mocker.patch("benefits.core.session.agency", autospec=True, return_value=model_TransitAgency) + + path = reverse(routes.ELIGIBILITY_INDEX) + response = client.get(path) + filtered_flow_ids = [choice[0] for choice in response.context_data["form"].fields["flow"].choices] + + assert digital.id, both.id in filtered_flow_ids + assert in_person.id not in filtered_flow_ids + + @pytest.mark.django_db def test_index_get_agency_multiple_flows(mocker, model_TransitAgency, model_EnrollmentFlow, mocked_session_agency, client): # override the mocked session agency with a mock agency that has multiple flows @@ -80,6 +111,7 @@ def test_index_get_agency_multiple_flows(mocker, model_TransitAgency, model_Enro mock_manager = mocker.Mock() mock_manager.all.return_value = [model_EnrollmentFlow, model_EnrollmentFlow] type(mock_agency).enrollment_flows = mocker.PropertyMock(return_value=mock_manager) + type(mock_agency).enrollment_flows.filter.return_value = [model_EnrollmentFlow, model_EnrollmentFlow] mock_agency.index_url = "/agency" mock_agency.eligibility_index_template = "eligibility/index.html" @@ -103,6 +135,7 @@ def test_index_get_agency_single_flow(mocker, model_TransitAgency, model_Enrollm mock_manager = mocker.Mock() mock_manager.all.return_value = [model_EnrollmentFlow] type(mock_agency).enrollment_flows = mocker.PropertyMock(return_value=mock_manager) + type(mock_agency).enrollment_flows.filter.return_value = [model_EnrollmentFlow, model_EnrollmentFlow] mock_agency.index_url = "/agency" mock_agency.eligibility_index_template = "eligibility/index.html" diff --git a/tests/pytest/in_person/test_views.py b/tests/pytest/in_person/test_views.py index 7d53d1729..f4f22ec73 100644 --- a/tests/pytest/in_person/test_views.py +++ b/tests/pytest/in_person/test_views.py @@ -49,6 +49,31 @@ def test_eligibility_logged_in(admin_client): assert response.template_name == "in_person/eligibility.html" +@pytest.mark.django_db +def test_eligibility_logged_in_filtering_flows(mocker, model_TransitAgency, admin_client): + digital = models.EnrollmentFlow.objects.create( + transit_agency=model_TransitAgency, supported_enrollment_methods=[models.EnrollmentMethods.DIGITAL], label="Digital" + ) + in_person = models.EnrollmentFlow.objects.create( + transit_agency=model_TransitAgency, + supported_enrollment_methods=[models.EnrollmentMethods.IN_PERSON], + label="In-Person", + ) + both = models.EnrollmentFlow.objects.create( + transit_agency=model_TransitAgency, + supported_enrollment_methods=[models.EnrollmentMethods.DIGITAL, models.EnrollmentMethods.IN_PERSON], + label="Both", + ) + mocker.patch("benefits.core.session.agency", autospec=True, return_value=model_TransitAgency) + + path = reverse(routes.IN_PERSON_ELIGIBILITY) + response = admin_client.get(path) + filtered_flow_ids = [choice[0] for choice in response.context_data["form"].fields["flow"].choices] + + assert in_person.id, both.id in filtered_flow_ids + assert digital.id not in filtered_flow_ids + + @pytest.mark.django_db @pytest.mark.usefixtures("mocked_session_agency", "mocked_session_flow") def test_confirm_post_valid_form_eligibility_verified(admin_client):