Repository: home-assistant/core
File: tests/components/aws_s3/test_backup.py (Python)

Code before:
async def test_agent_list_backups_parametrized(
    hass: HomeAssistant,
    hass_ws_client: WebSocketGenerator,
    mock_config_entry: MockConfigEntry,
    mock_client: MagicMock,
    test_backup: AgentBackup,
) -> None:
    """Test agent list backups with and without prefix."""
    client = await hass_ws_client(hass)
    await client.send_json_auto_id({"type": "backup/info"})
    response = await client.receive_json()

    assert response["success"]
    assert response["result"]["agent_errors"] == {}

    # Get prefix from config entry
    prefix = mock_config_entry.data.get(CONF_PREFIX)
    if prefix is not None:
        mock_client.get_paginator.return_value.paginate.assert_called_with(
            Bucket="test", Prefix=f"{prefix}/"
        )
    else:
        # Verify no Prefix parameter when no prefix is configured
        mock_client.get_paginator.return_value.paginate.assert_called_with(
            Bucket="test"
        )


@pytest.mark.parametrize(
    "config_entry_extra_data",
    [
        {"prefix": "backups/home"},
        {},
    ],
    ids=["with_prefix", "no_prefix"],
)
async def test_agent_delete_backup_parametrized(
    hass: HomeAssistant,
    hass_ws_client: WebSocketGenerator,
    mock_client: MagicMock,
    mock_config_entry: MockConfigEntry,
    test_backup: AgentBackup,
) -> None:
    """Test agent delete backup with and without prefix."""
    client = await hass_ws_client(hass)

    await client.send_json_auto_id(
        {
            "type": "backup/delete",
            "backup_id": "23e64aec",
        }

Review comment (suggestion):
Don't branch in tests.
In this case, pass in all or just extra kwargs via parametrizations.

```py
@pytest.mark.parametrize(
    ("config_entry_extra_data", "expected_paginate_kwargs"),
    [
        ({"prefix": "backups/home"}, {"Prefix": "backups/home"}),
        ({}, {}),
    ],
    ids=["with_prefix", "no_prefix"],
)
async def test_agent_list_backups_parametrized(
    ...
```

Code after:
    hass: HomeAssistant,
    hass_ws_client: WebSocketGenerator,
    mock_config_entry: MockConfigEntry,
    mock_client: MagicMock,
    test_backup: AgentBackup,
    config_entry_extra_data: dict,
    expected_paginate_extra_kwargs: dict,
) -> None:
    """Test agent list backups with and without prefix."""
    client = await hass_ws_client(hass)
    await client.send_json_auto_id({"type": "backup/info"})
    response = await client.receive_json()

    assert response["success"]
    assert response["result"]["agent_errors"] == {}

    # Verify pagination call with expected parameters
    mock_client.get_paginator.return_value.paginate.assert_called_with(
        **{"Bucket": "test"} | expected_paginate_extra_kwargs
    )


@pytest.mark.parametrize(
    ("config_entry_extra_data", "expected_key_prefix"),
    [
        ({"prefix": "backups/home"}, "backups/home/"),
        ({}, ""),
    ],
    ids=["with_prefix", "no_prefix"],
)
async def test_agent_delete_backup_parametrized(
    hass: HomeAssistant,
    hass_ws_client: WebSocketGenerator,
    mock_client: MagicMock,
    mock_config_entry: MockConfigEntry,
    test_backup: AgentBackup,
    expected_key_prefix: str,
) -> None:
    """Test agent delete backup with and without prefix."""
    client = await hass_ws_client(hass)

    await client.send_json_auto_id(
        {
            "type": "backup/delete",
            "backup_id": "23e64aec",
        }
    )
    response = await client.receive_json()

    assert response["success"]
    assert response["result"] == {"agent_errors": {}}