Fix todoist filtering custom projects by labels (#87904)
* Fix filtering custom projects by labels. * Don't lowercase the label. * Labels are case-sensitive, don't lowercase them.pull/84951/head^2
parent
42a69566ac
commit
ab9bd5c29e
|
@ -94,7 +94,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|||
),
|
||||
vol.Optional(
|
||||
CONF_PROJECT_LABEL_WHITELIST, default=[]
|
||||
): vol.All(cv.ensure_list, [vol.All(cv.string, vol.Lower)]),
|
||||
): vol.All(cv.ensure_list, [vol.All(cv.string)]),
|
||||
}
|
||||
)
|
||||
]
|
||||
|
@ -458,9 +458,8 @@ class TodoistProjectData:
|
|||
|
||||
# All task Labels (optional parameter).
|
||||
task[LABELS] = [
|
||||
label.name.lower() for label in self._labels if label.id in data.labels
|
||||
label.name for label in self._labels if label.name in data.labels
|
||||
]
|
||||
|
||||
if self._label_whitelist and (
|
||||
not any(label in task[LABELS] for label in self._label_whitelist)
|
||||
):
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
"""Unit tests for the Todoist calendar platform."""
|
||||
from datetime import datetime
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
import pytest
|
||||
|
@ -9,6 +10,7 @@ from homeassistant.components.todoist.calendar import DOMAIN
|
|||
from homeassistant.const import CONF_TOKEN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry
|
||||
from homeassistant.helpers.entity_component import async_update_entity
|
||||
|
||||
|
||||
@pytest.fixture(name="task")
|
||||
|
@ -23,9 +25,11 @@ def mock_task() -> 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"),
|
||||
due=Due(
|
||||
is_recurring=False, date=datetime.now().strftime("%Y-%m-%d"), string="today"
|
||||
),
|
||||
id="1",
|
||||
labels=[],
|
||||
labels=["Label1"],
|
||||
order=1,
|
||||
parent_id=None,
|
||||
priority=1,
|
||||
|
@ -37,7 +41,7 @@ def mock_task() -> Task:
|
|||
|
||||
|
||||
@pytest.fixture(name="api")
|
||||
def mock_api() -> AsyncMock:
|
||||
def mock_api(task) -> AsyncMock:
|
||||
"""Mock the api state."""
|
||||
api = AsyncMock()
|
||||
api.get_projects.return_value = [
|
||||
|
@ -57,9 +61,10 @@ def mock_api() -> AsyncMock:
|
|||
)
|
||||
]
|
||||
api.get_labels.return_value = [
|
||||
Label(id="1", name="label1", color="1", order=1, is_favorite=False)
|
||||
Label(id="1", name="Label1", color="1", order=1, is_favorite=False)
|
||||
]
|
||||
api.get_collaborators.return_value = []
|
||||
api.get_tasks.return_value = [task]
|
||||
return api
|
||||
|
||||
|
||||
|
@ -84,6 +89,29 @@ async def test_calendar_entity_unique_id(todoist_api, hass: HomeAssistant, api)
|
|||
assert entity.unique_id == "12345"
|
||||
|
||||
|
||||
@patch("homeassistant.components.todoist.calendar.TodoistAPIAsync")
|
||||
async def test_update_entity_for_custom_project_with_labels_on(todoist_api, hass, api):
|
||||
"""Test that the calendar's state is on for a custom project using labels."""
|
||||
todoist_api.return_value = api
|
||||
assert await setup.async_setup_component(
|
||||
hass,
|
||||
"calendar",
|
||||
{
|
||||
"calendar": {
|
||||
"platform": DOMAIN,
|
||||
CONF_TOKEN: "token",
|
||||
"custom_projects": [{"name": "All projects", "labels": ["Label1"]}],
|
||||
}
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
await async_update_entity(hass, "calendar.all_projects")
|
||||
state = hass.states.get("calendar.all_projects")
|
||||
assert state.attributes["labels"] == ["Label1"]
|
||||
assert state.state == "on"
|
||||
|
||||
|
||||
@patch("homeassistant.components.todoist.calendar.TodoistAPIAsync")
|
||||
async def test_calendar_custom_project_unique_id(
|
||||
todoist_api, hass: HomeAssistant, api
|
||||
|
|
Loading…
Reference in New Issue