-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from klejejs/feat/automated-tests-against-api
Add automated test workflow against Thermia API
- Loading branch information
Showing
3 changed files
with
120 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Automated API test that runs against Thermia API and checks for breaking changes | ||
|
||
on: | ||
schedule: | ||
# run every six hours | ||
- cron: '0 */6 * * *' | ||
workflow_dispatch: | ||
|
||
jobs: | ||
test_api: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/[email protected] | ||
- name: Set up Python | ||
uses: actions/[email protected] | ||
with: | ||
python-version: "3.x" | ||
- name: Install Python dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -U -r requirements.txt | ||
pip install -U ThermiaOnlineAPI | ||
- name: Create .env file | ||
run: | | ||
touch .env | ||
echo "USERNAME=${{ secrets.THERMIA_USERNAME }}" >> .env | ||
echo "PASSWORD=${{ secrets.THERMIA_PASSWORD }}" >> .env | ||
- name: Create a debug log file | ||
run: | | ||
python scripts/test_api.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import os | ||
from ThermiaOnlineAPI import Thermia | ||
|
||
TEST_EXCLUDED_LINE_STRINGS = [ | ||
# self.__info related | ||
"lastOnline", | ||
"activeAlarms", | ||
"activeCriticalAlarms", | ||
"unreadErrors", | ||
"unreadInfo", | ||
"unreadWarnings", | ||
# self.__status related | ||
"dcmVersion", | ||
"heatingEffect", | ||
"hotWaterTemperature", | ||
"indoorTemperature", | ||
"isHotWaterActive", | ||
"isOutdoorTempSensorFunctioning", | ||
"outdoorTemperature", | ||
"programVersion", | ||
"reducedHeatingEffect", | ||
# self.__device_data related | ||
"firmwareVersion", | ||
"lastOnline", | ||
# Register group related | ||
"registerValue", | ||
"timeStamp", | ||
"value", | ||
] | ||
|
||
|
||
def test_excluded_string_in_line(line: str) -> bool: | ||
for excluded_string in TEST_EXCLUDED_LINE_STRINGS: | ||
if excluded_string in line: | ||
return True | ||
return False | ||
|
||
|
||
USERNAME = None | ||
PASSWORD = None | ||
|
||
with open(".env", "r") as env_file: | ||
for line in env_file: | ||
if line.startswith("USERNAME="): | ||
USERNAME = line.split("=")[1].strip() | ||
elif line.startswith("PASSWORD="): | ||
PASSWORD = line.split("=")[1].strip() | ||
|
||
if not USERNAME or not PASSWORD: | ||
print("Username and password not present in .env file") | ||
exit(1) | ||
|
||
thermia = Thermia(USERNAME, PASSWORD) | ||
|
||
print("Connected: " + str(thermia.connected)) | ||
|
||
heat_pump = thermia.heat_pumps[0] | ||
|
||
print("Fetching debug data") | ||
|
||
debug_data = heat_pump.debug() | ||
|
||
print("Comparing debug data to existing debug file") | ||
|
||
absolute_path = os.path.dirname(os.path.abspath(__file__)) | ||
existing_data_filename = ( | ||
f"{absolute_path}/../ThermiaOnlineAPI/tests/debug_files/diplomat_duo_921.txt" | ||
) | ||
|
||
with open("debug.txt", "r") as f: | ||
existing_debug_data = f.read() | ||
|
||
for [existing_line, new_line] in zip( | ||
existing_debug_data.split("\n"), debug_data.split("\n") | ||
): | ||
if test_excluded_string_in_line(existing_line) and test_excluded_string_in_line( | ||
new_line | ||
): | ||
continue | ||
|
||
if existing_line != new_line: | ||
print("Existing data does not match new data") | ||
print("Existing line: " + existing_line) | ||
print("New line: " + new_line) | ||
print("\n") | ||
exit(1) | ||
|
||
print("Debug data matches existing debug file") |