mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Improve type hints in telegram_bot tests (#123914)
This commit is contained in:
parent
ccde51da85
commit
324b6529e8
@ -1,6 +1,8 @@
|
|||||||
"""Tests for the telegram_bot integration."""
|
"""Tests for the telegram_bot integration."""
|
||||||
|
|
||||||
|
from collections.abc import AsyncGenerator, Generator
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from typing import Any
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@ -18,11 +20,12 @@ from homeassistant.const import (
|
|||||||
CONF_URL,
|
CONF_URL,
|
||||||
EVENT_HOMEASSISTANT_START,
|
EVENT_HOMEASSISTANT_START,
|
||||||
)
|
)
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def config_webhooks():
|
def config_webhooks() -> dict[str, Any]:
|
||||||
"""Fixture for a webhooks platform configuration."""
|
"""Fixture for a webhooks platform configuration."""
|
||||||
return {
|
return {
|
||||||
DOMAIN: [
|
DOMAIN: [
|
||||||
@ -43,7 +46,7 @@ def config_webhooks():
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def config_polling():
|
def config_polling() -> dict[str, Any]:
|
||||||
"""Fixture for a polling platform configuration."""
|
"""Fixture for a polling platform configuration."""
|
||||||
return {
|
return {
|
||||||
DOMAIN: [
|
DOMAIN: [
|
||||||
@ -62,7 +65,7 @@ def config_polling():
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_register_webhook():
|
def mock_register_webhook() -> Generator[None]:
|
||||||
"""Mock calls made by telegram_bot when (de)registering webhook."""
|
"""Mock calls made by telegram_bot when (de)registering webhook."""
|
||||||
with (
|
with (
|
||||||
patch(
|
patch(
|
||||||
@ -78,7 +81,7 @@ def mock_register_webhook():
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_external_calls():
|
def mock_external_calls() -> Generator[None]:
|
||||||
"""Mock calls that make calls to the live Telegram API."""
|
"""Mock calls that make calls to the live Telegram API."""
|
||||||
test_user = User(123456, "Testbot", True)
|
test_user = User(123456, "Testbot", True)
|
||||||
message = Message(
|
message = Message(
|
||||||
@ -109,7 +112,7 @@ def mock_external_calls():
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_generate_secret_token():
|
def mock_generate_secret_token() -> Generator[str]:
|
||||||
"""Mock secret token generated for webhook."""
|
"""Mock secret token generated for webhook."""
|
||||||
mock_secret_token = "DEADBEEF12345678DEADBEEF87654321"
|
mock_secret_token = "DEADBEEF12345678DEADBEEF87654321"
|
||||||
with patch(
|
with patch(
|
||||||
@ -217,12 +220,12 @@ def update_callback_query():
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def webhook_platform(
|
async def webhook_platform(
|
||||||
hass,
|
hass: HomeAssistant,
|
||||||
config_webhooks,
|
config_webhooks: dict[str, Any],
|
||||||
mock_register_webhook,
|
mock_register_webhook: None,
|
||||||
mock_external_calls,
|
mock_external_calls: None,
|
||||||
mock_generate_secret_token,
|
mock_generate_secret_token: str,
|
||||||
):
|
) -> AsyncGenerator[None]:
|
||||||
"""Fixture for setting up the webhooks platform using appropriate config and mocks."""
|
"""Fixture for setting up the webhooks platform using appropriate config and mocks."""
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
@ -235,7 +238,9 @@ async def webhook_platform(
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def polling_platform(hass, config_polling, mock_external_calls):
|
async def polling_platform(
|
||||||
|
hass: HomeAssistant, config_polling: dict[str, Any], mock_external_calls: None
|
||||||
|
) -> None:
|
||||||
"""Fixture for setting up the polling platform using appropriate config and mocks."""
|
"""Fixture for setting up the polling platform using appropriate config and mocks."""
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user