mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 09:17:53 +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."""
|
||||
|
||||
from collections.abc import AsyncGenerator, Generator
|
||||
from datetime import datetime
|
||||
from typing import Any
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
@ -18,11 +20,12 @@ from homeassistant.const import (
|
||||
CONF_URL,
|
||||
EVENT_HOMEASSISTANT_START,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def config_webhooks():
|
||||
def config_webhooks() -> dict[str, Any]:
|
||||
"""Fixture for a webhooks platform configuration."""
|
||||
return {
|
||||
DOMAIN: [
|
||||
@ -43,7 +46,7 @@ def config_webhooks():
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def config_polling():
|
||||
def config_polling() -> dict[str, Any]:
|
||||
"""Fixture for a polling platform configuration."""
|
||||
return {
|
||||
DOMAIN: [
|
||||
@ -62,7 +65,7 @@ def config_polling():
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_register_webhook():
|
||||
def mock_register_webhook() -> Generator[None]:
|
||||
"""Mock calls made by telegram_bot when (de)registering webhook."""
|
||||
with (
|
||||
patch(
|
||||
@ -78,7 +81,7 @@ def mock_register_webhook():
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_external_calls():
|
||||
def mock_external_calls() -> Generator[None]:
|
||||
"""Mock calls that make calls to the live Telegram API."""
|
||||
test_user = User(123456, "Testbot", True)
|
||||
message = Message(
|
||||
@ -109,7 +112,7 @@ def mock_external_calls():
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_generate_secret_token():
|
||||
def mock_generate_secret_token() -> Generator[str]:
|
||||
"""Mock secret token generated for webhook."""
|
||||
mock_secret_token = "DEADBEEF12345678DEADBEEF87654321"
|
||||
with patch(
|
||||
@ -217,12 +220,12 @@ def update_callback_query():
|
||||
|
||||
@pytest.fixture
|
||||
async def webhook_platform(
|
||||
hass,
|
||||
config_webhooks,
|
||||
mock_register_webhook,
|
||||
mock_external_calls,
|
||||
mock_generate_secret_token,
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
config_webhooks: dict[str, Any],
|
||||
mock_register_webhook: None,
|
||||
mock_external_calls: None,
|
||||
mock_generate_secret_token: str,
|
||||
) -> AsyncGenerator[None]:
|
||||
"""Fixture for setting up the webhooks platform using appropriate config and mocks."""
|
||||
await async_setup_component(
|
||||
hass,
|
||||
@ -235,7 +238,9 @@ async def webhook_platform(
|
||||
|
||||
|
||||
@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."""
|
||||
await async_setup_component(
|
||||
hass,
|
||||
|
Loading…
x
Reference in New Issue
Block a user