hass-core/tests/components/todoist/test_calendar.py
Aaron Godfrey 8cbbdf21f3
Update todoist integration to use new official rest api library (#79481)
* Swapping out libraries.

* Adding types

* Add ability to add task.

* Removed remaining todos.

* Fix lint errors.

* Fixing tests.

* Update to v2 of the rest api.

* Swapping out libraries.

* Adding types

* Add ability to add task.

* Removed remaining todos.

* Fix lint errors.

* Fix mypy errors

* Fix custom projects.

* Bump DEPENDENCY_CONFLICTS const

* Remove conflict bump

* Addressing PR feedback.

* Removing utc offset logic and configuration.

* Addressing PR feedback.

* Revert date range logic check
2022-12-30 09:49:35 -08:00

108 lines
3 KiB
Python

"""Unit tests for the Todoist calendar platform."""
from unittest.mock import AsyncMock, patch
import pytest
from todoist_api_python.models import Due, Label, Project, Task
from homeassistant import setup
from homeassistant.components.todoist.calendar import DOMAIN
from homeassistant.const import CONF_TOKEN
from homeassistant.helpers import entity_registry
@pytest.fixture(name="task")
def mock_task() -> Task:
"""Mock a todoist Task instance."""
return Task(
assignee_id="1",
assigner_id="1",
comment_count=0,
is_completed=False,
content="A task",
created_at="2021-10-01T00:00:00",
creator_id="1",
description="A task",
due=Due(is_recurring=False, date="2022-01-01", string="today"),
id="1",
labels=[],
order=1,
parent_id=None,
priority=1,
project_id="12345",
section_id=None,
url="https://todoist.com",
sync_id=None,
)
@pytest.fixture(name="api")
def mock_api() -> AsyncMock:
"""Mock the api state."""
api = AsyncMock()
api.get_projects.return_value = [
Project(
id="12345",
color="blue",
comment_count=0,
is_favorite=False,
name="Name",
is_shared=False,
url="",
is_inbox_project=False,
is_team_inbox=False,
order=1,
parent_id=None,
view_style="list",
)
]
api.get_labels.return_value = [
Label(id="1", name="label1", color="1", order=1, is_favorite=False)
]
api.get_collaborators.return_value = []
return api
@patch("homeassistant.components.todoist.calendar.TodoistAPIAsync")
async def test_calendar_entity_unique_id(todoist_api, hass, api):
"""Test unique id is set to project id."""
todoist_api.return_value = api
assert await setup.async_setup_component(
hass,
"calendar",
{
"calendar": {
"platform": DOMAIN,
CONF_TOKEN: "token",
}
},
)
await hass.async_block_till_done()
registry = entity_registry.async_get(hass)
entity = registry.async_get("calendar.name")
assert "12345" == entity.unique_id
@patch("homeassistant.components.todoist.calendar.TodoistAPIAsync")
async def test_calendar_custom_project_unique_id(todoist_api, hass, api):
"""Test unique id is None for any custom projects."""
todoist_api.return_value = api
assert await setup.async_setup_component(
hass,
"calendar",
{
"calendar": {
"platform": DOMAIN,
CONF_TOKEN: "token",
"custom_projects": [{"name": "All projects"}],
}
},
)
await hass.async_block_till_done()
registry = entity_registry.async_get(hass)
entity = registry.async_get("calendar.all_projects")
assert entity is None
state = hass.states.get("calendar.all_projects")
assert state.state == "off"