Fix missing mock in islamic_prayer_times (#90178)

* Fix missing mock in islamic_prayer_times

* Restore 100% coverage

* Update test_config_flow.py
This commit is contained in:
epenet 2023-03-23 20:10:51 +01:00 committed by GitHub
parent 3e3ece4e56
commit 38a4f08e15
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 17 deletions

View file

@ -0,0 +1,15 @@
"""Common fixtures for the islamic_prayer_times tests."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch
import pytest
@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.islamic_prayer_times.async_setup_entry",
return_value=True,
) as mock_setup_entry:
yield mock_setup_entry

View file

@ -1,15 +1,15 @@
"""Tests for Islamic Prayer Times config flow."""
from unittest.mock import patch
import pytest
from homeassistant import config_entries, data_entry_flow
from homeassistant.components import islamic_prayer_times
from homeassistant.components.islamic_prayer_times.const import CONF_CALC_METHOD, DOMAIN
from homeassistant.core import HomeAssistant
from . import PRAYER_TIMES
from tests.common import MockConfigEntry
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
async def test_flow_works(hass: HomeAssistant) -> None:
"""Test user config."""
@ -19,13 +19,11 @@ async def test_flow_works(hass: HomeAssistant) -> None:
assert result["type"] == data_entry_flow.FlowResultType.FORM
assert result["step_id"] == "user"
with patch(
"homeassistant.components.islamic_prayer_times.async_setup_entry",
return_value=True,
):
result = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input={}
)
result = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input={}
)
await hass.async_block_till_done()
assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
assert result["title"] == "Islamic Prayer Times"
@ -40,13 +38,6 @@ async def test_options(hass: HomeAssistant) -> None:
)
entry.add_to_hass(hass)
with patch(
"prayer_times_calculator.PrayerTimesCalculator.fetch_prayer_times",
return_value=PRAYER_TIMES,
):
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
result = await hass.config_entries.options.async_init(entry.entry_id)
assert result["type"] == data_entry_flow.FlowResultType.FORM

View file

@ -8,6 +8,7 @@ import pytest
from homeassistant import config_entries
from homeassistant.components import islamic_prayer_times
from homeassistant.components.islamic_prayer_times.const import CONF_CALC_METHOD
from homeassistant.core import HomeAssistant
from . import (
@ -85,6 +86,26 @@ async def test_unload_entry(hass: HomeAssistant) -> None:
assert islamic_prayer_times.DOMAIN not in hass.data
async def test_options_listener(hass: HomeAssistant) -> None:
"""Ensure updating options triggers a coordinator refresh."""
entry = MockConfigEntry(domain=islamic_prayer_times.DOMAIN, data={})
entry.add_to_hass(hass)
with patch(
"prayer_times_calculator.PrayerTimesCalculator.fetch_prayer_times",
return_value=PRAYER_TIMES,
) as mock_fetch_prayer_times:
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert mock_fetch_prayer_times.call_count == 1
hass.config_entries.async_update_entry(
entry, options={CONF_CALC_METHOD: "makkah"}
)
await hass.async_block_till_done()
assert mock_fetch_prayer_times.call_count == 2
async def test_islamic_prayer_times_timestamp_format(hass: HomeAssistant) -> None:
"""Test Islamic prayer times timestamp format."""
entry = MockConfigEntry(domain=islamic_prayer_times.DOMAIN, data={})