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
update tests
  • Loading branch information
tr4nt0r committed Dec 17, 2024
commit d8ce6e5d27fb6acb1913124af3c42002e019cccc
32 changes: 24 additions & 8 deletions tests/components/habitica/snapshots/test_sensor.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -259,22 +259,38 @@
'yester_daily': True,
}),
'6e53f1f5-a315-4edd-984d-8d762e4a08ef': dict({
'created_at': '2024-10-10T15:57:14.304Z',
'challenge': dict({
'broken': None,
'id': None,
'shortName': None,
'taskId': None,
'winner': None,
}),
'created_at': '2024-10-10T15:57:14.304000+00:00',
'every_x': 1,
'frequency': 'monthly',
'group': dict({
'assignedDate': None,
'assignedUsers': list([
]),
'assignedUsersDetail': dict({
}),
'assigningUsername': None,
'completedBy': dict({
'date': None,
'userId': None,
}),
'id': None,
'managerNotes': None,
'taskId': None,
}),
'next_due': list([
'2024-12-14T23:00:00.000Z',
'2025-01-18T23:00:00.000Z',
'2025-02-15T23:00:00.000Z',
'2025-03-15T23:00:00.000Z',
'2025-04-19T23:00:00.000Z',
'2025-05-17T23:00:00.000Z',
'2024-12-14T23:00:00+00:00',
'2025-01-18T23:00:00+00:00',
'2025-02-15T23:00:00+00:00',
'2025-03-15T23:00:00+00:00',
'2025-04-19T23:00:00+00:00',
'2025-05-17T23:00:00+00:00',
]),
'notes': 'Klicke um den Namen Deines aktuellen Projekts anzugeben & setze einen Terminplan!',
'priority': 1,
Expand All @@ -287,7 +303,7 @@
'th': False,
'w': False,
}),
'start_date': '2024-09-20T23:00:00.000Z',
'start_date': '2024-09-20T23:00:00+00:00',
'streak': 1,
'text': 'Arbeite an einem kreativen Projekt',
'type': 'daily',
Expand Down
38 changes: 10 additions & 28 deletions tests/components/habitica/test_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from collections.abc import Generator
from datetime import timedelta
import re
from unittest.mock import AsyncMock, patch

from freezegun.api import FrozenDateTimeFactory
from habiticalib import HabiticaUserResponse, Skill
import pytest
from syrupy.assertion import SnapshotAssertion
Expand All @@ -16,7 +16,6 @@
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
from homeassistant.helpers import entity_registry as er
import homeassistant.util.dt as dt_util

from .conftest import ERROR_BAD_REQUEST, ERROR_NOT_AUTHORIZED, ERROR_TOO_MANY_REQUESTS

Expand Down Expand Up @@ -333,9 +332,8 @@ async def test_button_unavailable(
async def test_class_change(
hass: HomeAssistant,
config_entry: MockConfigEntry,
aioclient_mock: AiohttpClientMocker,
snapshot: SnapshotAssertion,
entity_registry: er.EntityRegistry,
habitica: AsyncMock,
freezer: FrozenDateTimeFactory,
) -> None:
"""Test removing and adding skills after class change."""
mage_skills = [
Expand All @@ -349,23 +347,9 @@ async def test_class_change(
"button.test_user_searing_brightness",
"button.test_user_blessing",
]
aioclient_mock.get(
f"{DEFAULT_URL}/api/v3/user",
json=load_json_object_fixture("wizard_fixture.json", DOMAIN),
)
aioclient_mock.get(
f"{DEFAULT_URL}/api/v3/tasks/user",
params={"type": "completedTodos"},
json=load_json_object_fixture("completed_todos.json", DOMAIN),
)
aioclient_mock.get(
f"{DEFAULT_URL}/api/v3/tasks/user",
json=load_json_object_fixture("tasks.json", DOMAIN),
)
aioclient_mock.get(
f"{DEFAULT_URL}/api/v3/content",
params={"language": "en"},
json=load_json_object_fixture("content.json", DOMAIN),

habitica.get_user.return_value = HabiticaUserResponse.from_json(
load_fixture("wizard_fixture.json", DOMAIN)
)
config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(config_entry.entry_id)
Expand All @@ -376,13 +360,11 @@ async def test_class_change(
for skill in mage_skills:
assert hass.states.get(skill)

aioclient_mock._mocks.pop(0)
aioclient_mock.get(
f"{DEFAULT_URL}/api/v3/user",
json=load_json_object_fixture("healer_fixture.json", DOMAIN),
habitica.get_user.return_value = HabiticaUserResponse.from_json(
load_fixture("healer_fixture.json", DOMAIN)
)

async_fire_time_changed(hass, dt_util.now() + timedelta(seconds=60))
freezer.tick(timedelta(seconds=60))
async_fire_time_changed(hass)
await hass.async_block_till_done()

for skill in mage_skills:
Expand Down