Skip to content

Commit cf437b4

Browse files
authored
Merge pull request #43 from klejejs/feat/automated-tests-against-api
Add automated test workflow against Thermia API
2 parents 860fd01 + a49536a commit cf437b4

File tree

3 files changed

+120
-1
lines changed

3 files changed

+120
-1
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Automated API test that runs against Thermia API and checks for breaking changes
2+
3+
on:
4+
schedule:
5+
# run every six hours
6+
- cron: '0 */6 * * *'
7+
workflow_dispatch:
8+
9+
jobs:
10+
test_api:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4.2.2
15+
- name: Set up Python
16+
uses: actions/setup-python@v5.3.0
17+
with:
18+
python-version: "3.x"
19+
- name: Install Python dependencies
20+
run: |
21+
python -m pip install --upgrade pip
22+
pip install -U -r requirements.txt
23+
pip install -U ThermiaOnlineAPI
24+
- name: Create .env file
25+
run: |
26+
touch .env
27+
echo "USERNAME=${{ secrets.THERMIA_USERNAME }}" >> .env
28+
echo "PASSWORD=${{ secrets.THERMIA_PASSWORD }}" >> .env
29+
- name: Create a debug log file
30+
run: |
31+
python scripts/test_api.py

.github/workflows/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ jobs:
2323
python -m pip install --upgrade pip
2424
pip install -U -r requirements.txt -r requirements_testing.txt
2525
- name: Run tests
26-
run: pytest
26+
run: pytest ThermiaOnlineAPI

scripts/test_api.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import os
2+
from ThermiaOnlineAPI import Thermia
3+
4+
TEST_EXCLUDED_LINE_STRINGS = [
5+
# self.__info related
6+
"lastOnline",
7+
"activeAlarms",
8+
"activeCriticalAlarms",
9+
"unreadErrors",
10+
"unreadInfo",
11+
"unreadWarnings",
12+
# self.__status related
13+
"dcmVersion",
14+
"heatingEffect",
15+
"hotWaterTemperature",
16+
"indoorTemperature",
17+
"isHotWaterActive",
18+
"isOutdoorTempSensorFunctioning",
19+
"outdoorTemperature",
20+
"programVersion",
21+
"reducedHeatingEffect",
22+
# self.__device_data related
23+
"firmwareVersion",
24+
"lastOnline",
25+
# Register group related
26+
"registerValue",
27+
"timeStamp",
28+
"value",
29+
]
30+
31+
32+
def test_excluded_string_in_line(line: str) -> bool:
33+
for excluded_string in TEST_EXCLUDED_LINE_STRINGS:
34+
if excluded_string in line:
35+
return True
36+
return False
37+
38+
39+
USERNAME = None
40+
PASSWORD = None
41+
42+
with open(".env", "r") as env_file:
43+
for line in env_file:
44+
if line.startswith("USERNAME="):
45+
USERNAME = line.split("=")[1].strip()
46+
elif line.startswith("PASSWORD="):
47+
PASSWORD = line.split("=")[1].strip()
48+
49+
if not USERNAME or not PASSWORD:
50+
print("Username and password not present in .env file")
51+
exit(1)
52+
53+
thermia = Thermia(USERNAME, PASSWORD)
54+
55+
print("Connected: " + str(thermia.connected))
56+
57+
heat_pump = thermia.heat_pumps[0]
58+
59+
print("Fetching debug data")
60+
61+
debug_data = heat_pump.debug()
62+
63+
print("Comparing debug data to existing debug file")
64+
65+
absolute_path = os.path.dirname(os.path.abspath(__file__))
66+
existing_data_filename = (
67+
f"{absolute_path}/../ThermiaOnlineAPI/tests/debug_files/diplomat_duo_921.txt"
68+
)
69+
70+
with open("debug.txt", "r") as f:
71+
existing_debug_data = f.read()
72+
73+
for [existing_line, new_line] in zip(
74+
existing_debug_data.split("\n"), debug_data.split("\n")
75+
):
76+
if test_excluded_string_in_line(existing_line) and test_excluded_string_in_line(
77+
new_line
78+
):
79+
continue
80+
81+
if existing_line != new_line:
82+
print("Existing data does not match new data")
83+
print("Existing line: " + existing_line)
84+
print("New line: " + new_line)
85+
print("\n")
86+
exit(1)
87+
88+
print("Debug data matches existing debug file")

0 commit comments

Comments
 (0)