예제 #1
0
 def __init__(self, notifiers_config_dict, notifier_directory,
              notifier_parent_module):
     self.monitor_alarm = Notifier(
         config=notifiers_config_dict['monitor_alarm'],
         notifier_directory=notifier_directory,
         notifier_parent_module=notifier_parent_module)
     self.monitor_failure = Notifier(
         config=notifiers_config_dict['monitor_failure'],
         notifier_directory=notifier_directory,
         notifier_parent_module=notifier_parent_module)
예제 #2
0
def test_when_notifier_name_empty_then_exception(notifier_config):
    notifier_config['name'] = ''
    exception_validator = RunnableExceptionValidator(
        lambda: Notifier(notifier_config, Monitor.NOTIFIERS_DIRECTORY, Monitor.
                         NOTIFIER_INSTANCES_PARENT_MODULE))
    exception_validator.verify_exception(
        AssertionError,
        'The name of the notifier must contain at least one character!')
예제 #3
0
def test_when_notifier_file_not_in_directory_then_exception(notifier_config):
    notifier_config['name'] = 'non_existent_notifier.py'
    exception_validator = RunnableExceptionValidator(lambda: Notifier(
        config=notifier_config,
        notifier_directory=NOTIFIERS_TEST_INSTANCES_DIRECTORY,
        notifier_parent_module=NOTIFIERS_TEST_INSTANCES_MODULE))
    exception_validator.verify_exception(
        AssertionError,
        f"The notifier name must be the Python file name placed in the path '{NOTIFIERS_TEST_INSTANCES_DIRECTORY}',"
        f" but got '{notifier_config['name']}'!")
예제 #4
0
def test_when_notifier_file_contains_multiple_python_classes_then_exception(
        notifier_config):
    notifier_config['name'] = 'multiple_classes_in_file.py'
    exception_validator = RunnableExceptionValidator(lambda: Notifier(
        config=notifier_config,
        notifier_directory=NOTIFIERS_TEST_INSTANCES_DIRECTORY,
        notifier_parent_module=NOTIFIERS_TEST_INSTANCES_MODULE))
    exception_validator.verify_exception(
        AssertionError,
        f"The notifier defined in '{notifier_config['name']}' must have a single class defined in its file, "
        f"but got 2 classes: "
        f"{['Notifier', 'AnotherNotifier']}!")
예제 #5
0
def test_when_comparator_class_constructor_missing_reference_value_parameter_then_exception(
        notifier_config):
    notifier_config[
        'name'] = 'notifier_class_constructor_missing_configuration.py'
    exception_validator = RunnableExceptionValidator(lambda: Notifier(
        config=notifier_config,
        notifier_directory=NOTIFIERS_TEST_INSTANCES_DIRECTORY,
        notifier_parent_module=NOTIFIERS_TEST_INSTANCES_MODULE))
    exception_validator.verify_exception(
        AssertionError,
        f"Notifier() takes no arguments. Please make sure that the notifier class constructor takes a single "
        f"argument representing the notifier configuration (which might be empty/undefined)!"
    )
예제 #6
0
def test_when_comparator_class_is_not_subclass_of_abstract_comparator_class_then_exception(
        notifier_config):
    notifier_config[
        'name'] = 'notifier_class_not_subclass_of_abstract_notifier_class.py'
    exception_validator = RunnableExceptionValidator(lambda: Notifier(
        config=notifier_config,
        notifier_directory=NOTIFIERS_TEST_INSTANCES_DIRECTORY,
        notifier_parent_module=NOTIFIERS_TEST_INSTANCES_MODULE))
    exception_validator.verify_exception(
        AssertionError,
        f"The notifier class defined in '{notifier_config['name']}' must be a subclass of the abstract "
        f"Notifier class defined in "
        f"{os.path.join(Notifier.NOTIFIER_ABSTRACT_CLASS_MODULE, Notifier.NOTIFIER_ABSTRACT_CLASS_NAME)}"
    )
예제 #7
0
def test_when_notifier_monitor_failure_configuration_missing_then_no_exception(
        notifier_config):
    notifier_config.pop('configuration')
    Notifier(notifier_config, Monitor.NOTIFIERS_DIRECTORY,
             Monitor.NOTIFIER_INSTANCES_PARENT_MODULE)
예제 #8
0
def test_when_comparator_class_meets_all_contract_requirements_then_no_exception(
        notifier_config):
    notifier_config['name'] = 'well_defined_notifier.py'
    Notifier(config=notifier_config,
             notifier_directory=NOTIFIERS_TEST_INSTANCES_DIRECTORY,
             notifier_parent_module=NOTIFIERS_TEST_INSTANCES_MODULE)