def test_get_emergency_recipients(self): """errorlib - test return of proper set of recipients""" now = datetime.datetime.today() tomorrow = now + datetime.timedelta(days=1) diff_day = now + datetime.timedelta(days=4) later = now.replace(hour=(now.hour + 1) % 24) earlier = now.replace(hour=(now.hour - 1) % 24) constraint_now = "%s %s-%s" % ( now.strftime("%a"), earlier.strftime("%H:00"), later.strftime("%H:00"), ) constraint_tomorrow = "%s %s-%s" % ( tomorrow.strftime("%a"), earlier.strftime("%H:00"), later.strftime("%H:00"), ) constraint_time = "%s-%s" % ( earlier.strftime("%H:00"), later.strftime("%H:00"), ) minute = (now.minute - 3) % 60 # hour and earlier can change when minute is modified if minute > now.minute: hour = (now.hour - 1) % 24 earlier = now.replace(hour=(now.hour - 2) % 24) else: hour = now.hour constraint_near_miss = "%s-%s" % ( earlier.strftime("%H:00"), now.replace(minute=minute, hour=hour) \ .strftime("%H:%M") ) constraint_day = "%s" % now.strftime("%A") constraint_diff_day = "%s" % diff_day.strftime("%A") test_config = { constraint_now: '*****@*****.**', constraint_tomorrow: '*****@*****.**', constraint_time: '*****@*****.**', constraint_day: '[email protected],[email protected]', constraint_diff_day: '*****@*****.**', constraint_near_miss: '*****@*****.**', '*': '*****@*****.**', } result = get_emergency_recipients(recipient_cfg=test_config) expected = [ '*****@*****.**', '*****@*****.**', '[email protected],[email protected]', '*****@*****.**' ] self.assertEqual(set(result), set(expected))
def test_get_emergency_recipients(self): """errorlib - test return of proper set of recipients""" now = datetime.datetime.today() tomorrow = now + datetime.timedelta(days=1) diff_day = now + datetime.timedelta(days=4) later = now.replace(hour=(now.hour + 1) % 24) earlier = now.replace(hour=(now.hour - 1) % 24) constraint_now = "%s %s-%s" % ( now.strftime("%a"), earlier.strftime("%H:00"), later.strftime("%H:00"), ) constraint_tomorrow = "%s %s-%s" % ( tomorrow.strftime("%a"), earlier.strftime("%H:00"), later.strftime("%H:00"), ) constraint_time = "%s-%s" % ( earlier.strftime("%H:00"), later.strftime("%H:00"), ) minute = (now.minute - 3) % 60 # hour and earlier can change when minute is modified if minute > now.minute: hour = (now.hour - 1) % 24 earlier = now.replace(hour=(now.hour - 2) % 24) else: hour = now.hour constraint_near_miss = "%s-%s" % ( earlier.strftime("%H:00"), now.replace(minute=minute, hour=hour) \ .strftime("%H:%M") ) constraint_day = "%s" % now.strftime("%A") constraint_diff_day = "%s" % diff_day.strftime("%A") test_config = { constraint_now: '*****@*****.**', constraint_tomorrow: '*****@*****.**', constraint_time: '*****@*****.**', constraint_day: '[email protected],[email protected]', constraint_diff_day: '*****@*****.**', constraint_near_miss:'*****@*****.**', '*': '*****@*****.**', } result = get_emergency_recipients(recipient_cfg=test_config) expected = ['*****@*****.**', '*****@*****.**', '[email protected],[email protected]', '*****@*****.**'] self.assertEqual(set(result), set(expected))