diff --git a/scripts/utils/notifications.py b/scripts/utils/notifications.py index f958002..5c624e5 100644 --- a/scripts/utils/notifications.py +++ b/scripts/utils/notifications.py @@ -126,13 +126,15 @@ def should_notify(com_name): # check if this is an excluded species APPRISE_ONLY_NOTIFY_SPECIES_NAMES = settings_dict.get('APPRISE_ONLY_NOTIFY_SPECIES_NAMES') if APPRISE_ONLY_NOTIFY_SPECIES_NAMES is not None and APPRISE_ONLY_NOTIFY_SPECIES_NAMES.strip() != "": - if any(bird.lower().replace(" ", "") in com_name.lower().replace(" ", "") for bird in APPRISE_ONLY_NOTIFY_SPECIES_NAMES.split(",")): + excluded_species = [bird.lower().replace(" ", "") for bird in APPRISE_ONLY_NOTIFY_SPECIES_NAMES.split(",")] + if com_name.lower().replace(" ", "") in excluded_species: return False # check if this is an included species APPRISE_ONLY_NOTIFY_SPECIES_NAMES_2 = settings_dict.get('APPRISE_ONLY_NOTIFY_SPECIES_NAMES_2') if APPRISE_ONLY_NOTIFY_SPECIES_NAMES_2 is not None and APPRISE_ONLY_NOTIFY_SPECIES_NAMES_2.strip() != "": - if not any(bird.lower().replace(" ", "") in com_name.lower().replace(" ", "") for bird in APPRISE_ONLY_NOTIFY_SPECIES_NAMES_2.split(",")): + included_species = [bird.lower().replace(" ", "") for bird in APPRISE_ONLY_NOTIFY_SPECIES_NAMES_2.split(",")] + if com_name.lower().replace(" ", "") not in included_species: return False # is it still too soon? diff --git a/tests/test_apprise_notifications.py b/tests/test_apprise_notifications.py index 0269aa8..3f7605d 100644 --- a/tests/test_apprise_notifications.py +++ b/tests/test_apprise_notifications.py @@ -144,7 +144,13 @@ class TestAppriseNotifications(unittest.TestCase): settings_dict['APPRISE_ONLY_NOTIFY_SPECIES_NAMES'] = 'Quailfinch' mock_load_settings.return_value = settings_dict sendAppriseNotifications(**self.get_default_params()) + # Not excluded. Confirm notifications. + self.assertEqual(mock_notify.call_count, 1) + mock_notify.reset_mock() + settings_dict['APPRISE_ONLY_NOTIFY_SPECIES_NAMES'] = 'Quailfinch,' + mock_load_settings.return_value = settings_dict + sendAppriseNotifications(**self.get_default_params()) # Not excluded. Confirm notifications. self.assertEqual(mock_notify.call_count, 1) @@ -167,7 +173,12 @@ class TestAppriseNotifications(unittest.TestCase): settings_dict['APPRISE_ONLY_NOTIFY_SPECIES_NAMES_2'] = 'Quailfinch' mock_load_settings.return_value = settings_dict sendAppriseNotifications(**self.get_default_params()) + # No wanted species. Confirm no notifications. + self.assertEqual(mock_notify.call_count, 0) + settings_dict['APPRISE_ONLY_NOTIFY_SPECIES_NAMES_2'] = 'Quailfinch,' + mock_load_settings.return_value = settings_dict + sendAppriseNotifications(**self.get_default_params()) # No wanted species. Confirm no notifications. self.assertEqual(mock_notify.call_count, 0) @@ -175,7 +186,6 @@ class TestAppriseNotifications(unittest.TestCase): settings_dict['APPRISE_ONLY_NOTIFY_SPECIES_NAMES_2'] = 'Quailfinch,Great Crested Flycatcher' mock_load_settings.return_value = settings_dict sendAppriseNotifications(**self.get_default_params()) - self.assertEqual(mock_notify.call_count, 1)