def _test_append_inactive(self): deleted_alarm_ids = [] for alarm in INACTIVE_ALARMS: alarm_name = alarm[VProps.RAWTEXT] if alarm.get(VProps.RAWTEXT) \ else alarm[VProps.NAME] alarm_id, timestamp = ADProcessor.\ _get_alarm_id_and_timestamp(alarm, alarm_name) expected_alarm_id = \ AlarmID(alarm.get(VProps.VITRAGE_RESOURCE_ID), alarm.get(VProps.VITRAGE_RESOURCE_TYPE), alarm_name) self.assertEqual(expected_alarm_id, alarm_id, '') self.inactivate_timestamps[alarm_id] = timestamp deleted_alarm_ids.append(alarm_id) self.data_manager.append_inactive(alarm_id, timestamp) # assert all deleted alarms has same alarm ids as activated alarms self.assertEqual(self.alarm_ids, deleted_alarm_ids) # all alarm are inactive at this moment expected_active_start_dict = {} self.assertEqual(expected_active_start_dict, self.data_manager.active_start_times) expected_activity_dict = {} for alarm_id in self.alarm_ids: expected_activity_dict[alarm_id] = \ self.inactivate_timestamps[alarm_id]\ - self.activate_timestamps[alarm_id] self.assertEqual(expected_activity_dict, self.data_manager.alarms_activity) expected_intersections_dict = {} # all alarms started and ended at the same time, # intersection time equals activity time for alarm_id1 in self.alarm_ids: for alarm_id2 in self.alarm_ids: # exclude intersection of alarm with itself if alarm_id1 != alarm_id2: key = frozenset([alarm_id1, alarm_id2]) expected_intersections_dict[key] = \ self.inactivate_timestamps[alarm_id]\ - self.activate_timestamps[alarm_id] self.assertEqual(expected_intersections_dict, self.data_manager.alarms_intersects)
def _setup_expected_active_alarms_ids(): alarm_ids = [] for alarm in ACTIVE_ALARMS: alarm_name = alarm[VProps.RAWTEXT] if alarm.get(VProps.RAWTEXT) \ else alarm[VProps.NAME] alarm_id = AlarmID(alarm.get(VProps.VITRAGE_RESOURCE_ID), alarm.get(VProps.VITRAGE_RESOURCE_TYPE), alarm_name) alarm_ids.append(alarm_id) return alarm_ids