From 33e46765c9544d74c5a0b5771cf3ae2b94dc5d9a Mon Sep 17 00:00:00 2001 From: Cal Williams <9409256+cal4@users.noreply.github.com> Date: Sun, 25 Aug 2024 14:05:25 -0400 Subject: [PATCH 1/2] Return before sending when no urls --- CHANGELOG.md | 6 ++++++ src/utils.py | 7 ++++++- test/test_utils.py | 11 +++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 test/test_utils.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 74207e49..6650ffe5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.0.1] - 2024-08-25 + +### Fixed + +- [AssertionError from apprise.notify(title=str(title), body=str(body))](https://github.com/klept0/MS-Rewards-Farmer/issues) + ## [1.0.0] - 2024-08-23 ### Removed diff --git a/src/utils.py b/src/utils.py index 51bd614d..e7225c3d 100644 --- a/src/utils.py +++ b/src/utils.py @@ -46,7 +46,10 @@ def loadConfig(configFilename="config.yaml") -> dict: configFile = Utils.getProjectRoot() / configFilename try: with open(configFile, "r") as file: - return yaml.safe_load(file) + config = yaml.safe_load(file) + if not config: + return {} + return config except OSError: logging.warning(f"{configFilename} doesn't exist") return {} @@ -57,6 +60,8 @@ def sendNotification(title, body) -> None: return apprise = Apprise() urls: list[str] = Utils.loadConfig("config-private.yaml").get("apprise", {}).get("urls", []) + if not urls: + return for url in urls: apprise.add(url) assert apprise.notify(title=str(title), body=str(body)) diff --git a/test/test_utils.py b/test/test_utils.py new file mode 100644 index 00000000..780a76e8 --- /dev/null +++ b/test/test_utils.py @@ -0,0 +1,11 @@ +from argparse import Namespace +from unittest import TestCase + +from src.utils import Utils + + +class TestUtils(TestCase): + def test_send_notification(self): + Utils.args = Namespace() + Utils.args.disable_apprise = False + Utils.sendNotification("title", "body") From c70155a35810e18921565904d32c71b882805f85 Mon Sep 17 00:00:00 2001 From: Cal Williams <9409256+cal4@users.noreply.github.com> Date: Sun, 25 Aug 2024 14:08:32 -0400 Subject: [PATCH 2/2] Add logging --- src/utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/utils.py b/src/utils.py index e7225c3d..5b2fc555 100644 --- a/src/utils.py +++ b/src/utils.py @@ -48,6 +48,7 @@ def loadConfig(configFilename="config.yaml") -> dict: with open(configFile, "r") as file: config = yaml.safe_load(file) if not config: + logging.info(f"{file} doesn't exist") return {} return config except OSError: @@ -61,6 +62,7 @@ def sendNotification(title, body) -> None: apprise = Apprise() urls: list[str] = Utils.loadConfig("config-private.yaml").get("apprise", {}).get("urls", []) if not urls: + logging.debug("No urls found, not sending notification") return for url in urls: apprise.add(url)