Add tests for Habitica integration (#126445)
* Add tests for sensor platform * Add tests for switch platform * Add tests for button platform * Add tests for todo platform * Add tests for todo platform * Load json data fixtures * Update snapshot * Add fixtures * test move todo * parametrize todo tests, test drop notification * test todo exceptions * some minor improvements * test setup retry * Test update failed * Test coordinator rate limit * Test date utils * Reduce scope of PR * remove unused assert_mock_called_with function * update snapshot * Update tests/components/habitica/test_init.py --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
parent
e52b347b18
commit
8540343d7f
7 changed files with 1867 additions and 1 deletions
|
@ -4,6 +4,12 @@ from unittest.mock import patch
|
|||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.habitica.const import CONF_API_USER, DEFAULT_URL, DOMAIN
|
||||
from homeassistant.const import CONF_API_KEY, CONF_URL
|
||||
|
||||
from tests.common import MockConfigEntry, load_json_object_fixture
|
||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def disable_plumbum():
|
||||
|
@ -13,3 +19,38 @@ def disable_plumbum():
|
|||
"""
|
||||
with patch("plumbum.local"), patch("plumbum.colors"):
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_habitica(aioclient_mock: AiohttpClientMocker) -> AiohttpClientMocker:
|
||||
"""Mock aiohttp requests."""
|
||||
|
||||
aioclient_mock.get(
|
||||
f"{DEFAULT_URL}/api/v3/user", json=load_json_object_fixture("user.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),
|
||||
)
|
||||
|
||||
return aioclient_mock
|
||||
|
||||
|
||||
@pytest.fixture(name="config_entry")
|
||||
def mock_config_entry() -> MockConfigEntry:
|
||||
"""Mock Habitica configuration entry."""
|
||||
return MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
title="test-user",
|
||||
data={
|
||||
CONF_URL: DEFAULT_URL,
|
||||
CONF_API_USER: "test-api-user",
|
||||
CONF_API_KEY: "test-api-key",
|
||||
},
|
||||
unique_id="00000000-0000-0000-0000-000000000000",
|
||||
)
|
||||
|
|
78
tests/components/habitica/fixtures/completed_todos.json
Normal file
78
tests/components/habitica/fixtures/completed_todos.json
Normal file
|
@ -0,0 +1,78 @@
|
|||
{
|
||||
"success": true,
|
||||
"data": [
|
||||
{
|
||||
"_id": "162f0bbe-a097-4a06-b4f4-8fbeed85d2ba",
|
||||
"completed": true,
|
||||
"collapseChecklist": false,
|
||||
"checklist": [],
|
||||
"type": "todo",
|
||||
"text": "Wocheneinkauf erledigen",
|
||||
"notes": "Lebensmittel und Haushaltsbedarf für die Woche einkaufen.",
|
||||
"tags": ["64235347-55d0-4ba1-a86a-3428dcfdf319"],
|
||||
"value": 1,
|
||||
"priority": 1.5,
|
||||
"attribute": "str",
|
||||
"challenge": {},
|
||||
"group": {
|
||||
"completedBy": {},
|
||||
"assignedUsers": []
|
||||
},
|
||||
"reminders": [],
|
||||
"byHabitica": false,
|
||||
"createdAt": "2024-09-21T22:19:10.919Z",
|
||||
"updatedAt": "2024-09-21T22:19:15.484Z",
|
||||
"userId": "5f359083-ef78-4af0-985a-0b2c6d05797c",
|
||||
"dateCompleted": "2024-09-21T22:19:15.478Z",
|
||||
"id": "162f0bbe-a097-4a06-b4f4-8fbeed85d2ba"
|
||||
},
|
||||
{
|
||||
"_id": "3fa06743-aa0f-472b-af1a-f27c755e329c",
|
||||
"completed": true,
|
||||
"collapseChecklist": false,
|
||||
"checklist": [],
|
||||
"type": "todo",
|
||||
"text": "Wohnung aufräumen",
|
||||
"notes": "Wohnzimmer und Küche gründlich aufräumen.",
|
||||
"tags": ["64235347-55d0-4ba1-a86a-3428dcfdf319"],
|
||||
"value": 1,
|
||||
"priority": 2,
|
||||
"attribute": "str",
|
||||
"challenge": {},
|
||||
"group": {
|
||||
"completedBy": {},
|
||||
"assignedUsers": []
|
||||
},
|
||||
"reminders": [],
|
||||
"byHabitica": false,
|
||||
"createdAt": "2024-09-21T22:18:30.646Z",
|
||||
"updatedAt": "2024-09-21T22:18:34.663Z",
|
||||
"userId": "5f359083-ef78-4af0-985a-0b2c6d05797c",
|
||||
"dateCompleted": "2024-09-21T22:18:34.660Z",
|
||||
"id": "3fa06743-aa0f-472b-af1a-f27c755e329c"
|
||||
}
|
||||
],
|
||||
"notifications": [
|
||||
{
|
||||
"type": "ITEM_RECEIVED",
|
||||
"data": {
|
||||
"icon": "notif_orca_mount",
|
||||
"title": "Orcas for Summer Splash!",
|
||||
"text": "To celebrate Summer Splash, we've given you an Orca Mount!",
|
||||
"destination": "stable"
|
||||
},
|
||||
"seen": true,
|
||||
"id": "b7a85df1-06ed-4ab1-b56d-43418fc6a5e5"
|
||||
},
|
||||
{
|
||||
"type": "UNALLOCATED_STATS_POINTS",
|
||||
"data": {
|
||||
"points": 2
|
||||
},
|
||||
"seen": true,
|
||||
"id": "bc3f8a69-231f-4eb1-ba48-a00b6c0e0f37"
|
||||
}
|
||||
],
|
||||
"userV": 584,
|
||||
"appVersion": "5.28.6"
|
||||
}
|
548
tests/components/habitica/fixtures/tasks.json
Normal file
548
tests/components/habitica/fixtures/tasks.json
Normal file
|
@ -0,0 +1,548 @@
|
|||
{
|
||||
"success": true,
|
||||
"data": [
|
||||
{
|
||||
"_id": "f21fa608-cfc6-4413-9fc7-0eb1b48ca43a",
|
||||
"up": true,
|
||||
"down": true,
|
||||
"counterUp": 0,
|
||||
"counterDown": 0,
|
||||
"frequency": "daily",
|
||||
"history": [],
|
||||
"type": "habit",
|
||||
"text": "Gesundes Essen/Junkfood",
|
||||
"notes": "",
|
||||
"tags": [],
|
||||
"value": 0,
|
||||
"priority": 1,
|
||||
"attribute": "str",
|
||||
"challenge": {},
|
||||
"group": {
|
||||
"completedBy": {},
|
||||
"assignedUsers": []
|
||||
},
|
||||
"byHabitica": false,
|
||||
"reminders": [],
|
||||
"createdAt": "2024-07-07T17:51:53.268Z",
|
||||
"updatedAt": "2024-07-07T17:51:53.268Z",
|
||||
"userId": "5f359083-ef78-4af0-985a-0b2c6d05797c",
|
||||
"id": "f21fa608-cfc6-4413-9fc7-0eb1b48ca43a"
|
||||
},
|
||||
{
|
||||
"_id": "1d147de6-5c02-4740-8e2f-71d3015a37f4",
|
||||
"up": true,
|
||||
"down": false,
|
||||
"counterUp": 0,
|
||||
"counterDown": 0,
|
||||
"frequency": "daily",
|
||||
"history": [
|
||||
{
|
||||
"date": 1720376763324,
|
||||
"value": 1,
|
||||
"scoredUp": 1,
|
||||
"scoredDown": 0
|
||||
}
|
||||
],
|
||||
"type": "habit",
|
||||
"text": "Eine kurze Pause machen",
|
||||
"notes": "",
|
||||
"tags": [],
|
||||
"value": 0,
|
||||
"priority": 1,
|
||||
"attribute": "str",
|
||||
"challenge": {},
|
||||
"group": {
|
||||
"completedBy": {},
|
||||
"assignedUsers": []
|
||||
},
|
||||
"byHabitica": false,
|
||||
"reminders": [],
|
||||
"createdAt": "2024-07-07T17:51:53.266Z",
|
||||
"updatedAt": "2024-07-12T09:58:45.438Z",
|
||||
"userId": "5f359083-ef78-4af0-985a-0b2c6d05797c",
|
||||
"id": "1d147de6-5c02-4740-8e2f-71d3015a37f4"
|
||||
},
|
||||
{
|
||||
"_id": "bc1d1855-b2b8-4663-98ff-62e7b763dfc4",
|
||||
"up": false,
|
||||
"down": true,
|
||||
"counterUp": 0,
|
||||
"counterDown": 0,
|
||||
"frequency": "daily",
|
||||
"history": [],
|
||||
"type": "habit",
|
||||
"text": "Klicke hier um dies als schlechte Gewohnheit zu markieren, die Du gerne loswerden möchtest",
|
||||
"notes": "Oder lösche es über die Bearbeitungs-Ansicht",
|
||||
"tags": [],
|
||||
"value": 0,
|
||||
"priority": 1,
|
||||
"attribute": "str",
|
||||
"challenge": {},
|
||||
"group": {
|
||||
"completedBy": {},
|
||||
"assignedUsers": []
|
||||
},
|
||||
"byHabitica": false,
|
||||
"reminders": [],
|
||||
"createdAt": "2024-07-07T17:51:53.265Z",
|
||||
"updatedAt": "2024-07-07T17:51:53.265Z",
|
||||
"userId": "5f359083-ef78-4af0-985a-0b2c6d05797c",
|
||||
"id": "bc1d1855-b2b8-4663-98ff-62e7b763dfc4"
|
||||
},
|
||||
{
|
||||
"_id": "e97659e0-2c42-4599-a7bb-00282adc410d",
|
||||
"up": true,
|
||||
"down": false,
|
||||
"counterUp": 0,
|
||||
"counterDown": 0,
|
||||
"frequency": "daily",
|
||||
"history": [
|
||||
{
|
||||
"date": 1720376763140,
|
||||
"value": 1,
|
||||
"scoredUp": 1,
|
||||
"scoredDown": 0
|
||||
}
|
||||
],
|
||||
"type": "habit",
|
||||
"text": "Füge eine Aufgabe zu Habitica hinzu",
|
||||
"notes": "Eine Gewohnheit, eine Tagesaufgabe oder ein To-Do",
|
||||
"tags": [],
|
||||
"value": 0,
|
||||
"priority": 1,
|
||||
"attribute": "str",
|
||||
"challenge": {},
|
||||
"group": {
|
||||
"completedBy": {},
|
||||
"assignedUsers": []
|
||||
},
|
||||
"byHabitica": false,
|
||||
"reminders": [],
|
||||
"createdAt": "2024-07-07T17:51:53.264Z",
|
||||
"updatedAt": "2024-07-12T09:58:45.438Z",
|
||||
"userId": "5f359083-ef78-4af0-985a-0b2c6d05797c",
|
||||
"id": "e97659e0-2c42-4599-a7bb-00282adc410d"
|
||||
},
|
||||
{
|
||||
"_id": "564b9ac9-c53d-4638-9e7f-1cd96fe19baa",
|
||||
"frequency": "weekly",
|
||||
"everyX": 1,
|
||||
"repeat": {
|
||||
"m": true,
|
||||
"t": true,
|
||||
"w": true,
|
||||
"th": true,
|
||||
"f": true,
|
||||
"s": true,
|
||||
"su": true
|
||||
},
|
||||
"streak": 1,
|
||||
"nextDue": [
|
||||
"Mon Sep 23 2024 00:00:00 GMT+0200",
|
||||
"Tue Sep 24 2024 00:00:00 GMT+0200",
|
||||
"Wed Sep 25 2024 00:00:00 GMT+0200",
|
||||
"Thu Sep 26 2024 00:00:00 GMT+0200",
|
||||
"Fri Sep 27 2024 00:00:00 GMT+0200",
|
||||
"Sat Sep 28 2024 00:00:00 GMT+0200"
|
||||
],
|
||||
"yesterDaily": true,
|
||||
"history": [
|
||||
{
|
||||
"date": 1720376766749,
|
||||
"value": 1,
|
||||
"isDue": true,
|
||||
"completed": true
|
||||
},
|
||||
{
|
||||
"date": 1720545311292,
|
||||
"value": 0.02529999999999999,
|
||||
"isDue": true,
|
||||
"completed": false
|
||||
},
|
||||
{
|
||||
"date": 1720564306719,
|
||||
"value": -0.9740518837628547,
|
||||
"isDue": true,
|
||||
"completed": false
|
||||
},
|
||||
{
|
||||
"date": 1720691096907,
|
||||
"value": 0.051222853419153,
|
||||
"isDue": true,
|
||||
"completed": true
|
||||
},
|
||||
{
|
||||
"date": 1720778325243,
|
||||
"value": 1.0499115128458676,
|
||||
"isDue": true,
|
||||
"completed": true
|
||||
},
|
||||
{
|
||||
"date": 1724185196447,
|
||||
"value": 0.07645736684721605,
|
||||
"isDue": true,
|
||||
"completed": false
|
||||
},
|
||||
{
|
||||
"date": 1724255707692,
|
||||
"value": -0.921585289356988,
|
||||
"isDue": true,
|
||||
"completed": false
|
||||
},
|
||||
{
|
||||
"date": 1726846163640,
|
||||
"value": -1.9454824860630637,
|
||||
"isDue": true,
|
||||
"completed": false
|
||||
},
|
||||
{
|
||||
"date": 1726953787542,
|
||||
"value": -2.9966001649571803,
|
||||
"isDue": true,
|
||||
"completed": false
|
||||
},
|
||||
{
|
||||
"date": 1726956115608,
|
||||
"value": -4.07641493832036,
|
||||
"isDue": true,
|
||||
"completed": false
|
||||
},
|
||||
{
|
||||
"date": 1726957460150,
|
||||
"value": -2.9663035443712333,
|
||||
"isDue": true,
|
||||
"completed": true
|
||||
}
|
||||
],
|
||||
"completed": true,
|
||||
"collapseChecklist": false,
|
||||
"type": "daily",
|
||||
"text": "Zahnseide benutzen",
|
||||
"notes": "Klicke um Änderungen zu machen!",
|
||||
"tags": [],
|
||||
"value": -2.9663035443712333,
|
||||
"priority": 1,
|
||||
"attribute": "str",
|
||||
"challenge": {},
|
||||
"group": {
|
||||
"completedBy": {},
|
||||
"assignedUsers": []
|
||||
},
|
||||
"byHabitica": false,
|
||||
"startDate": "2024-07-06T22:00:00.000Z",
|
||||
"daysOfMonth": [],
|
||||
"weeksOfMonth": [],
|
||||
"checklist": [],
|
||||
"reminders": [],
|
||||
"createdAt": "2024-07-07T17:51:53.268Z",
|
||||
"updatedAt": "2024-09-21T22:24:20.154Z",
|
||||
"userId": "5f359083-ef78-4af0-985a-0b2c6d05797c",
|
||||
"isDue": true,
|
||||
"id": "564b9ac9-c53d-4638-9e7f-1cd96fe19baa"
|
||||
},
|
||||
{
|
||||
"_id": "f2c85972-1a19-4426-bc6d-ce3337b9d99f",
|
||||
"frequency": "weekly",
|
||||
"everyX": 1,
|
||||
"repeat": {
|
||||
"m": true,
|
||||
"t": true,
|
||||
"w": true,
|
||||
"th": true,
|
||||
"f": true,
|
||||
"s": true,
|
||||
"su": true
|
||||
},
|
||||
"streak": 0,
|
||||
"nextDue": [
|
||||
"2024-09-22T22:00:00.000Z",
|
||||
"2024-09-23T22:00:00.000Z",
|
||||
"2024-09-24T22:00:00.000Z",
|
||||
"2024-09-25T22:00:00.000Z",
|
||||
"2024-09-26T22:00:00.000Z",
|
||||
"2024-09-27T22:00:00.000Z"
|
||||
],
|
||||
"yesterDaily": true,
|
||||
"history": [
|
||||
{
|
||||
"date": 1720374903074,
|
||||
"value": 1,
|
||||
"isDue": true,
|
||||
"completed": true
|
||||
},
|
||||
{
|
||||
"date": 1720545311291,
|
||||
"value": 0.02529999999999999,
|
||||
"isDue": true,
|
||||
"completed": false
|
||||
},
|
||||
{
|
||||
"date": 1720564306717,
|
||||
"value": -0.9740518837628547,
|
||||
"isDue": true,
|
||||
"completed": false
|
||||
},
|
||||
{
|
||||
"date": 1720682459722,
|
||||
"value": 0.051222853419153,
|
||||
"isDue": true,
|
||||
"completed": true
|
||||
},
|
||||
{
|
||||
"date": 1720778325246,
|
||||
"value": 1.0499115128458676,
|
||||
"isDue": true,
|
||||
"completed": true
|
||||
},
|
||||
{
|
||||
"date": 1720778492219,
|
||||
"value": 2.023365658844519,
|
||||
"isDue": true,
|
||||
"completed": true
|
||||
},
|
||||
{
|
||||
"date": 1724255707691,
|
||||
"value": 1.0738942424964806,
|
||||
"isDue": true,
|
||||
"completed": false
|
||||
},
|
||||
{
|
||||
"date": 1726846163638,
|
||||
"value": 0.10103816898038132,
|
||||
"isDue": true,
|
||||
"completed": false
|
||||
},
|
||||
{
|
||||
"date": 1726953787540,
|
||||
"value": -0.8963760215867302,
|
||||
"isDue": true,
|
||||
"completed": false
|
||||
},
|
||||
{
|
||||
"date": 1726956115607,
|
||||
"value": -1.919611992979862,
|
||||
"isDue": true,
|
||||
"completed": false
|
||||
}
|
||||
],
|
||||
"completed": false,
|
||||
"collapseChecklist": false,
|
||||
"type": "daily",
|
||||
"text": "5 Minuten ruhig durchatmen",
|
||||
"notes": "Klicke um Deinen Terminplan festzulegen!",
|
||||
"tags": [],
|
||||
"value": -1.919611992979862,
|
||||
"priority": 1,
|
||||
"attribute": "str",
|
||||
"challenge": {},
|
||||
"group": {
|
||||
"completedBy": {},
|
||||
"assignedUsers": []
|
||||
},
|
||||
"byHabitica": false,
|
||||
"startDate": "2024-07-06T22:00:00.000Z",
|
||||
"daysOfMonth": [],
|
||||
"weeksOfMonth": [],
|
||||
"checklist": [],
|
||||
"reminders": [],
|
||||
"createdAt": "2024-07-07T17:51:53.266Z",
|
||||
"updatedAt": "2024-09-21T22:51:41.756Z",
|
||||
"userId": "5f359083-ef78-4af0-985a-0b2c6d05797c",
|
||||
"isDue": true,
|
||||
"id": "f2c85972-1a19-4426-bc6d-ce3337b9d99f"
|
||||
},
|
||||
{
|
||||
"_id": "2c6d136c-a1c3-4bef-b7c4-fa980784b1e1",
|
||||
"frequency": "weekly",
|
||||
"everyX": 1,
|
||||
"startDate": "2024-09-21T22:00:00.000Z",
|
||||
"repeat": {
|
||||
"m": false,
|
||||
"t": false,
|
||||
"w": true,
|
||||
"th": false,
|
||||
"f": false,
|
||||
"s": true,
|
||||
"su": true
|
||||
},
|
||||
"streak": 0,
|
||||
"daysOfMonth": [],
|
||||
"weeksOfMonth": [],
|
||||
"nextDue": [
|
||||
"2024-09-24T22:00:00.000Z",
|
||||
"2024-09-27T22:00:00.000Z",
|
||||
"2024-09-28T22:00:00.000Z",
|
||||
"2024-10-01T22:00:00.000Z",
|
||||
"2024-10-04T22:00:00.000Z",
|
||||
"2024-10-08T22:00:00.000Z"
|
||||
],
|
||||
"yesterDaily": true,
|
||||
"history": [],
|
||||
"completed": false,
|
||||
"collapseChecklist": false,
|
||||
"checklist": [],
|
||||
"type": "daily",
|
||||
"text": "Fitnessstudio besuchen",
|
||||
"notes": "Ein einstündiges Workout im Fitnessstudio absolvieren.",
|
||||
"tags": ["51076966-2970-4b40-b6ba-d58c6a756dd7"],
|
||||
"value": 0,
|
||||
"priority": 2,
|
||||
"attribute": "str",
|
||||
"challenge": {},
|
||||
"group": {
|
||||
"completedBy": {},
|
||||
"assignedUsers": []
|
||||
},
|
||||
"reminders": [],
|
||||
"byHabitica": false,
|
||||
"createdAt": "2024-09-22T11:44:43.774Z",
|
||||
"updatedAt": "2024-09-22T11:44:43.774Z",
|
||||
"userId": "1343a9af-d891-4027-841a-956d105ca408",
|
||||
"isDue": true,
|
||||
"id": "2c6d136c-a1c3-4bef-b7c4-fa980784b1e1"
|
||||
},
|
||||
{
|
||||
"_id": "88de7cd9-af2b-49ce-9afd-bf941d87336b",
|
||||
"date": "2024-09-27T22:17:00.000Z",
|
||||
"completed": false,
|
||||
"collapseChecklist": false,
|
||||
"checklist": [],
|
||||
"type": "todo",
|
||||
"text": "Buch zu Ende lesen",
|
||||
"notes": "Das Buch, das du angefangen hast, bis zum Wochenende fertig lesen.",
|
||||
"tags": [],
|
||||
"value": 0,
|
||||
"priority": 1,
|
||||
"attribute": "str",
|
||||
"challenge": {},
|
||||
"group": {
|
||||
"completedBy": {},
|
||||
"assignedUsers": []
|
||||
},
|
||||
"reminders": [],
|
||||
"byHabitica": false,
|
||||
"createdAt": "2024-09-21T22:17:57.816Z",
|
||||
"updatedAt": "2024-09-21T22:17:57.816Z",
|
||||
"userId": "5f359083-ef78-4af0-985a-0b2c6d05797c",
|
||||
"id": "88de7cd9-af2b-49ce-9afd-bf941d87336b"
|
||||
},
|
||||
{
|
||||
"_id": "2f6fcabc-f670-4ec3-ba65-817e8deea490",
|
||||
"date": "2024-08-31T22:16:00.000Z",
|
||||
"completed": false,
|
||||
"collapseChecklist": false,
|
||||
"checklist": [],
|
||||
"type": "todo",
|
||||
"text": "Rechnungen bezahlen",
|
||||
"notes": "Strom- und Internetrechnungen rechtzeitig überweisen.",
|
||||
"tags": [],
|
||||
"value": 0,
|
||||
"priority": 1,
|
||||
"attribute": "str",
|
||||
"challenge": {},
|
||||
"group": {
|
||||
"completedBy": {},
|
||||
"assignedUsers": []
|
||||
},
|
||||
"reminders": [],
|
||||
"byHabitica": false,
|
||||
"createdAt": "2024-09-21T22:17:19.513Z",
|
||||
"updatedAt": "2024-09-21T22:19:35.576Z",
|
||||
"userId": "5f359083-ef78-4af0-985a-0b2c6d05797c",
|
||||
"id": "2f6fcabc-f670-4ec3-ba65-817e8deea490"
|
||||
},
|
||||
{
|
||||
"_id": "1aa3137e-ef72-4d1f-91ee-41933602f438",
|
||||
"completed": false,
|
||||
"collapseChecklist": false,
|
||||
"checklist": [],
|
||||
"type": "todo",
|
||||
"text": "Garten pflegen",
|
||||
"notes": "Rasen mähen und die Pflanzen gießen.",
|
||||
"tags": [],
|
||||
"value": 0,
|
||||
"priority": 1,
|
||||
"attribute": "str",
|
||||
"challenge": {},
|
||||
"group": {
|
||||
"completedBy": {},
|
||||
"assignedUsers": []
|
||||
},
|
||||
"reminders": [],
|
||||
"byHabitica": false,
|
||||
"createdAt": "2024-09-21T22:16:38.153Z",
|
||||
"updatedAt": "2024-09-21T22:16:38.153Z",
|
||||
"userId": "5f359083-ef78-4af0-985a-0b2c6d05797c",
|
||||
"id": "1aa3137e-ef72-4d1f-91ee-41933602f438"
|
||||
},
|
||||
{
|
||||
"_id": "86ea2475-d1b5-4020-bdcc-c188c7996afa",
|
||||
"date": "2024-09-26T22:15:00.000Z",
|
||||
"completed": false,
|
||||
"collapseChecklist": false,
|
||||
"checklist": [],
|
||||
"type": "todo",
|
||||
"text": "Wochenendausflug planen",
|
||||
"notes": "Den Ausflug für das kommende Wochenende organisieren.",
|
||||
"tags": ["51076966-2970-4b40-b6ba-d58c6a756dd7"],
|
||||
"value": 0,
|
||||
"priority": 1,
|
||||
"attribute": "str",
|
||||
"challenge": {},
|
||||
"group": {
|
||||
"completedBy": {},
|
||||
"assignedUsers": []
|
||||
},
|
||||
"reminders": [],
|
||||
"byHabitica": false,
|
||||
"createdAt": "2024-09-21T22:16:16.756Z",
|
||||
"updatedAt": "2024-09-21T22:16:16.756Z",
|
||||
"userId": "5f359083-ef78-4af0-985a-0b2c6d05797c",
|
||||
"id": "86ea2475-d1b5-4020-bdcc-c188c7996afa"
|
||||
},
|
||||
{
|
||||
"_id": "5e2ea1df-f6e6-4ba3-bccb-97c5ec63e99b",
|
||||
"type": "reward",
|
||||
"text": "Belohne Dich selbst",
|
||||
"notes": "Schaue fern, spiele ein Spiel, gönne Dir einen Leckerbissen, es liegt ganz bei Dir!",
|
||||
"tags": [],
|
||||
"value": 10,
|
||||
"priority": 1,
|
||||
"attribute": "str",
|
||||
"challenge": {},
|
||||
"group": {
|
||||
"completedBy": {},
|
||||
"assignedUsers": []
|
||||
},
|
||||
"byHabitica": false,
|
||||
"reminders": [],
|
||||
"createdAt": "2024-07-07T17:51:53.266Z",
|
||||
"updatedAt": "2024-07-07T17:51:53.266Z",
|
||||
"userId": "5f359083-ef78-4af0-985a-0b2c6d05797c",
|
||||
"id": "5e2ea1df-f6e6-4ba3-bccb-97c5ec63e99b"
|
||||
}
|
||||
],
|
||||
"notifications": [
|
||||
{
|
||||
"type": "ITEM_RECEIVED",
|
||||
"data": {
|
||||
"icon": "notif_orca_mount",
|
||||
"title": "Orcas for Summer Splash!",
|
||||
"text": "To celebrate Summer Splash, we've given you an Orca Mount!",
|
||||
"destination": "stable"
|
||||
},
|
||||
"seen": true,
|
||||
"id": "b7a85df1-06ed-4ab1-b56d-43418fc6a5e5"
|
||||
},
|
||||
{
|
||||
"type": "UNALLOCATED_STATS_POINTS",
|
||||
"data": {
|
||||
"points": 2
|
||||
},
|
||||
"seen": true,
|
||||
"id": "bc3f8a69-231f-4eb1-ba48-a00b6c0e0f37"
|
||||
}
|
||||
],
|
||||
"userV": 589,
|
||||
"appVersion": "5.28.6"
|
||||
}
|
24
tests/components/habitica/fixtures/user.json
Normal file
24
tests/components/habitica/fixtures/user.json
Normal file
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"data": {
|
||||
"api_user": "test-api-user",
|
||||
"profile": { "name": "test-user" },
|
||||
"stats": {
|
||||
"hp": 0,
|
||||
"mp": 50.89999999999998,
|
||||
"exp": 737,
|
||||
"gp": 137.62587214609795,
|
||||
"lvl": 38,
|
||||
"class": "wizard",
|
||||
"maxHealth": 50,
|
||||
"maxMP": 166,
|
||||
"toNextLevel": 880,
|
||||
"points": 5
|
||||
},
|
||||
"preferences": {
|
||||
"sleep": false,
|
||||
"automaticAllocation": true
|
||||
},
|
||||
"needsCron": true,
|
||||
"lastCron": "2024-09-21T22:01:55.586Z"
|
||||
}
|
||||
}
|
1019
tests/components/habitica/snapshots/test_sensor.ambr
Normal file
1019
tests/components/habitica/snapshots/test_sensor.ambr
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,7 +1,10 @@
|
|||
"""Test the habitica module."""
|
||||
|
||||
import datetime
|
||||
from http import HTTPStatus
|
||||
import logging
|
||||
|
||||
from freezegun.api import FrozenDateTimeFactory
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.habitica.const import (
|
||||
|
@ -13,10 +16,16 @@ from homeassistant.components.habitica.const import (
|
|||
EVENT_API_CALL_SUCCESS,
|
||||
SERVICE_API_CALL,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.const import ATTR_NAME
|
||||
from homeassistant.core import Event, HomeAssistant
|
||||
|
||||
from tests.common import MockConfigEntry, async_capture_events
|
||||
from tests.common import (
|
||||
MockConfigEntry,
|
||||
async_capture_events,
|
||||
async_fire_time_changed,
|
||||
load_json_object_fixture,
|
||||
)
|
||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||
|
||||
TEST_API_CALL_ARGS = {"text": "Use API from Home Assistant", "type": "todo"}
|
||||
|
@ -160,3 +169,78 @@ async def test_service_call(
|
|||
assert await hass.config_entries.async_unload(habitica_entry.entry_id)
|
||||
|
||||
assert not hass.services.has_service(DOMAIN, SERVICE_API_CALL)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("status"), [HTTPStatus.NOT_FOUND, HTTPStatus.TOO_MANY_REQUESTS]
|
||||
)
|
||||
async def test_config_entry_not_ready(
|
||||
hass: HomeAssistant,
|
||||
config_entry: MockConfigEntry,
|
||||
aioclient_mock: AiohttpClientMocker,
|
||||
status: HTTPStatus,
|
||||
) -> None:
|
||||
"""Test config entry not ready."""
|
||||
|
||||
aioclient_mock.get(
|
||||
f"{DEFAULT_URL}/api/v3/user",
|
||||
status=status,
|
||||
)
|
||||
|
||||
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.SETUP_RETRY
|
||||
|
||||
|
||||
async def test_coordinator_update_failed(
|
||||
hass: HomeAssistant,
|
||||
config_entry: MockConfigEntry,
|
||||
aioclient_mock: AiohttpClientMocker,
|
||||
) -> None:
|
||||
"""Test coordinator update failed."""
|
||||
|
||||
aioclient_mock.get(
|
||||
f"{DEFAULT_URL}/api/v3/user",
|
||||
json=load_json_object_fixture("user.json", DOMAIN),
|
||||
)
|
||||
aioclient_mock.get(
|
||||
f"{DEFAULT_URL}/api/v3/tasks/user",
|
||||
status=HTTPStatus.NOT_FOUND,
|
||||
)
|
||||
|
||||
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.SETUP_RETRY
|
||||
|
||||
|
||||
async def test_coordinator_rate_limited(
|
||||
hass: HomeAssistant,
|
||||
config_entry: MockConfigEntry,
|
||||
mock_habitica: AiohttpClientMocker,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
) -> None:
|
||||
"""Test coordinator when rate limited."""
|
||||
|
||||
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
|
||||
|
||||
mock_habitica.clear_requests()
|
||||
mock_habitica.get(
|
||||
f"{DEFAULT_URL}/api/v3/user",
|
||||
status=HTTPStatus.TOO_MANY_REQUESTS,
|
||||
)
|
||||
|
||||
with caplog.at_level(logging.DEBUG):
|
||||
freezer.tick(datetime.timedelta(seconds=60))
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert "Currently rate limited, skipping update" in caplog.text
|
||||
|
|
72
tests/components/habitica/test_sensor.py
Normal file
72
tests/components/habitica/test_sensor.py
Normal file
|
@ -0,0 +1,72 @@
|
|||
"""Test Habitica sensor platform."""
|
||||
|
||||
from collections.abc import Generator
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.habitica.const import DOMAIN
|
||||
from homeassistant.components.habitica.sensor import HabitipySensorEntity
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er, issue_registry as ir
|
||||
|
||||
from tests.common import MockConfigEntry, snapshot_platform
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def sensor_only() -> Generator[None]:
|
||||
"""Enable only the sensor platform."""
|
||||
with patch(
|
||||
"homeassistant.components.habitica.PLATFORMS",
|
||||
[Platform.SENSOR],
|
||||
):
|
||||
yield
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_habitica", "entity_registry_enabled_by_default")
|
||||
async def test_sensors(
|
||||
hass: HomeAssistant,
|
||||
config_entry: MockConfigEntry,
|
||||
snapshot: SnapshotAssertion,
|
||||
entity_registry: er.EntityRegistry,
|
||||
) -> None:
|
||||
"""Test setup of the Habitica sensor platform."""
|
||||
|
||||
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
|
||||
|
||||
await snapshot_platform(hass, entity_registry, snapshot, config_entry.entry_id)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_habitica", "entity_registry_enabled_by_default")
|
||||
async def test_sensor_deprecation_issue(
|
||||
hass: HomeAssistant,
|
||||
config_entry: MockConfigEntry,
|
||||
issue_registry: ir.IssueRegistry,
|
||||
) -> None:
|
||||
"""Test task sensor deprecation issue."""
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.habitica.sensor.entity_used_in", return_value=True
|
||||
):
|
||||
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
|
||||
|
||||
assert issue_registry.async_get_issue(
|
||||
domain=DOMAIN,
|
||||
issue_id=f"deprecated_task_entity_{HabitipySensorEntity.TODOS}",
|
||||
)
|
||||
assert issue_registry.async_get_issue(
|
||||
domain=DOMAIN,
|
||||
issue_id=f"deprecated_task_entity_{HabitipySensorEntity.DAILIES}",
|
||||
)
|
Loading…
Add table
Reference in a new issue