mirror of
https://github.com/home-assistant/core.git
synced 2025-11-09 10:59:40 +00:00
Rename S3 to AWS_S3 (#144324)
This commit is contained in:
75
tests/components/aws_s3/test_init.py
Normal file
75
tests/components/aws_s3/test_init.py
Normal file
@@ -0,0 +1,75 @@
|
||||
"""Test the AWS S3 storage integration."""
|
||||
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
from botocore.exceptions import (
|
||||
ClientError,
|
||||
EndpointConnectionError,
|
||||
ParamValidationError,
|
||||
)
|
||||
import pytest
|
||||
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import setup_integration
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_load_unload_config_entry(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test loading and unloading the integration."""
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
assert mock_config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
await hass.config_entries.async_unload(mock_config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert mock_config_entry.state is ConfigEntryState.NOT_LOADED
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("exception", "state"),
|
||||
[
|
||||
(
|
||||
ParamValidationError(report="Invalid bucket name"),
|
||||
ConfigEntryState.SETUP_ERROR,
|
||||
),
|
||||
(ValueError(), ConfigEntryState.SETUP_ERROR),
|
||||
(
|
||||
EndpointConnectionError(endpoint_url="https://example.com"),
|
||||
ConfigEntryState.SETUP_RETRY,
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_setup_entry_create_client_errors(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
exception: Exception,
|
||||
state: ConfigEntryState,
|
||||
) -> None:
|
||||
"""Test various setup errors."""
|
||||
with patch(
|
||||
"aiobotocore.session.AioSession.create_client",
|
||||
side_effect=exception,
|
||||
):
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
assert mock_config_entry.state is state
|
||||
|
||||
|
||||
async def test_setup_entry_head_bucket_error(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_client: AsyncMock,
|
||||
) -> None:
|
||||
"""Test setup_entry error when calling head_bucket."""
|
||||
mock_client.head_bucket.side_effect = ClientError(
|
||||
error_response={"Error": {"Code": "InvalidAccessKeyId"}},
|
||||
operation_name="head_bucket",
|
||||
)
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
assert mock_config_entry.state is ConfigEntryState.SETUP_ERROR
|
||||
Reference in New Issue
Block a user