def has_hour_in_notification_hours(self, hour: Hour) -> bool: try: return bool(hour.value & self.notification_hours) except AttributeError: error = EnumError(except_enum=Hour, wrong_value=hour) log.warning(error.__str__()) return False
def test__has_day_in_notification_days(self): to_have_day = Day.MONDAY not_to_have_day = Day.TUESDAY self.notification_days = [to_have_day] alert_notification = self.get_alert_notification() self.assertTrue( alert_notification.has_day_in_notification_days(to_have_day)) self.assertFalse( alert_notification.has_day_in_notification_days(not_to_have_day)) # Test in Multiples Flags another_day_to_have = Day.SATURDAY self.notification_days = [to_have_day, another_day_to_have] alert_notification = self.get_alert_notification() self.assertTrue( alert_notification.has_day_in_notification_days(day=to_have_day)) self.assertFalse( alert_notification.has_day_in_notification_days( day=not_to_have_day)) self.assertTrue( alert_notification.has_day_in_notification_days( day=another_day_to_have)) # ERROR : Not a Day wrong_day = "iam no day" error = EnumError(except_enum=Day, wrong_value=wrong_day) with patch("logging.warning") as mock: self.assertFalse( alert_notification.has_day_in_notification_days(day=wrong_day)) mock.assert_called_with(error.__str__())
def has_day_in_notification_days(self, day: Day) -> bool: try: return bool(day.value & self.notification_days) except AttributeError: error = EnumError(except_enum=Day, wrong_value=day) log.warning(error.__str__()) return False
def test__has_hour_in_notification_hours(self): to_have_hour = Hour.H_1 not_to_have_hour = Hour.H_2 self.notification_hours = [to_have_hour] alert_notification = self.get_alert_notification() self.assertTrue( alert_notification.has_hour_in_notification_hours(to_have_hour)) self.assertFalse( alert_notification.has_hour_in_notification_hours( not_to_have_hour)) # Test in Multiples Flags another_hour_to_have = Hour.H_3 self.notification_hours = [to_have_hour, another_hour_to_have] alert_notification = self.get_alert_notification() self.assertTrue( alert_notification.has_hour_in_notification_hours( hour=to_have_hour)) self.assertFalse( alert_notification.has_hour_in_notification_hours( hour=not_to_have_hour)) self.assertTrue( alert_notification.has_hour_in_notification_hours( hour=another_hour_to_have)) # ERROR : Not a Hour wrong_hour = "iam no hour" error = EnumError(except_enum=Hour, wrong_value=wrong_hour) with patch("logging.warning") as mock: self.assertFalse( alert_notification.has_hour_in_notification_hours( hour=wrong_hour)) mock.assert_called_with(error.__str__())