Пример #1
0
 def test_set_log_handler_with_non_callables(self, callback):
     '''
     Test whether a non callable may be set as the log function
     '''
     aerospike.set_log_level(aerospike.LOG_LEVEL_DEBUG)
     with pytest.raises(e.ParamError):
         aerospike.set_log_handler(callback)
Пример #2
0
 def test_set_log_handler_with_non_callables(self, callback):
     '''
     Test whether a non callable may be set as the log function
     '''
     aerospike.set_log_level(aerospike.LOG_LEVEL_DEBUG)
     with pytest.raises(e.ParamError):
         aerospike.set_log_handler(callback)
Пример #3
0
    def test_set_log_level_with_invalid_type(self, level):
        """
        Test set_log_level with non int subtypes
        """
        with pytest.raises(e.ParamError) as param_error:
            aerospike.set_log_level(level)

        assert param_error.value.code == -2
Пример #4
0
    def test_set_log_level_with_invalid_type(self, level):
        """
        Test set_log_level with non int subtypes
        """
        with pytest.raises(e.ParamError) as param_error:
            aerospike.set_log_level(level)

        assert param_error.value.code == -2
Пример #5
0
    def test_set_log_level_with_bool(self):
        """
        Test log level with log level as a bool,
        this works because bool is a subclass of int
        """
        with pytest.raises(e.ParamError) as param_error:
            aerospike.set_log_level(False)

        assert param_error.value.code == -2
Пример #6
0
    def test_set_log_level_with_bool(self):
        """
        Test log level with log level as a bool,
        this works because bool is a subclass of int
        """
        with pytest.raises(e.ParamError) as param_error:
            aerospike.set_log_level(False)

        assert param_error.value.code == -2
Пример #7
0
    def test_set_log_level_None(self):
        """
        Test log level with log level as None
        """
        try:
            aerospike.set_log_level(None)

        except e.ParamError as exception:
            assert exception.code == -2
            assert exception.msg == 'Invalid log level'
    def test_set_log_level_None(self):
        """
        Test log level with log level as None
        """
        try:
            aerospike.set_log_level(None)

        except e.ParamError as exception:
            assert exception.code == -2
            assert exception.msg == 'Invalid log level'
Пример #9
0
    def test_set_log_handler_extra_parameter(self):
        """
        Test log handler with extra parameter
        """
        aerospike.set_log_level(aerospike.LOG_LEVEL_DEBUG)

        with pytest.raises(TypeError) as typeError:
            aerospike.set_log_handler(handler, extrahandler)

        assert "setLogHandler() takes at most 1 argument (2 given)" in str(
            typeError.value)
Пример #10
0
    def test_set_log_handler_extra_parameter(self):
        """
        Test log handler with extra parameter
        """
        aerospike.set_log_level(aerospike.LOG_LEVEL_DEBUG)

        with pytest.raises(TypeError) as typeError:
            aerospike.set_log_handler(handler, extrahandler)

        assert "setLogHandler() takes at most 1 argument (2 given)" in str(
            typeError.value)
    def test_set_log_level_incorrect(self):
        """
        Test log level with log level incorrect
        """
        response = aerospike.set_log_level(9)

        assert response == 0
Пример #12
0
    def test_set_log_level_incorrect(self):
        """
        Test log level with log level incorrect
        """
        response = aerospike.set_log_level(9)

        assert response == 0
Пример #13
0
    def test_set_log_level_correct(self):
        """
        Test log level with correct parameters
        """

        response = aerospike.set_log_level(aerospike.LOG_LEVEL_DEBUG)

        assert response == 0
Пример #14
0
    def test_set_log_level_incorrect(self):
        """
        Test log level with a log level of valid type, but outside of
        expected range
        """
        response = aerospike.set_log_level(9)

        assert response == 0
Пример #15
0
    def test_set_log_level_correct(self):
        """
        Test log level with correct parameters
        """

        response = aerospike.set_log_level(aerospike.LOG_LEVEL_DEBUG)

        assert response == 0
Пример #16
0
    def test_set_log_level_incorrect(self):
        """
        Test log level with a log level of valid type, but outside of
        expected range
        """
        response = aerospike.set_log_level(9)

        assert response == 0
    def test_set_log_handler_extra_parameter(self):
        """
        Test log handler with extra parameter
        """

        aerospike.set_log_level(aerospike.LOG_LEVEL_DEBUG)

        def handler(level, func, myfile, line):
            print "Level is: %d" % level

        def extrahandler(level, func, myfile, line):
            print "Level is: %d" % level

        with pytest.raises(TypeError) as typeError:
            aerospike.set_log_handler(handler, extrahandler)

        assert "setLogHandler() takes at most 1 argument (2 given)" in typeError.value
Пример #18
0
    def test_log_handler_raising_error(self):
        '''
        Test for handling of a log handler which raises an error
        '''
        aerospike.set_log_level(aerospike.LOG_LEVEL_DEBUG)
        aerospike.set_log_handler(error_raising_handler)
        with pytest.raises(SystemError):
            hostlist, user, password = TestBaseClass.get_hosts()
            config = {"hosts": hostlist}
            if user is None and password is None:
                client = aerospike.client(config).connect()
            else:
                client = aerospike.client(config).connect(user, password)

        try:
            client.close()  # Close the client if it got opened
        except:
            pass
    def test_set_log_level_None(self):
        """
        Test log level with log level as None
        """
        with pytest.raises(Exception) as exception:
            response = aerospike.set_log_level(None)

        assert exception.value[0] == -2
        assert exception.value[1] == 'Invalid log level'
Пример #20
0
    def test_log_handler_raising_error(self):
        '''
        Test for handling of a log handler which raises an error
        '''
        aerospike.set_log_level(aerospike.LOG_LEVEL_DEBUG)
        aerospike.set_log_handler(error_raising_handler)
        with pytest.raises(SystemError):
            hostlist, user, password = TestBaseClass.get_hosts()
            config = {
                "hosts": hostlist
            }
            if user is None and password is None:
                client = aerospike.client(config).connect()
            else:
                client = aerospike.client(config).connect(user, password)

        try:
            client.close()  # Close the client if it got opened
        except:
            pass
Пример #21
0
    def test_incorrect_prototype_callback(self):
        """
        Test that having a callback which takes the wrong number
        of args, will raise an error on methods which trigger
        logging
        """
        aerospike.set_log_level(aerospike.LOG_LEVEL_DEBUG)
        aerospike.set_log_handler(wrong_args_handler)

        with pytest.raises(SystemError):
            hostlist, user, password = TestBaseClass.get_hosts()
            config = {"hosts": hostlist}
            if user is None and password is None:
                client = aerospike.client(config).connect()
            else:
                client = aerospike.client(config).connect(user, password)

        try:
            client.close()  # Close the client if it got opened
        except:
            pass
Пример #22
0
    def test_set_log_handler_correct(self):
        """
        Test log handler with correct parameters
        """

        response = aerospike.set_log_level(aerospike.LOG_LEVEL_DEBUG)
        aerospike.set_log_handler(handler)

        # Forces an event to be logged
        client = TestBaseClass.get_new_connection()

        assert response == 0
        client.close()
    def test_set_log_handler_correct(self):
        """
        Test log handler with correct parameters
        """

        response = aerospike.set_log_level(aerospike.LOG_LEVEL_DEBUG)
        aerospike.set_log_handler(handler)

        # Forces an event to be logged
        client = TestBaseClass.get_new_connection()

        assert response == 0
        client.close()
Пример #24
0
    def test_incorrect_prototype_callback(self):
        """
        Test that having a callback which takes the wrong number
        of args, will raise an error on methods which trigger
        logging
        """
        aerospike.set_log_level(aerospike.LOG_LEVEL_DEBUG)
        aerospike.set_log_handler(wrong_args_handler)

        with pytest.raises(SystemError):
            hostlist, user, password = TestBaseClass.get_hosts()
            config = {
                "hosts": hostlist
            }
            if user is None and password is None:
                client = aerospike.client(config).connect()
            else:
                client = aerospike.client(config).connect(user, password)

        try:
            client.close()  # Close the client if it got opened
        except:
            pass
    def test_set_log_handler_correct(self):
        """
        Test log handler with correct parameters
        """

        response = aerospike.set_log_level(aerospike.LOG_LEVEL_DEBUG)

        aerospike.set_log_handler(handler)

        config = {
                "hosts": [("127.0.0.1", 3000)]
                }
        client = aerospike.client(config).connect()

        assert response == 0
        client.close()
Пример #26
0
    def test_set_log_handler_correct(self):
        """
        Test log handler with correct parameters
        """

        response = aerospike.set_log_level(aerospike.LOG_LEVEL_DEBUG)
        aerospike.set_log_handler(handler)

        hostlist, user, password = TestBaseClass.get_hosts()
        config = {"hosts": hostlist}
        if user is None and password is None:
            client = aerospike.client(config).connect()
        else:
            client = aerospike.client(config).connect(user, password)

        assert response == 0
        client.close()
Пример #27
0
    def test_set_log_handler_correct(self):
        """
        Test log handler with correct parameters
        """

        response = aerospike.set_log_level(aerospike.LOG_LEVEL_DEBUG)
        aerospike.set_log_handler(handler)

        hostlist, user, password = TestBaseClass.get_hosts()
        config = {
            "hosts": hostlist
        }
        if user is None and password is None:
            client = aerospike.client(config).connect()
        else:
            client = aerospike.client(config).connect(user, password)

        assert response == 0
        client.close()
Пример #28
0
import os
import aerospike

THIS_DIR = os.path.abspath(os.path.dirname(__file__))


def log_callback(level, func, path, line, msg):
    print("[{}] {}".format(func, msg))


if __name__ == "__main__":

    # Setup debug logging in the Aerospike client to help with troubleshooting
    aerospike.set_log_level(aerospike.LOG_LEVEL_DEBUG)
    aerospike.set_log_handler(log_callback)

    config = {
        # The 'tls-name' (third element in tuple) must be specified when using
        # TLS. The 'tls-name' must match the Common Name (CN) or a Subject
        # Alternative Name (SAN) found in the certificate.
        'hosts': [('127.0.0.1', 4000, 'example.server')],
        'tls': {
            # TLS must be explicitly enabled
            'enable':
            True,

            # The CA certificate can alternatively be installed in the system
            # trusted CA certificate directory if security requirements allow
            # system-wide CA trust.
            'cafile':
            os.path.join(THIS_DIR, '..', 'certs', 'example.ca.crt'),