Skip to content

Commit

Permalink
Tests for different combinations of wastetypes
Browse files Browse the repository at this point in the history
  • Loading branch information
flabbamann committed Oct 10, 2023
1 parent 24ff4dd commit 58b7bbf
Show file tree
Hide file tree
Showing 5 changed files with 285 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
49 changes: 49 additions & 0 deletions tests/responses/response_papier_leichtverpackungen.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<html>
<head>
</head>
<body>
<table>
<tbody>
<tr>
<th class="mobile_no">Wochentag</th>
<th>nächste Termine</th>
<th>Abholungen</th>
</tr>

<tr>
<td colspan="3" class="bg-light p-2">
<strong>Papier</strong>
</td>
</tr>
<tr>
<td valign="top" class="mobile_no p-1"><strong>Donnerstag</strong></td>
<td valign="top" width="150px" class="p-1"><!-- ###SUCH_ERGEBNIS_FRAKTIONEN_NAECHSTE_TERMINE### start-->Do, 12.10.2023<br>Do, 19.10.2023<br>Do, 26.10.2023<br><br><!-- ###SUCH_ERGEBNIS_FRAKTIONEN_NAECHSTE_TERMINE### end--></td>
<td valign="top" class="p-1">1x wöchentlich</td>
</tr>
<tr>
<td colspan="3">
</td>
</tr>

<tr colspan="3">
<td class="p-2"></td>
</tr>
<tr>
<td colspan="3" class="bg-light p-2">
<strong>Leichtverpackungen</strong>
</td>
</tr>
<tr>
<td valign="top" class="mobile_no p-1"><strong>Donnerstag</strong></td>
<td valign="top" width="150px" class="p-1"><!-- ###SUCH_ERGEBNIS_FRAKTIONEN_NAECHSTE_TERMINE### start-->Do, 12.10.2023<br>Do, 19.10.2023<br>Do, 26.10.2023<br><br><!-- ###SUCH_ERGEBNIS_FRAKTIONEN_NAECHSTE_TERMINE### end--></td>
<td valign="top" class="p-1">1x wöchentlich</td>
</tr>
<tr>
<td colspan="3">
</td>
</tr>
</tbody>
</table>

</body>
</html>
88 changes: 88 additions & 0 deletions tests/responses/response_restabfall.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<html>
<head>
</head>
<body>
<table>
<tbody>
<tr>
<th class="mobile_no">Wochentag</th>
<th>nächste Termine</th>
<th>Abholungen</th>
</tr>

<tr colspan="3">
<td class="p-2"></td>
</tr>
<tr>
<td colspan="3" class="bg-light p-2">
<strong>Restabfall</strong>
</td>
</tr>
<tr>
<td valign="top" class="mobile_no p-1"><strong>Mittwoch</strong></td>
<td valign="top" width="150px" class="p-1"><!-- ###SUCH_ERGEBNIS_FRAKTIONEN_NAECHSTE_TERMINE### start-->Mi, 11.10.2023<br>Mi, 18.10.2023<br>Mi, 25.10.2023<br><br><!-- ###SUCH_ERGEBNIS_FRAKTIONEN_NAECHSTE_TERMINE### end--></td>
<td valign="top" class="p-1">1x wöchentlich</td>
</tr>
<tr>
<td colspan="3">
</td>
</tr>

<tr colspan="3">
<td class="p-2"></td>
</tr>
<tr>
<td colspan="3" class="bg-light p-2">
<strong>Bioabfall</strong>
</td>
</tr>
<tr>
<td valign="top" class="mobile_no p-1"><strong>Donnerstag</strong></td>
<td valign="top" width="150px" class="p-1"><!-- ###SUCH_ERGEBNIS_FRAKTIONEN_NAECHSTE_TERMINE### start-->Do, 12.10.2023<br>Do, 19.10.2023<br>Do, 26.10.2023<br><br><!-- ###SUCH_ERGEBNIS_FRAKTIONEN_NAECHSTE_TERMINE### end--></td>
<td valign="top" class="p-1">1x wöchentlich</td>
</tr>
<tr>
<td colspan="3">
</td>
</tr>

<tr colspan="3">
<td class="p-2"></td>
</tr>
<tr>
<td colspan="3" class="bg-light p-2">
<strong>Papier</strong>
</td>
</tr>
<tr>
<td valign="top" class="mobile_no p-1"><strong>Freitag</strong></td>
<td valign="top" width="150px" class="p-1"><!-- ###SUCH_ERGEBNIS_FRAKTIONEN_NAECHSTE_TERMINE### start-->Fr, 13.10.2023<br>Fr, 20.10.2023<br>Fr, 27.10.2023<br><br><!-- ###SUCH_ERGEBNIS_FRAKTIONEN_NAECHSTE_TERMINE### end--></td>
<td valign="top" class="p-1">1x wöchentlich</td>
</tr>
<tr>
<td colspan="3">
</td>
</tr>

<tr colspan="3">
<td class="p-2"></td>
</tr>
<tr>
<td colspan="3" class="bg-light p-2">
<strong>Leichtverpackungen</strong>
</td>
</tr>
<tr>
<td valign="top" class="mobile_no p-1"><strong>Donnerstag</strong></td>
<td valign="top" width="150px" class="p-1"><!-- ###SUCH_ERGEBNIS_FRAKTIONEN_NAECHSTE_TERMINE### start-->Do, 12.10.2023<br>Do, 19.10.2023<br>Do, 26.10.2023<br><br><!-- ###SUCH_ERGEBNIS_FRAKTIONEN_NAECHSTE_TERMINE### end--></td>
<td valign="top" class="p-1">1x wöchentlich</td>
</tr>
<tr>
<td colspan="3">
</td>
</tr>
</tbody>
</table>

</body>
</html>
88 changes: 88 additions & 0 deletions tests/responses/response_restabfall_660.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<html>
<head>
</head>
<body>
<table>
<tbody>
<tr>
<th class="mobile_no">Wochentag</th>
<th>nächste Termine</th>
<th>Abholungen</th>
</tr>

<tr colspan="3">
<td class="p-2"></td>
</tr>
<tr>
<td colspan="3" class="bg-light p-2">
<strong>Restabfall 660/1.100 Liter</strong>
</td>
</tr>
<tr>
<td valign="top" class="mobile_no p-1"><strong>Mittwoch</strong></td>
<td valign="top" width="150px" class="p-1"><!-- ###SUCH_ERGEBNIS_FRAKTIONEN_NAECHSTE_TERMINE### start-->Mi, 11.10.2023<br>Mi, 18.10.2023<br>Mi, 25.10.2023<br><br><!-- ###SUCH_ERGEBNIS_FRAKTIONEN_NAECHSTE_TERMINE### end--></td>
<td valign="top" class="p-1">1x wöchentlich</td>
</tr>
<tr>
<td colspan="3">
</td>
</tr>

<tr colspan="3">
<td class="p-2"></td>
</tr>
<tr>
<td colspan="3" class="bg-light p-2">
<strong>Bioabfall</strong>
</td>
</tr>
<tr>
<td valign="top" class="mobile_no p-1"><strong>Donnerstag</strong></td>
<td valign="top" width="150px" class="p-1"><!-- ###SUCH_ERGEBNIS_FRAKTIONEN_NAECHSTE_TERMINE### start-->Do, 12.10.2023<br>Do, 19.10.2023<br>Do, 26.10.2023<br><br><!-- ###SUCH_ERGEBNIS_FRAKTIONEN_NAECHSTE_TERMINE### end--></td>
<td valign="top" class="p-1">1x wöchentlich</td>
</tr>
<tr>
<td colspan="3">
</td>
</tr>

<tr colspan="3">
<td class="p-2"></td>
</tr>
<tr>
<td colspan="3" class="bg-light p-2">
<strong>Papier</strong>
</td>
</tr>
<tr>
<td valign="top" class="mobile_no p-1"><strong>Freitag</strong></td>
<td valign="top" width="150px" class="p-1"><!-- ###SUCH_ERGEBNIS_FRAKTIONEN_NAECHSTE_TERMINE### start-->Fr, 13.10.2023<br>Fr, 20.10.2023<br>Fr, 27.10.2023<br><br><!-- ###SUCH_ERGEBNIS_FRAKTIONEN_NAECHSTE_TERMINE### end--></td>
<td valign="top" class="p-1">1x wöchentlich</td>
</tr>
<tr>
<td colspan="3">
</td>
</tr>

<tr colspan="3">
<td class="p-2"></td>
</tr>
<tr>
<td colspan="3" class="bg-light p-2">
<strong>Leichtverpackungen</strong>
</td>
</tr>
<tr>
<td valign="top" class="mobile_no p-1"><strong>Donnerstag</strong></td>
<td valign="top" width="150px" class="p-1"><!-- ###SUCH_ERGEBNIS_FRAKTIONEN_NAECHSTE_TERMINE### start-->Do, 12.10.2023<br>Do, 19.10.2023<br>Do, 26.10.2023<br><br><!-- ###SUCH_ERGEBNIS_FRAKTIONEN_NAECHSTE_TERMINE### end--></td>
<td valign="top" class="p-1">1x wöchentlich</td>
</tr>
<tr>
<td colspan="3">
</td>
</tr>
</tbody>
</table>

</body>
</html>
58 changes: 58 additions & 0 deletions tests/test_coordinator.py
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 58b7bbf

Please sign in to comment.