Add tests for Habitica integration (#131780)

* Add tests for Habitica integration

* update iqs
pull/133796/head
Manu 2024-12-17 09:07:18 +01:00 committed by GitHub
parent fc9d32ef65
commit 9ca9e787b2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 266 additions and 10 deletions

View File

@ -35,7 +35,7 @@ rules:
log-when-unavailable: done
parallel-updates: todo
reauthentication-flow: todo
test-coverage: todo
test-coverage: done
# Gold
devices: done

View File

@ -532,6 +532,56 @@
"updatedAt": "2024-07-07T17:51:53.266Z",
"userId": "5f359083-ef78-4af0-985a-0b2c6d05797c",
"id": "5e2ea1df-f6e6-4ba3-bccb-97c5ec63e99b"
},
{
"repeat": {
"m": false,
"t": false,
"w": false,
"th": false,
"f": false,
"s": false,
"su": true
},
"challenge": {},
"group": {
"completedBy": {},
"assignedUsers": []
},
"_id": "6e53f1f5-a315-4edd-984d-8d762e4a08ef",
"frequency": "monthly",
"everyX": 1,
"streak": 1,
"nextDue": [
"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"
],
"yesterDaily": true,
"history": [],
"completed": false,
"collapseChecklist": false,
"type": "daily",
"text": "Arbeite an einem kreativen Projekt",
"notes": "Klicke um den Namen Deines aktuellen Projekts anzugeben & setze einen Terminplan!",
"tags": [],
"value": -0.9215181434950852,
"priority": 1,
"attribute": "str",
"byHabitica": false,
"startDate": "2024-09-20T23:00:00.000Z",
"daysOfMonth": [],
"weeksOfMonth": [3],
"checklist": [],
"reminders": [],
"createdAt": "2024-10-10T15:57:14.304Z",
"updatedAt": "2024-11-27T23:47:29.986Z",
"userId": "5f359083-ef78-4af0-985a-0b2c6d05797c",
"isDue": false,
"id": "6e53f1f5-a315-4edd-984d-8d762e4a08ef"
}
],
"notifications": [

View File

@ -55,7 +55,8 @@
"e97659e0-2c42-4599-a7bb-00282adc410d",
"564b9ac9-c53d-4638-9e7f-1cd96fe19baa",
"f2c85972-1a19-4426-bc6d-ce3337b9d99f",
"2c6d136c-a1c3-4bef-b7c4-fa980784b1e1"
"2c6d136c-a1c3-4bef-b7c4-fa980784b1e1",
"6e53f1f5-a315-4edd-984d-8d762e4a08ef"
],
"habits": ["1d147de6-5c02-4740-8e2f-71d3015a37f4"]
},

View File

@ -1,5 +1,21 @@
# serializer version: 1
# name: test_api_events[calendar.test_user_dailies]
# name: test_api_events[date range in the past-calendar.test_user_dailies]
list([
])
# ---
# name: test_api_events[date range in the past-calendar.test_user_daily_reminders]
list([
])
# ---
# name: test_api_events[date range in the past-calendar.test_user_to_do_reminders]
list([
])
# ---
# name: test_api_events[date range in the past-calendar.test_user_to_do_s]
list([
])
# ---
# name: test_api_events[default date range-calendar.test_user_dailies]
list([
dict({
'description': 'Klicke um Deinen Terminplan festzulegen!',
@ -577,7 +593,7 @@
}),
])
# ---
# name: test_api_events[calendar.test_user_daily_reminders]
# name: test_api_events[default date range-calendar.test_user_daily_reminders]
list([
dict({
'description': 'Klicke um Deinen Terminplan festzulegen!',
@ -819,7 +835,7 @@
}),
])
# ---
# name: test_api_events[calendar.test_user_to_do_reminders]
# name: test_api_events[default date range-calendar.test_user_to_do_reminders]
list([
dict({
'description': 'Strom- und Internetrechnungen rechtzeitig überweisen.',
@ -837,7 +853,7 @@
}),
])
# ---
# name: test_api_events[calendar.test_user_to_do_s]
# name: test_api_events[default date range-calendar.test_user_to_do_s]
list([
dict({
'description': 'Strom- und Internetrechnungen rechtzeitig überweisen.',

View File

@ -615,6 +615,66 @@
'userId': '5f359083-ef78-4af0-985a-0b2c6d05797c',
'value': 10,
}),
dict({
'_id': '6e53f1f5-a315-4edd-984d-8d762e4a08ef',
'attribute': 'str',
'byHabitica': False,
'challenge': dict({
}),
'checklist': list([
]),
'collapseChecklist': False,
'completed': False,
'createdAt': '2024-10-10T15:57:14.304Z',
'daysOfMonth': list([
]),
'everyX': 1,
'frequency': 'monthly',
'group': dict({
'assignedUsers': list([
]),
'completedBy': dict({
}),
}),
'history': list([
]),
'id': '6e53f1f5-a315-4edd-984d-8d762e4a08ef',
'isDue': False,
'nextDue': 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',
]),
'notes': 'Klicke um den Namen Deines aktuellen Projekts anzugeben & setze einen Terminplan!',
'priority': 1,
'reminders': list([
]),
'repeat': dict({
'f': False,
'm': False,
's': False,
'su': True,
't': False,
'th': False,
'w': False,
}),
'startDate': '2024-09-20T23:00:00.000Z',
'streak': 1,
'tags': list([
]),
'text': 'Arbeite an einem kreativen Projekt',
'type': 'daily',
'updatedAt': '2024-11-27T23:47:29.986Z',
'userId': '5f359083-ef78-4af0-985a-0b2c6d05797c',
'value': -0.9215181434950852,
'weeksOfMonth': list([
3,
]),
'yesterDaily': True,
}),
]),
'user': dict({
'api_user': 'test-api-user',
@ -695,6 +755,7 @@
'564b9ac9-c53d-4638-9e7f-1cd96fe19baa',
'f2c85972-1a19-4426-bc6d-ce3337b9d99f',
'2c6d136c-a1c3-4bef-b7c4-fa980784b1e1',
'6e53f1f5-a315-4edd-984d-8d762e4a08ef',
]),
'habits': list([
'1d147de6-5c02-4740-8e2f-71d3015a37f4',

View File

@ -226,6 +226,45 @@
'value': -2.9663035443712333,
'yester_daily': True,
}),
'6e53f1f5-a315-4edd-984d-8d762e4a08ef': dict({
'created_at': '2024-10-10T15:57:14.304Z',
'every_x': 1,
'frequency': 'monthly',
'group': dict({
'assignedUsers': list([
]),
'completedBy': dict({
}),
}),
'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',
]),
'notes': 'Klicke um den Namen Deines aktuellen Projekts anzugeben & setze einen Terminplan!',
'priority': 1,
'repeat': dict({
'f': False,
'm': False,
's': False,
'su': True,
't': False,
'th': False,
'w': False,
}),
'start_date': '2024-09-20T23:00:00.000Z',
'streak': 1,
'text': 'Arbeite an einem kreativen Projekt',
'type': 'daily',
'value': -0.9215181434950852,
'weeks_of_month': list([
3,
]),
'yester_daily': True,
}),
'f2c85972-1a19-4426-bc6d-ce3337b9d99f': dict({
'created_at': '2024-07-07T17:51:53.266Z',
'every_x': 1,
@ -270,7 +309,7 @@
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '3',
'state': '4',
})
# ---
# name: test_sensors[sensor.test_user_display_name-entry]

View File

@ -42,6 +42,13 @@
'summary': 'Fitnessstudio besuchen',
'uid': '2c6d136c-a1c3-4bef-b7c4-fa980784b1e1',
}),
dict({
'description': 'Klicke um den Namen Deines aktuellen Projekts anzugeben & setze einen Terminplan!',
'due': '2024-12-14',
'status': 'needs_action',
'summary': 'Arbeite an einem kreativen Projekt',
'uid': '6e53f1f5-a315-4edd-984d-8d762e4a08ef',
}),
]),
}),
})
@ -137,7 +144,7 @@
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '2',
'state': '3',
})
# ---
# name: test_todos[todo.test_user_to_do_s-entry]

View File

@ -1,6 +1,7 @@
"""Tests for Habitica button platform."""
from collections.abc import Generator
from datetime import timedelta
from http import HTTPStatus
import re
from unittest.mock import patch
@ -15,10 +16,16 @@ from homeassistant.const import ATTR_ENTITY_ID, STATE_UNAVAILABLE, Platform
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 mock_called_with
from tests.common import MockConfigEntry, load_json_object_fixture, snapshot_platform
from tests.common import (
MockConfigEntry,
async_fire_time_changed,
load_json_object_fixture,
snapshot_platform,
)
from tests.test_util.aiohttp import AiohttpClientMocker
@ -340,3 +347,65 @@ async def test_button_unavailable(
for entity_id in entity_ids:
assert (state := hass.states.get(entity_id))
assert state.state == STATE_UNAVAILABLE
async def test_class_change(
hass: HomeAssistant,
config_entry: MockConfigEntry,
aioclient_mock: AiohttpClientMocker,
snapshot: SnapshotAssertion,
entity_registry: er.EntityRegistry,
) -> None:
"""Test removing and adding skills after class change."""
mage_skills = [
"button.test_user_chilling_frost",
"button.test_user_earthquake",
"button.test_user_ethereal_surge",
]
healer_skills = [
"button.test_user_healing_light",
"button.test_user_protective_aura",
"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),
)
config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
assert config_entry.state is ConfigEntryState.LOADED
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),
)
async_fire_time_changed(hass, dt_util.now() + timedelta(seconds=60))
await hass.async_block_till_done()
for skill in mage_skills:
assert not hass.states.get(skill)
for skill in healer_skills:
assert hass.states.get(skill)

View File

@ -59,6 +59,17 @@ async def test_calendar_platform(
"calendar.test_user_to_do_reminders",
],
)
@pytest.mark.parametrize(
("start_date", "end_date"),
[
("2024-08-29", "2024-10-08"),
("2023-08-01", "2023-08-02"),
],
ids=[
"default date range",
"date range in the past",
],
)
@pytest.mark.freeze_time("2024-09-20T22:00:00.000Z")
@pytest.mark.usefixtures("mock_habitica")
async def test_api_events(
@ -67,6 +78,8 @@ async def test_api_events(
config_entry: MockConfigEntry,
hass_client: ClientSessionGenerator,
entity: str,
start_date: str,
end_date: str,
) -> None:
"""Test calendar event."""
@ -76,7 +89,7 @@ async def test_api_events(
client = await hass_client()
response = await client.get(
f"/api/calendars/{entity}?start=2024-08-29&end=2024-10-08"
f"/api/calendars/{entity}?start={start_date}&end={end_date}"
)
assert await response.json() == snapshot