diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9c39107..234a1c8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,8 +17,8 @@ repos: hooks: - id: codespell args: - - --ignore-words-list=hass,alot,datas,dof,dur,farenheit,hist,iff,ines,ist,lightsensor,mut,nd,pres,referer,ser,serie,te,technik,ue,uint,visability,wan,wanna,withing - - --skip="./.*,*.csv,*.json" + - --ignore-words-list=hass,termine + - --skip="./.*,*.csv,*.json," - --quiet-level=2 exclude_types: [csv, json] - repo: https://github.com/PyCQA/flake8 diff --git a/tests/responses/response_papier_leichtverpackungen.html b/tests/responses/response_papier_leichtverpackungen.html new file mode 100644 index 0000000..7447ce6 --- /dev/null +++ b/tests/responses/response_papier_leichtverpackungen.html @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Wochentagnächste TermineAbholungen
+ Papier +
DonnerstagDo, 12.10.2023
Do, 19.10.2023
Do, 26.10.2023

1x wöchentlich
+
+ Leichtverpackungen +
DonnerstagDo, 12.10.2023
Do, 19.10.2023
Do, 26.10.2023

1x wöchentlich
+
+ + + diff --git a/tests/responses/response_restabfall.html b/tests/responses/response_restabfall.html new file mode 100644 index 0000000..00cfdac --- /dev/null +++ b/tests/responses/response_restabfall.html @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Wochentagnächste TermineAbholungen
+ Restabfall +
MittwochMi, 11.10.2023
Mi, 18.10.2023
Mi, 25.10.2023

1x wöchentlich
+
+ Bioabfall +
DonnerstagDo, 12.10.2023
Do, 19.10.2023
Do, 26.10.2023

1x wöchentlich
+
+ Papier +
FreitagFr, 13.10.2023
Fr, 20.10.2023
Fr, 27.10.2023

1x wöchentlich
+
+ Leichtverpackungen +
DonnerstagDo, 12.10.2023
Do, 19.10.2023
Do, 26.10.2023

1x wöchentlich
+
+ + + diff --git a/tests/responses/response_restabfall_660.html b/tests/responses/response_restabfall_660.html new file mode 100644 index 0000000..6442b89 --- /dev/null +++ b/tests/responses/response_restabfall_660.html @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Wochentagnächste TermineAbholungen
+ Restabfall 660/1.100 Liter +
MittwochMi, 11.10.2023
Mi, 18.10.2023
Mi, 25.10.2023

1x wöchentlich
+
+ Bioabfall +
DonnerstagDo, 12.10.2023
Do, 19.10.2023
Do, 26.10.2023

1x wöchentlich
+
+ Papier +
FreitagFr, 13.10.2023
Fr, 20.10.2023
Fr, 27.10.2023

1x wöchentlich
+
+ Leichtverpackungen +
DonnerstagDo, 12.10.2023
Do, 19.10.2023
Do, 26.10.2023

1x wöchentlich
+
+ + + diff --git a/tests/test_coordinator.py b/tests/test_coordinator.py new file mode 100644 index 0000000..32cd291 --- /dev/null +++ b/tests/test_coordinator.py @@ -0,0 +1,58 @@ +"""Tests for coordinator.""" +from unittest.mock import AsyncMock + +import pytest + +from custom_components.aha_region.coordinator import AhaApi + + +@pytest.mark.asyncio +async def test_get_data_restabfall(): + """Test with 4 wastetypes and regular 'Restabfall'.""" + with open("tests/responses/response_restabfall.html") as file: + response = AsyncMock() + response.text.return_value = file.read() + session = AsyncMock() + session.post.return_value = response + api = AhaApi(session, "", "", "", "", "") + data = await api.get_data() + + assert len(data) == 4 + assert data["Restabfall"] == "Mi, 11.10.2023" + assert data["Bioabfall"] == "Do, 12.10.2023" + assert data["Papier"] == "Fr, 13.10.2023" + assert data["Leichtverpackungen"] == "Do, 12.10.2023" + + +@pytest.mark.asyncio +async def test_get_data_restabfall_660(): + """Test with 4 wastetypes and 'Restabfall 660/1.000 Liter'.""" + with open("tests/responses/response_restabfall_660.html") as file: + response = AsyncMock() + response.text.return_value = file.read() + session = AsyncMock() + session.post.return_value = response + api = AhaApi(session, "", "", "", "", "") + data = await api.get_data() + + assert len(data) == 4 + assert data["Restabfall 660/1.100 Liter"] == "Mi, 11.10.2023" + assert data["Bioabfall"] == "Do, 12.10.2023" + assert data["Papier"] == "Fr, 13.10.2023" + assert data["Leichtverpackungen"] == "Do, 12.10.2023" + + +@pytest.mark.asyncio +async def test_get_data_papier_leichtverpackungen(): + """Test with just 2 types of waste collected.""" + with open("tests/responses/response_papier_leichtverpackungen.html") as file: + response = AsyncMock() + response.text.return_value = file.read() + session = AsyncMock() + session.post.return_value = response + api = AhaApi(session, "", "", "", "", "") + data = await api.get_data() + + assert len(data) == 2 + assert data["Papier"] == "Do, 12.10.2023" + assert data["Leichtverpackungen"] == "Do, 12.10.2023"