def test_get_jira_recovery_label_returns_correct_value_for_host_recovery(self): test_dict = create_valid_environment_dict_for_host_recovery() environment = IcingaEnvironment(test_dict) self.assertEqual(ANY_ICINGA_LABEL_STRING_FORMAT % (ANY_LAST_HOST_PROBLEM_ID, ANY_HOSTNAME), environment.get_jira_recovery_label())
def test_create_labels_list_contains_host_problem_id(self): test_dict = create_valid_environment_dict_for_host_problem() environment = IcingaEnvironment(test_dict) actual_labels = environment.create_labels_list() self.assertEqual(1, len(actual_labels)) self.assertEqual(ANY_ICINGA_LABEL_STRING_FORMAT % (ANY_HOST_PROBLEM_ID, ANY_HOSTNAME), actual_labels[0])
def test_create_icinga_label_with_prefix_and_hostname(self): test_dict = create_valid_environment_dict_for_host_problem() environment = IcingaEnvironment(test_dict) actual_label = environment._create_icinga_label(ANY_HOST_PROBLEM_ID) self.assertEqual( ANY_ICINGA_LABEL_STRING_FORMAT % (ANY_HOST_PROBLEM_ID, ANY_HOSTNAME), actual_label)
def test_create_labels_list_contains_host_problem_id(self): test_dict = create_valid_environment_dict_for_host_problem() environment = IcingaEnvironment(test_dict) actual_labels = environment.create_labels_list() self.assertEqual(1, len(actual_labels)) self.assertEqual( ANY_ICINGA_LABEL_STRING_FORMAT % (ANY_HOST_PROBLEM_ID, ANY_HOSTNAME), actual_labels[0])
def test_get_jira_recovery_label_returns_correct_value_for_host_recovery( self): test_dict = create_valid_environment_dict_for_host_recovery() environment = IcingaEnvironment(test_dict) self.assertEqual( ANY_ICINGA_LABEL_STRING_FORMAT % (ANY_LAST_HOST_PROBLEM_ID, ANY_HOSTNAME), environment.get_jira_recovery_label())
def test_validation_for_RECOVERY_succeeds_with_minimal_service_state_environment( self): environment = { 'ICINGA_NOTIFICATIONTYPE': NOTIFICATION_TYPE_RECOVERY, 'ICINGA_SERVICEDESC': ANY_SERVICE_DESCRIPTION, 'ICINGA_LASTSERVICEPROBLEMID': ANY_LAST_SERVICE_PROBLEM_ID, } IcingaEnvironment(environment)
def test_validation_for_RECOVERY_succeeds_with_minimal_host_state_environment( self): environment = { 'ICINGA_NOTIFICATIONTYPE': NOTIFICATION_TYPE_RECOVERY, 'ICINGA_SERVICEDESC': None, 'ICINGA_LASTHOSTPROBLEMID': ANY_LAST_HOST_PROBLEM_ID, } IcingaEnvironment(environment)
def test_validation_for_PROBLEM_succeeds_with_minimal_host_environment( self): environment = { 'ICINGA_NOTIFICATIONTYPE': NOTIFICATION_TYPE_PROBLEM, 'ICINGA_HOSTNAME': ANY_HOSTNAME, 'ICINGA_HOSTSTATE': ANY_HOST_STATE, 'ICINGA_HOSTPROBLEMID': ANY_HOST_PROBLEM_ID, } IcingaEnvironment(environment)
def test_validation_for_PROBLEM_succeeds_with_minimal_service_state_environment( self): environment = { 'ICINGA_NOTIFICATIONTYPE': NOTIFICATION_TYPE_PROBLEM, 'ICINGA_SERVICEDESC': ANY_SERVICE_DESCRIPTION, 'ICINGA_HOSTNAME': ANY_HOSTNAME, 'ICINGA_SERVICESTATE': ANY_SERVICE_STATE, 'ICINGA_SERVICEPROBLEMID': ANY_SERVICE_PROBLEM_ID, } IcingaEnvironment(environment)
def test_icinga_environment_should_skip_nonexisting_or_empty_environment_values( self): environment = create_valid_environment_dict_for_service_problem() environment['ICINGA_LASTHOSTPROBLEMID'] = None environment['ICINGA_HOSTPROBLEMID'] = '' environment.pop('ICINGA_NOTIFICATIONCOMMENT') icinga_environment = IcingaEnvironment(environment) self.assertEqual(icinga_environment.last_host_problem_id, None) self.assertEqual(icinga_environment.host_problem_id, None) self.assertEqual(icinga_environment.notification_comment, None)
def test_has_new_problem_returns_true(self): environment = IcingaEnvironment(create_valid_environment_dict_for_service_problem()) self.assertTrue(environment.has_new_problem())
def test_get_recovery_last_problem_id_returns_last_service_problem_id_for_service_recovery(self): environment = IcingaEnvironment(create_valid_environment_dict_for_service_recovery()) problem_id = environment.get_recovery_last_problem_id() self.assertEqual(ANY_LAST_SERVICE_PROBLEM_ID, problem_id)
def test_when_is_service_issue_is_true_then_is_host_issue_is_false(self): environment = IcingaEnvironment(create_valid_environment_dict_for_service_problem()) self.assertTrue(environment.is_service_issue()) self.assertFalse(environment.is_host_issue())
def test_get_recovery_last_problem_id_returns_last_host_problem_id_for_host_recovery( self): test_dict = create_valid_environment_dict_for_host_recovery() environment = IcingaEnvironment(test_dict) problem_id = environment.get_recovery_last_problem_id() self.assertEqual(ANY_LAST_HOST_PROBLEM_ID, problem_id)
def test_get_recovery_last_problem_id_returns_last_host_problem_id_for_host_recovery(self): test_dict = create_valid_environment_dict_for_host_recovery() environment = IcingaEnvironment(test_dict) problem_id = environment.get_recovery_last_problem_id() self.assertEqual(ANY_LAST_HOST_PROBLEM_ID, problem_id)
def test_get_recovery_last_problem_id_raises_type_error_when_not_in_recovery_state( self): environment = IcingaEnvironment( create_valid_environment_dict_for_host_problem()) self.assertRaises(TypeError, environment.get_recovery_last_problem_id)
def test_get_recovery_last_problem_id_returns_last_service_problem_id_for_service_recovery( self): environment = IcingaEnvironment( create_valid_environment_dict_for_service_recovery()) problem_id = environment.get_recovery_last_problem_id() self.assertEqual(ANY_LAST_SERVICE_PROBLEM_ID, problem_id)
def test_when_is_service_issue_is_true_then_is_host_issue_is_false(self): environment = IcingaEnvironment( create_valid_environment_dict_for_service_problem()) self.assertTrue(environment.is_service_issue()) self.assertFalse(environment.is_host_issue())
def test_host_is_recovered(self): test_dict = create_valid_environment_dict_for_host_recovery() environment = IcingaEnvironment(test_dict) self.assertTrue(environment.is_recovered())
def test_has_new_problem_returns_true(self): environment = IcingaEnvironment( create_valid_environment_dict_for_service_problem()) self.assertTrue(environment.has_new_problem())
def test_create_icinga_label_with_prefix_and_hostname(self): test_dict = create_valid_environment_dict_for_host_problem() environment = IcingaEnvironment(test_dict) actual_label = environment._create_icinga_label(ANY_HOST_PROBLEM_ID) self.assertEqual(ANY_ICINGA_LABEL_STRING_FORMAT % (ANY_HOST_PROBLEM_ID, ANY_HOSTNAME), actual_label)