Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate Habitica integration to habiticalib #131032

Merged
merged 27 commits into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
migrate init to habiticalib
  • Loading branch information
tr4nt0r committed Dec 17, 2024
commit e7681b69d981bff7d17f2a1ae956fedd6fee1fa0
2 changes: 1 addition & 1 deletion homeassistant/components/habitica/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def _make_headers(self) -> dict[str, str]:
hass, verify_ssl=config_entry.data.get(CONF_VERIFY_SSL, True)
)

# habitipy is still needed for the already deprecated api_call action
# habitipy is still needed for the deprecated api_call action
# but it will be removed in 2025.6.0
habitipy = await hass.async_add_executor_job(
HAHabitipyAsync,
Expand Down
12 changes: 8 additions & 4 deletions tests/components/habitica/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,14 @@ async def set_tz(hass: HomeAssistant) -> None:
async def mock_habiticalib() -> Generator[AsyncMock]:
"""Mock habiticalib."""

with patch(
"homeassistant.components.habitica.config_flow.Habitica",
autospec=True,
) as mock_client:
with (
patch(
"homeassistant.components.habitica.Habitica", autospec=True
) as mock_client,
patch(
"homeassistant.components.habitica.config_flow.Habitica", new=mock_client
),
):
client = mock_client.return_value

client.login.return_value = HabiticaLoginResponse.from_json(
Expand Down
23 changes: 14 additions & 9 deletions tests/components/habitica/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import datetime
from http import HTTPStatus
import logging
from unittest.mock import AsyncMock

from freezegun.api import FrozenDateTimeFactory
import pytest
Expand All @@ -20,6 +21,8 @@
from homeassistant.const import ATTR_NAME
from homeassistant.core import Event, HomeAssistant

from .conftest import ERROR_BAD_REQUEST, ERROR_NOT_AUTHORIZED, ERROR_TOO_MANY_REQUESTS

from tests.common import (
MockConfigEntry,
async_capture_events,
Expand All @@ -38,7 +41,7 @@ def capture_api_call_success(hass: HomeAssistant) -> list[Event]:
return async_capture_events(hass, EVENT_API_CALL_SUCCESS)


@pytest.mark.usefixtures("mock_habitica")
@pytest.mark.usefixtures("mock_habitica", "habitica")
async def test_entry_setup_unload(
hass: HomeAssistant, config_entry: MockConfigEntry
) -> None:
Expand Down Expand Up @@ -94,21 +97,23 @@ async def test_service_call(


@pytest.mark.parametrize(
("status"), [HTTPStatus.NOT_FOUND, HTTPStatus.TOO_MANY_REQUESTS]
("exception"),
[
ERROR_BAD_REQUEST,
ERROR_TOO_MANY_REQUESTS,
ERROR_NOT_AUTHORIZED,
],
ids=["BadRequestError", "TooManyRequestsError", "NotAuthorizedError"],
)
async def test_config_entry_not_ready(
hass: HomeAssistant,
config_entry: MockConfigEntry,
aioclient_mock: AiohttpClientMocker,
status: HTTPStatus,
habitica: AsyncMock,
exception: Exception,
) -> None:
"""Test config entry not ready."""

aioclient_mock.get(
f"{DEFAULT_URL}/api/v3/user",
status=status,
)

habitica.get_user.side_effect = exception
config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
Expand Down