Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tr4nt0r committed Dec 17, 2024
1 parent 56a9869 commit d8ce6e5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 36 deletions.
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

0 comments on commit d8ce6e5

Please sign in to comment.