Add tests for Habitica integration (#131780)
* Add tests for Habitica integration * update iqspull/133796/head
parent
fc9d32ef65
commit
9ca9e787b2
|
@ -35,7 +35,7 @@ rules:
|
||||||
log-when-unavailable: done
|
log-when-unavailable: done
|
||||||
parallel-updates: todo
|
parallel-updates: todo
|
||||||
reauthentication-flow: todo
|
reauthentication-flow: todo
|
||||||
test-coverage: todo
|
test-coverage: done
|
||||||
|
|
||||||
# Gold
|
# Gold
|
||||||
devices: done
|
devices: done
|
||||||
|
|
|
@ -532,6 +532,56 @@
|
||||||
"updatedAt": "2024-07-07T17:51:53.266Z",
|
"updatedAt": "2024-07-07T17:51:53.266Z",
|
||||||
"userId": "5f359083-ef78-4af0-985a-0b2c6d05797c",
|
"userId": "5f359083-ef78-4af0-985a-0b2c6d05797c",
|
||||||
"id": "5e2ea1df-f6e6-4ba3-bccb-97c5ec63e99b"
|
"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": [
|
"notifications": [
|
||||||
|
|
|
@ -55,7 +55,8 @@
|
||||||
"e97659e0-2c42-4599-a7bb-00282adc410d",
|
"e97659e0-2c42-4599-a7bb-00282adc410d",
|
||||||
"564b9ac9-c53d-4638-9e7f-1cd96fe19baa",
|
"564b9ac9-c53d-4638-9e7f-1cd96fe19baa",
|
||||||
"f2c85972-1a19-4426-bc6d-ce3337b9d99f",
|
"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"]
|
"habits": ["1d147de6-5c02-4740-8e2f-71d3015a37f4"]
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,5 +1,21 @@
|
||||||
# serializer version: 1
|
# 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([
|
list([
|
||||||
dict({
|
dict({
|
||||||
'description': 'Klicke um Deinen Terminplan festzulegen!',
|
'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([
|
list([
|
||||||
dict({
|
dict({
|
||||||
'description': 'Klicke um Deinen Terminplan festzulegen!',
|
'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([
|
list([
|
||||||
dict({
|
dict({
|
||||||
'description': 'Strom- und Internetrechnungen rechtzeitig überweisen.',
|
'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([
|
list([
|
||||||
dict({
|
dict({
|
||||||
'description': 'Strom- und Internetrechnungen rechtzeitig überweisen.',
|
'description': 'Strom- und Internetrechnungen rechtzeitig überweisen.',
|
||||||
|
|
|
@ -615,6 +615,66 @@
|
||||||
'userId': '5f359083-ef78-4af0-985a-0b2c6d05797c',
|
'userId': '5f359083-ef78-4af0-985a-0b2c6d05797c',
|
||||||
'value': 10,
|
'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({
|
'user': dict({
|
||||||
'api_user': 'test-api-user',
|
'api_user': 'test-api-user',
|
||||||
|
@ -695,6 +755,7 @@
|
||||||
'564b9ac9-c53d-4638-9e7f-1cd96fe19baa',
|
'564b9ac9-c53d-4638-9e7f-1cd96fe19baa',
|
||||||
'f2c85972-1a19-4426-bc6d-ce3337b9d99f',
|
'f2c85972-1a19-4426-bc6d-ce3337b9d99f',
|
||||||
'2c6d136c-a1c3-4bef-b7c4-fa980784b1e1',
|
'2c6d136c-a1c3-4bef-b7c4-fa980784b1e1',
|
||||||
|
'6e53f1f5-a315-4edd-984d-8d762e4a08ef',
|
||||||
]),
|
]),
|
||||||
'habits': list([
|
'habits': list([
|
||||||
'1d147de6-5c02-4740-8e2f-71d3015a37f4',
|
'1d147de6-5c02-4740-8e2f-71d3015a37f4',
|
||||||
|
|
|
@ -226,6 +226,45 @@
|
||||||
'value': -2.9663035443712333,
|
'value': -2.9663035443712333,
|
||||||
'yester_daily': True,
|
'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({
|
'f2c85972-1a19-4426-bc6d-ce3337b9d99f': dict({
|
||||||
'created_at': '2024-07-07T17:51:53.266Z',
|
'created_at': '2024-07-07T17:51:53.266Z',
|
||||||
'every_x': 1,
|
'every_x': 1,
|
||||||
|
@ -270,7 +309,7 @@
|
||||||
'last_changed': <ANY>,
|
'last_changed': <ANY>,
|
||||||
'last_reported': <ANY>,
|
'last_reported': <ANY>,
|
||||||
'last_updated': <ANY>,
|
'last_updated': <ANY>,
|
||||||
'state': '3',
|
'state': '4',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_sensors[sensor.test_user_display_name-entry]
|
# name: test_sensors[sensor.test_user_display_name-entry]
|
||||||
|
|
|
@ -42,6 +42,13 @@
|
||||||
'summary': 'Fitnessstudio besuchen',
|
'summary': 'Fitnessstudio besuchen',
|
||||||
'uid': '2c6d136c-a1c3-4bef-b7c4-fa980784b1e1',
|
'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_changed': <ANY>,
|
||||||
'last_reported': <ANY>,
|
'last_reported': <ANY>,
|
||||||
'last_updated': <ANY>,
|
'last_updated': <ANY>,
|
||||||
'state': '2',
|
'state': '3',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_todos[todo.test_user_to_do_s-entry]
|
# name: test_todos[todo.test_user_to_do_s-entry]
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
"""Tests for Habitica button platform."""
|
"""Tests for Habitica button platform."""
|
||||||
|
|
||||||
from collections.abc import Generator
|
from collections.abc import Generator
|
||||||
|
from datetime import timedelta
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
import re
|
import re
|
||||||
from unittest.mock import patch
|
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.core import HomeAssistant
|
||||||
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
from .conftest import mock_called_with
|
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
|
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||||
|
|
||||||
|
|
||||||
|
@ -340,3 +347,65 @@ async def test_button_unavailable(
|
||||||
for entity_id in entity_ids:
|
for entity_id in entity_ids:
|
||||||
assert (state := hass.states.get(entity_id))
|
assert (state := hass.states.get(entity_id))
|
||||||
assert state.state == STATE_UNAVAILABLE
|
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)
|
||||||
|
|
|
@ -59,6 +59,17 @@ async def test_calendar_platform(
|
||||||
"calendar.test_user_to_do_reminders",
|
"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.freeze_time("2024-09-20T22:00:00.000Z")
|
||||||
@pytest.mark.usefixtures("mock_habitica")
|
@pytest.mark.usefixtures("mock_habitica")
|
||||||
async def test_api_events(
|
async def test_api_events(
|
||||||
|
@ -67,6 +78,8 @@ async def test_api_events(
|
||||||
config_entry: MockConfigEntry,
|
config_entry: MockConfigEntry,
|
||||||
hass_client: ClientSessionGenerator,
|
hass_client: ClientSessionGenerator,
|
||||||
entity: str,
|
entity: str,
|
||||||
|
start_date: str,
|
||||||
|
end_date: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test calendar event."""
|
"""Test calendar event."""
|
||||||
|
|
||||||
|
@ -76,7 +89,7 @@ async def test_api_events(
|
||||||
|
|
||||||
client = await hass_client()
|
client = await hass_client()
|
||||||
response = await client.get(
|
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
|
assert await response.json() == snapshot
|
||||||
|
|
Loading…
Reference in New Issue