Add utility to parse thisrun format

This commit is contained in:
Joe Weiss
2022-06-18 14:52:42 -04:00
parent bd52aabaab
commit 6865274bd2
6 changed files with 110 additions and 31 deletions
+33 -4
View File
@@ -37,15 +37,44 @@ def clean_up_after_each_test():
yield
os.remove("test.db")
def test_daily_notifications(mocker):
def test_notifications(mocker):
notify_call = mocker.patch('scripts.notifications.notify')
create_test_db("test.db")
assert(0 == 0)
sendAppriseNotifications("Myiarchus crinitus_Great Crested Flycatcher", "91", "filename", "test.db")
settings_dict = {
"APPRISE_NOTIFICATION_TITLE": "New backyard bird!",
"APPRISE_NOTIFICATION_BODY": "A $comname ($sciname) was just detected with a confidence of $confidence",
"APPRISE_NOTIFY_EACH_DETECTION": "0",
"APPRISE_NOTIFY_NEW_SPECIES": "0",
"APPRISE_NOTIFY_NEW_SPECIES_EACH_DAY": "0"
}
# No active apprise notifcations configured. Confirm no notifications.
sendAppriseNotifications("Myiarchus crinitus_Great Crested Flycatcher", "91", "filename", settings_dict, "test.db")
assert(notify_call.call_count == 0) # No notification should be sent.
# Add daily notification.
notify_call.reset_mock()
settings_dict["APPRISE_NOTIFY_NEW_SPECIES_EACH_DAY"] = "1"
sendAppriseNotifications("Myiarchus crinitus_Great Crested Flycatcher", "91", "filename", settings_dict, "test.db")
assert(notify_call.call_count == 1)
assert(
notify_call.call_args_list[0][0][0][0] == "A Great Crested Flycatcher (Myiarchus crinitus) was just detected with a confidence of 91 (only seen 1 times today)"
)
# Add new species notification.
notify_call.reset_mock()
settings_dict["APPRISE_NOTIFY_NEW_SPECIES"] = "1"
sendAppriseNotifications("Myiarchus crinitus_Great Crested Flycatcher", "91", "filename", settings_dict, "test.db")
assert(notify_call.call_count == 2)
assert(
notify_call.call_args_list[0][0][0][0] == "A Great Crested Flycatcher (Myiarchus crinitus) was just detected with a confidence of 91 (only seen 1 times today)"
)
assert(
notify_call.call_args_list[1][0][0] == "A Great Crested Flycatcher (Myiarchus crinitus) was just detected with a confidence of 91 (only seen 1 times in last 7d)"
)
)
# Add each species notification.
notify_call.reset_mock()
settings_dict["APPRISE_NOTIFY_EACH_DETECTION"] = "1"
sendAppriseNotifications("Myiarchus crinitus_Great Crested Flycatcher", "91", "filename", settings_dict, "test.db")
assert(notify_call.call_count == 3)
+44
View File
@@ -0,0 +1,44 @@
from scripts.utils.parse_settings import config_to_settings
import tempfile
def test():
text = """LATITUDE=32.0
LONGITUDE=-73.0
BIRDWEATHER_ID=
CADDY_PWD="nonsuchpass"
ICE_PWD=birdnetpi
BIRDNETPI_URL=
RTSP_STREAM=
APPRISE_NOTIFICATION_TITLE="Bird!"
APPRISE_NOTIFICATION_BODY="A $comname ($sciname) was just detected with a confidence of $confidence"
APPRISE_NOTIFY_EACH_DETECTION=0
APPRISE_NOTIFY_NEW_SPECIES=1
FLICKR_API_KEY=
FLICKR_FILTER_EMAIL=
RECS_DIR=/home/pi/BirdSongs
REC_CARD=default
PROCESSED=/home/pi/BirdSongs/Processed
EXTRACTED=/home/pi/BirdSongs/Extracted
OVERLAP=0.0
CONFIDENCE=0.7
SENSITIVITY=1.25
CHANNELS=2
FULL_DISK=purge
PRIVACY_THRESHOLD=0
RECORDING_LENGTH=15
EXTRACTION_LENGTH=
AUDIOFMT=mp3
DATABASE_LANG=en
LAST_RUN=
THIS_RUN=
IDFILE=/home/pi/BirdNET-Pi/IdentifiedSoFar.txt"""
filename = tempfile.NamedTemporaryFile(suffix='.txt', delete=False)
with open(filename.name, 'w', encoding='utf8', newline='') as f:
f.write(text)
settings = config_to_settings(filename.name)
assert(settings["APPRISE_NOTIFICATION_TITLE"] == "Bird!")
assert(settings["FULL_DISK"] == "purge")
assert(settings["OVERLAP"] == "0.0") # Yes, it's a string at this point.