示例#1
0
def test_error_handler():
    """
    Simple test that ensures the error handler works as expected.
    Exceptions are not caught here. See `test_error_handler_exception`
    for that.
    :return:
    """
    service_alias = "mock-simple-service"
    service = MockSimpleService(service_alias)
    meta = ServiceMetaData(service_alias)
    service_entry = ServiceDirectoryEntry(service, meta)

    # for the purpose of this test add a directory (something which is done
    # for us in a CannedOS
    directory = {meta.alias: service_entry}
    directory_proxy = DirectoryService(directory)
    service.set_directory_service_proxy(directory_proxy)

    # expect that these two handlers are run, which will append
    # text to the exceptions list in the metadata of the service
    # entry meta object.
    e1 = ErrorHandlerFactory.create(E1, service)
    e2 = ErrorHandlerFactory.create(E2, service)

    service.add_error_handler(e1)
    service.add_error_handler(e2)
    # run the handlers
    service.handle_error(Exception("Something bad happened!"))

    # the mock exception handler commandeer the exception list by adding values
    # only to test that the class ran
    assert len(meta.exceptions) == 3
    assert meta.exceptions[1] == "Exception E1 Handled..."
    assert meta.exceptions[2] == "Exception E2 Handled..."
def test_error_handler():
    """
    Simple test that ensures the error handler works as expected.
    Exceptions are not caught here. See `test_error_handler_exception`
    for that.
    :return:
    """
    service_alias = "mock-simple-service"
    service = MockSimpleService(service_alias)
    meta = ServiceMetaData(service_alias)
    service_entry = ServiceDirectoryEntry(service, meta)

    # for the purpose of this test add a directory (something which is done
    # for us in a CannedOS
    directory = {meta.alias: service_entry}
    directory_proxy = DirectoryService(directory)
    service.set_directory_service_proxy(directory_proxy)

    # expect that these two handlers are run, which will append
    # text to the exceptions list in the metadata of the service
    # entry meta object.
    e1 = ErrorHandlerFactory.create(E1, service)
    e2 = ErrorHandlerFactory.create(E2, service)

    service.add_error_handler(e1)
    service.add_error_handler(e2)
    # run the handlers
    service.handle_error(Exception("Something bad happened!"))

    # the mock exception handler commandeer the exception list by adding values
    # only to test that the class ran
    assert len(meta.exceptions) == 3
    assert meta.exceptions[1] == "Exception E1 Handled..."
    assert meta.exceptions[2] == "Exception E2 Handled..."
示例#3
0
def test_error_handler_exception():
    service_alias = "mock-simple-service"
    service = MockSimpleService(service_alias)
    meta = ServiceMetaData(service_alias)
    service_entry = ServiceDirectoryEntry(service, meta)

    # for the purpose of this test add a directory (something which is done
    # for us in a CannedOS
    directory = {meta.alias: service_entry}
    directory_proxy = DirectoryService(directory)
    service.set_directory_service_proxy(directory_proxy)

    # expect that these two handlers are run, which will append
    # text to the exceptions list in the metadata of the service
    # entry meta object.
    service.add_error_handler(ErrorHandlerFactory.create(E1, service))
    service.add_error_handler(ErrorHandlerFactory.create(E2, service))
    service.add_error_handler(ErrorHandlerFactory.create(E3, service))

    try:
        # run the handlers
        service.handle_error(Exception("Something bad happened!"))
    except HandlerException as ex:
        print(
            "Found exception for test, test passed as it was expected. Exception: [%s]"
            % ex)
def test_error_handler_exception():
    service_alias = "mock-simple-service"
    service = MockSimpleService(service_alias)
    meta = ServiceMetaData(service_alias)
    service_entry = ServiceDirectoryEntry(service, meta)

    # for the purpose of this test add a directory (something which is done
    # for us in a CannedOS
    directory = {meta.alias: service_entry}
    directory_proxy = DirectoryService(directory)
    service.set_directory_service_proxy(directory_proxy)

    # expect that these two handlers are run, which will append
    # text to the exceptions list in the metadata of the service
    # entry meta object.
    service.add_error_handler(ErrorHandlerFactory.create(E1, service))
    service.add_error_handler(ErrorHandlerFactory.create(E2, service))
    service.add_error_handler(ErrorHandlerFactory.create(E3, service))

    try:
        # run the handlers
        service.handle_error(Exception("Something bad happened!"))
    except HandlerException as ex:
        print("Found exception for test, test passed as it was expected. Exception: [%s]" % ex)