Fixing tests

This commit is contained in:
Jonathan Bobel
2025-02-27 14:21:43 -05:00
parent f031f4bf18
commit a5146fc58a
2 changed files with 26 additions and 17 deletions

View File

@@ -982,20 +982,13 @@ def test_view_organization_settings(
page = client_request.get(endpoint, org_id=organization_one["id"]) page = client_request.get(endpoint, org_id=organization_one["id"])
radios = page.select("input[type=radio]") radios = page.select("input[type=radio]")
labels = page.select("label.usa-radio__label") # Select all radio labels in order
for index, option in enumerate(expected_options): for index, option in enumerate(expected_options):
option_values = { option_values = {
"value": radios[index]["value"], "value": radios[index]["value"],
"label": normalize_spaces( "label": normalize_spaces(labels[index].text), # Match labels using index
page.select_one("label[for={}]".format(radios[index]["id"])).text
),
} }
if "hint" in option:
option_values["hint"] = normalize_spaces(
page.select_one(
"label[for={}] + .usa-hint".format(radios[index]["id"])
).text
)
assert option_values == option assert option_values == option
if expected_selected: if expected_selected:
@@ -1082,7 +1075,7 @@ def test_update_organization_sector_sends_service_id_data_to_api_client(
client_request.post( client_request.post(
"main.edit_organization_type", "main.edit_organization_type",
org_id=organization_one["id"], org_id=organization_one["id"],
_data={"organization_type": "federal"}, _data={"organization_type": "state"},
_expected_status=302, _expected_status=302,
_expected_redirect=url_for( _expected_redirect=url_for(
"main.organization_settings", "main.organization_settings",
@@ -1093,7 +1086,7 @@ def test_update_organization_sector_sends_service_id_data_to_api_client(
mock_update_organization.assert_called_once_with( mock_update_organization.assert_called_once_with(
organization_one["id"], organization_one["id"],
cached_service_ids=["12345", "67890", SERVICE_ONE_ID], cached_service_ids=["12345", "67890", SERVICE_ONE_ID],
organization_type="federal", organization_type="state",
) )

View File

@@ -466,14 +466,30 @@ def test_show_switch_service_to_count_as_live_page(
"main.service_switch_count_as_live", "main.service_switch_count_as_live",
service_id=SERVICE_ONE_ID, service_id=SERVICE_ONE_ID,
) )
assert page.select_one("[checked]")["value"] == selected
assert ( client_request.login(platform_admin_user)
page.select_one( page = client_request.get(
"label[for={}]".format(page.select_one("[checked]")["id"]) "main.service_switch_count_as_live",
).text.strip() service_id=SERVICE_ONE_ID,
== labelled
) )
# Find the checked radio button
checked_input = page.select_one("[checked]")
# Ensure we actually found a checked input
assert checked_input is not None, "No checked radio button found"
# Check that the selected value is as expected
assert checked_input["value"] == selected
# Find all labels
labels = page.select("label.usa-radio__label")
# Extract label text and see if it matches the expected label
label_texts = [label.text.strip() for label in labels]
assert labelled in label_texts, f"Expected label '{labelled}' not found. Found labels: {label_texts}"
@pytest.mark.parametrize( @pytest.mark.parametrize(
("post_data", "expected_persisted_value"), ("post_data", "expected_persisted_value"),