def test_channel_raise_with_close_reply_code_500(self):
        connection = FakeConnection()
        channel = Channel(0, connection, 360)

        # Set up Fake Channel.
        channel._inbound = [1, 2, 3]
        channel.set_state(channel.OPEN)
        channel._consumer_tags = [1, 2, 3]

        close_frame = specification.Channel.Close(
            reply_code=500,
            reply_text='travis-ci'
        )
        channel._close_channel(close_frame)

        self.assertEqual(channel._inbound, [])
        self.assertEqual(channel._consumer_tags, [])
        self.assertEqual(channel._state, channel.CLOSED)

        self.assertIsInstance(
            connection.get_last_frame(),
            specification.Channel.CloseOk
        )

        self.assertRaisesRegexp(
            AMQPChannelError,
            'Channel 0 was closed by remote server: travis-ci',
            channel.check_for_errors
        )
    def test_io_receive_does_not_raise_on_block(self):
        connection = FakeConnection()

        io = IO(connection.parameters, exceptions=connection.exceptions)
        io.socket = mock.Mock(name='socket', spec=socket.socket)
        io.socket.recv.side_effect = socket.error(EWOULDBLOCK)
        io._receive()
        self.assertIsNone(connection.check_for_errors())
Beispiel #3
0
    def test_io_set_ssl_context_no_hostname_provided(self):
        connection = FakeConnection()
        connection.parameters['ssl_options'] = {
            'context': ssl.create_default_context(),
        }

        io = IO(connection.parameters)
        self.assertRaises(ValueError, io._ssl_wrap_socket, socket.socket())
Beispiel #4
0
    def test_channel0_credentials(self):
        connection = FakeConnection()
        connection.parameters['username'] = '******'
        connection.parameters['password'] = '******'
        channel = Channel0(connection)
        credentials = channel._plain_credentials()

        self.assertEqual(credentials, '\0guest\0password')
    def test_channel0_tune_frame(self):
        connection = FakeConnection()
        connection.parameters['virtual_host'] = '/'
        channel = Channel0(connection)

        channel.on_frame(Connection.Tune())

        self.assertIsInstance(connection.get_last_frame(), Connection.TuneOk)
        self.assertIsInstance(connection.get_last_frame(), Connection.Open)
Beispiel #6
0
    def test_io_set_ssl_context(self):
        connection = FakeConnection()
        connection.parameters['ssl_options'] = {
            'context': ssl.create_default_context(),
            'server_hostname': 'localhost',
        }

        io = IO(connection.parameters)
        self.assertTrue(io._ssl_wrap_socket(socket.socket()))
Beispiel #7
0
    def test_channel_flow_frame(self):
        connection = FakeConnection()
        connection.set_state(connection.OPEN)
        channel = Channel(0, connection, rpc_timeout=360)
        channel.set_state(channel.OPEN)

        channel.on_frame(specification.Channel.Flow())

        self.assertIsInstance(connection.frames_out[0][1],
                              specification.Channel.FlowOk)
Beispiel #8
0
    def test_io_get_socket_address(self):
        connection = FakeConnection()
        connection.parameters['hostname'] = '127.0.0.1'
        connection.parameters['port'] = 5672
        io = IO(connection.parameters)
        addresses = io._get_socket_addresses()
        sock_address_tuple = addresses[0]

        self.assertEqual(sock_address_tuple[4],
                         ('127.0.0.1', 5672))
Beispiel #9
0
    def test_io_sets_default_ssl_version(self):
        connection = FakeConnection()
        connection.parameters['ssl_options'] = {}

        sock = Mock(name='socket', spec=socket.socket)
        sock.fileno.return_value = 1

        io = IO(connection.parameters)
        self.assertRaises(Exception, io._ssl_wrap_socket, sock)
        self.assertEqual(connection.parameters['ssl_options']['ssl_version'],
                         compatibility.DEFAULT_SSL_VERSION)
 def test_io_normal_connection_without_ssl_library(self, _):
     connection = FakeConnection()
     connection.parameters['hostname'] = 'localhost'
     connection.parameters['port'] = 1234
     parameters = connection.parameters
     io = IO(parameters)
     self.assertRaisesRegexp(
         AMQPConnectionError,
         'Could not connect to localhost:1234 error: Connection refused',
         io.open
     )
 def test_io_raises_gaierror(self, _):
     connection = FakeConnection()
     connection.parameters['hostname'] = 'localhost'
     connection.parameters['port'] = 1234
     parameters = connection.parameters
     io = IO(parameters)
     self.assertRaisesRegexp(
         AMQPConnectionError,
         'could not connect',
         io._get_socket_addresses
     )
Beispiel #12
0
    def test_channel0_close_connection(self):
        connection = FakeConnection()
        connection.set_state(connection.OPEN)
        channel = Channel0(connection)

        self.assertTrue(connection.is_open)
        channel._close_connection(
            Connection.Close(reply_text=b'',
                             reply_code=200)
        )
        self.assertEqual(connection.exceptions, [])
        self.assertTrue(connection.is_closed)
Beispiel #13
0
 def test_io_normal_connection_without_ssl_library(self):
     compatibility.SSL_SUPPORTED = False
     try:
         connection = FakeConnection()
         connection.parameters['hostname'] = 'localhost'
         connection.parameters['port'] = 1234
         parameters = connection.parameters
         io = IO(parameters)
         self.assertRaisesRegexp(AMQPConnectionError,
                                 'Could not connect to localhost:1234',
                                 io.open, [])
     finally:
         compatibility.SSL_SUPPORTED = True
Beispiel #14
0
    def test_io_use_defined_ssl_version(self):
        connection = FakeConnection()
        connection.parameters['ssl_options'] = {
            'ssl_version': 'travis-ci'
        }

        sock = Mock(name='socket', spec=socket.socket)
        sock.fileno.return_value = 1

        io = IO(connection.parameters)
        self.assertRaises(Exception, io._ssl_wrap_socket, sock)
        self.assertEqual(connection.parameters['ssl_options']['ssl_version'],
                         'travis-ci')
    def test_channel0_start_invalid_auth_frame(self):
        connection = FakeConnection()
        connection.parameters['username'] = '******'
        connection.parameters['password'] = '******'
        channel = Channel0(connection)

        channel.on_frame(Connection.Start(mechanisms='invalid'))

        self.assertRaisesRegexp(
            AMQPConnectionError,
            'Unsupported Security Mechanism\(s\): invalid',
            connection.check_for_errors
        )
Beispiel #16
0
    def test_channel0_send_start_ok_frame(self):
        connection = FakeConnection()
        connection.parameters['username'] = '******'
        connection.parameters['password'] = '******'
        channel = Channel0(connection)
        channel._send_start_ok_frame(Connection.Start(mechanisms=b'PLAIN'))

        self.assertNotEqual(connection.frames_out, [])
        channel_id, frame_out = connection.frames_out.pop()
        self.assertEqual(channel_id, 0)
        self.assertIsInstance(frame_out, Connection.StartOk)
        self.assertNotEqual(frame_out.locale, '')
        self.assertIsNotNone(frame_out.locale)
    def test_channel0_start_frame(self):
        connection = FakeConnection()
        connection.parameters['username'] = '******'
        connection.parameters['password'] = '******'
        channel = Channel0(connection)

        properties = {
            'version': 0
        }

        channel.on_frame(Connection.Start(server_properties=properties))

        self.assertEqual(channel.server_properties, properties)
        self.assertIsInstance(connection.get_last_frame(), Connection.StartOk)
Beispiel #18
0
 def test_io_ssl_connection_without_ssl_library(self):
     compatibility.SSL_SUPPORTED = False
     try:
         connection = FakeConnection()
         connection.parameters['hostname'] = 'localhost'
         connection.parameters['port'] = 1234
         parameters = connection.parameters
         parameters['ssl'] = True
         io = IO(parameters)
         self.assertRaisesRegexp(AMQPConnectionError,
                                 'Python not compiled with '
                                 'support for TLSv1 or higher',
                                 io.open, [])
     finally:
         compatibility.SSL_SUPPORTED = True
Beispiel #19
0
    def test_io_simple_ssl_receive(self):
        connection = FakeConnection()
        connection.parameters['ssl'] = True
        io = IO(connection.parameters)

        self.assertTrue(io.use_ssl)

        if hasattr(ssl, 'SSLObject'):
            io.socket = Mock(name='socket', spec=ssl.SSLObject)
        elif hasattr(ssl, 'SSLSocket'):
            io.socket = Mock(name='socket', spec=ssl.SSLSocket)

        io.socket.read.return_value = '12345'

        self.assertEqual(io._receive(), '12345')
Beispiel #20
0
    def test_io_create_ssl_socket(self):
        connection = FakeConnection()
        connection.parameters['ssl'] = True
        io = IO(connection.parameters)

        self.assertTrue(io.use_ssl)

        addresses = io._get_socket_addresses()
        sock_address_tuple = addresses[0]
        sock = io._create_socket(socket_family=sock_address_tuple[0])

        if hasattr(socket, 'socket'):
            self.assertIsInstance(sock, socket.socket)
        if hasattr(ssl, 'SSLSocket'):
            self.assertIsInstance(sock, ssl.SSLSocket)
        self.assertTrue(connection.parameters['ssl_options']['ssl_version'])
Beispiel #21
0
    def test_io_has_ipv6(self):
        restore_func = socket.getaddrinfo

        def mock_getaddrinfo(hostname, port, family, socktype):
            return [hostname, port, family, socktype]

        try:
            amqpstorm.io.socket.getaddrinfo = mock_getaddrinfo
            connection = FakeConnection()
            connection.parameters['hostname'] = 'localhost'
            connection.parameters['port'] = 1234
            parameters = connection.parameters
            io = IO(parameters)

            result = io._get_socket_addresses()
            self.assertEqual(result[2], socket.AF_UNSPEC)
            self.assertEqual(result[3], socket.SOCK_STREAM)
        finally:
            amqpstorm.io.socket.getaddrinfo = restore_func
Beispiel #22
0
    def test_wait_for_request(self):
        rpc = Rpc(FakeConnection(), timeout=1)
        uuid = rpc.register_request(['travis-ci'])

        def delivery_payload():
            time.sleep(0.1)
            rpc.on_frame(FakePayload(name='travis-ci'))

        thread = threading.Thread(target=delivery_payload)
        thread.start()

        rpc._wait_for_request(
            uuid, connection_adapter=rpc._default_connection_adapter)
Beispiel #23
0
    def test_io_simple_send_zero_bytes_sent(self):
        connection = FakeConnection()

        io = IO(connection.parameters, exceptions=connection.exceptions)
        io.socket = Mock(name='socket', spec=socket.socket)
        io.socket.send.return_value = 0
        io.write_to_socket(self.message)

        self.assertRaisesRegexp(
            AMQPConnectionError,
            'connection/socket error',
            connection.check_for_errors
        )
Beispiel #24
0
    def test_channel_with_statement_when_failing(self):
        connection = FakeConnection()
        try:
            with Channel(0, connection, 360) as channel:
                channel.exceptions.append(AMQPChannelError('error'))
                channel.check_for_errors()
        except AMQPChannelError as why:
            self.assertIsInstance(why, AMQPChannelError)

        self.assertEqual(
            self.get_last_log(),
            'Closing channel due to an unhandled exception: '
            'error')
    def test_channel_close_frame(self):
        connection = FakeConnection(state=FakeConnection.OPEN)
        channel = Channel(0, connection, rpc_timeout=1)
        channel.set_state(channel.OPEN)

        channel.on_frame(
            specification.Channel.Close(reply_code=500,
                                        reply_text='travis-ci'))

        self.assertRaisesRegexp(
            AMQPChannelError,
            'Channel 0 was closed by remote server: travis-ci',
            channel.check_for_errors)
    def test_basic_publish_confirms_raises_on_timeout(self):
        connection = FakeConnection()
        channel = Channel(9, connection, 0.01)
        channel._confirming_deliveries = True
        channel.set_state(Channel.OPEN)
        basic = Basic(channel)

        self.assertRaisesRegexp(
            exception.AMQPChannelError,
            'rpc requests .* \(.*\) took too long',
            basic.publish, body=self.message,
            routing_key='travis-ci'
        )
Beispiel #27
0
    def test_channel0_send_start_ok_external(self):
        connection = FakeConnection()
        channel = Channel0(connection)
        channel._send_start_ok(Connection.Start(mechanisms=b'EXTERNAL'))

        self.assertTrue(connection.frames_out)

        channel_id, frame_out = connection.frames_out.pop()

        self.assertEqual(channel_id, 0)
        self.assertIsInstance(frame_out, Connection.StartOk)
        self.assertNotEqual(frame_out.locale, '')
        self.assertIsNotNone(frame_out.locale)
Beispiel #28
0
    def test_io_has_ipv6_is_false(self):
        restore_func = socket.getaddrinfo
        restore_has_ipv6 = amqpstorm.io.socket.has_ipv6

        def mock_getaddrinfo(hostname, port, family, socktype):
            return [hostname, port, family, socktype]

        try:
            amqpstorm.io.socket.getaddrinfo = mock_getaddrinfo
            amqpstorm.io.socket.has_ipv6 = False
            connection = FakeConnection()
            connection.parameters['hostname'] = 'localhost'
            connection.parameters['port'] = 1234
            parameters = connection.parameters
            io = IO(parameters)

            result = io._get_socket_addresses()
            self.assertEqual(result[2], socket.AF_INET)
            self.assertEqual(result[3], socket.SOCK_STREAM)
        finally:
            amqpstorm.io.socket.getaddrinfo = restore_func
            amqpstorm.io.socket.has_ipv6 = restore_has_ipv6
Beispiel #29
0
    def test_basic_publish_confirms_nack(self):
        message = str(uuid.uuid4())

        def on_publish_return_nack(*_):
            channel.rpc.on_frame(spec_basic.Nack())

        connection = FakeConnection(on_write=on_publish_return_nack)
        channel = Channel(9, connection, 1)
        channel.confirming_deliveries = True
        channel.set_state(Channel.OPEN)
        basic = Basic(channel)

        self.assertFalse(basic.publish(body=message, routing_key='unittest'))
Beispiel #30
0
    def test_basic_get_message_empty_queue(self):
        get_frame = specification.Basic.Get(queue='travis-ci', no_ack=False)

        def on_get_frame(*_):
            channel.rpc.on_frame(specification.Basic.GetEmpty())

        connection = FakeConnection(on_write=on_get_frame)
        channel = Channel(9, connection, 1)
        channel.set_state(Channel.OPEN)
        basic = Basic(channel)

        result = basic._get_message(get_frame, auto_decode=False)

        self.assertEqual(result, None)
Beispiel #31
0
    def test_basic_get_empty(self):
        def on_get_frame(*_):
            channel.rpc.on_frame(specification.Basic.GetEmpty())

        connection = FakeConnection(on_write=on_get_frame)
        channel = Channel(9, connection, 1)
        channel.set_state(Channel.OPEN)
        basic = Basic(channel)

        result = basic.get(queue='travis-ci')

        self.assertFalse(channel.rpc._request)
        self.assertFalse(channel.rpc._response)
        self.assertIsNone(result)
Beispiel #32
0
    def test_basic_publish_confirms_raises_on_timeout(self):
        message = str(uuid.uuid4())

        connection = FakeConnection()
        channel = Channel(9, connection, 0.01)
        channel.confirming_deliveries = True
        channel.set_state(Channel.OPEN)
        basic = Basic(channel)

        self.assertRaisesRegexp(exception.AMQPChannelError,
                                "rpc requests",
                                basic.publish,
                                body=message,
                                routing_key='unittest')
Beispiel #33
0
    def test_channel0_send_tune_ok(self):
        connection = FakeConnection()
        channel = Channel0(connection)
        channel._send_tune_ok(Connection.Tune())

        self.assertTrue(connection.frames_out)

        channel_id, frame_out = connection.frames_out.pop()

        self.assertEqual(channel_id, 0)
        self.assertIsInstance(frame_out, Connection.TuneOk)

        self.assertEqual(frame_out.channel_max, MAX_CHANNELS)
        self.assertEqual(frame_out.frame_max, MAX_FRAME_SIZE)
Beispiel #34
0
    def test_queue_declare(self):
        def on_declare(*_):
            channel.rpc.on_frame(pamqp_queue.DeclareOk())

        connection = FakeConnection(on_write=on_declare)
        channel = Channel(0, connection, 0.1)
        channel.set_state(Channel.OPEN)
        queue = Queue(channel)

        self.assertEqual(queue.declare(), {
            'queue': '',
            'message_count': 0,
            'consumer_count': 0
        })
Beispiel #35
0
    def test_channel_build_inbound_messages(self):
        channel = Channel(0, FakeConnection(), 360)
        channel.set_state(Channel.OPEN)

        message = b'Hello World!'
        message_len = len(message)

        deliver = specification.Basic.Deliver()
        header = ContentHeader(body_size=message_len)
        body = ContentBody(value=message)

        channel._inbound = [deliver, header, body]

        for message in channel.build_inbound_messages(break_on_empty=True):
            self.assertIsInstance(message, Message)
    def test_basic_publish_confirms_raises_on_invalid_frame(self):
        def on_publish_return_invalid_frame(*_):
            channel.rpc.on_frame(specification.Basic.Cancel())

        connection = FakeConnection(on_write=on_publish_return_invalid_frame)
        channel = Channel(9, connection, 0.01)
        channel._confirming_deliveries = True
        channel.set_state(Channel.OPEN)
        basic = Basic(channel)

        self.assertRaisesRegexp(exception.AMQPChannelError,
                                'rpc requests .* \(.*\) took too long',
                                basic.publish,
                                body=self.message,
                                routing_key='travis-ci')
Beispiel #37
0
    def test_channel_raise_with_close_reply_code_500(self):
        connection = FakeConnection()
        channel = Channel(0, connection, 360)

        # Set up Fake Channel.
        channel._inbound = [1, 2, 3]
        channel.set_state(channel.OPEN)
        channel._consumer_tags = [1, 2, 3]

        close_frame = specification.Channel.Close(reply_code=500,
                                                  reply_text='travis-ci')
        channel._close_channel(close_frame)

        self.assertEqual(channel._inbound, [])
        self.assertEqual(channel._consumer_tags, [])
        self.assertEqual(channel._state, channel.CLOSED)

        self.assertIsInstance(connection.get_last_frame(),
                              specification.Channel.CloseOk)

        self.assertRaisesRegexp(
            AMQPChannelError,
            'Channel 0 was closed by remote server: travis-ci',
            channel.check_for_errors)
Beispiel #38
0
    def test_queue_delete_invalid_parameter(self):
        channel = Channel(0, FakeConnection(), 360)
        channel.set_state(Channel.OPEN)
        queue = Queue(channel)

        self.assertRaisesRegexp(exception.AMQPInvalidArgument,
                                'queue should be a string', queue.delete, None)

        self.assertRaisesRegexp(exception.AMQPInvalidArgument,
                                'if_unused should be a boolean', queue.delete,
                                '', None)

        self.assertRaisesRegexp(exception.AMQPInvalidArgument,
                                'if_empty should be a boolean', queue.delete,
                                '', True, None)
Beispiel #39
0
    def test_channel0_client_properties(self):
        channel = Channel0(FakeConnection())
        result = channel._client_properties()

        information = 'See https://github.com/eandersson/amqpstorm'
        python_version = 'Python %s' % platform.python_version()

        self.assertIsInstance(result, dict)
        self.assertTrue(result['capabilities']['authentication_failure_close'])
        self.assertTrue(result['capabilities']['consumer_cancel_notify'])
        self.assertTrue(result['capabilities']['publisher_confirms'])
        self.assertTrue(result['capabilities']['connection.blocked'])
        self.assertTrue(result['capabilities']['basic.nack'])
        self.assertEqual(result['information'], information)
        self.assertEqual(result['platform'], python_version)
Beispiel #40
0
    def test_basic_get_fails(self):
        def on_get_frame(*_):
            pass

        connection = FakeConnection(on_write=on_get_frame)
        channel = Channel(9, connection, 0.1)
        channel.set_state(Channel.OPEN)
        basic = Basic(channel)

        self.assertRaisesRegexp(AMQPChannelError,
                                'rpc requests .* \(.*\) took too long',
                                basic.get, 'travis-ci')

        self.assertFalse(channel.rpc._request)
        self.assertFalse(channel.rpc._response)
    def test_basic_reject_invalid_parameter(self):
        channel = Channel(0, FakeConnection(), 360)
        channel.set_state(Channel.OPEN)
        basic = Basic(channel)

        self.assertRaisesRegexp(exception.AMQPInvalidArgument,
                                'delivery_tag should be an integer',
                                basic.reject, 'travis-ci')

        self.assertRaisesRegexp(exception.AMQPInvalidArgument,
                                'delivery_tag should be an integer',
                                basic.reject, None)

        self.assertRaisesRegexp(exception.AMQPInvalidArgument,
                                'requeue should be a boolean', basic.reject, 1,
                                None)
Beispiel #42
0
    def test_with_for_request_with_custom_adapter(self):
        class Adapter(object):
            def check_for_errors(self):
                pass

        rpc = Rpc(FakeConnection(), timeout=1)
        uuid = rpc.register_request(['travis-ci'])

        def delivery_payload():
            time.sleep(0.1)
            rpc.on_frame(FakePayload(name='travis-ci'))

        thread = threading.Thread(target=delivery_payload)
        thread.start()

        rpc._wait_for_request(uuid, Adapter())
Beispiel #43
0
    def test_channel_build_inbound_messages(self):
        channel = Channel(0, FakeConnection(), 360)
        channel.set_state(channel.OPEN)

        message = self.message.encode('utf-8')
        message_len = len(message)

        deliver = specification.Basic.Deliver()
        header = ContentHeader(body_size=message_len)
        body = ContentBody(value=message)

        channel._inbound = [deliver, header, body]

        for msg in channel.build_inbound_messages(break_on_empty=True):
            self.assertIsInstance(msg.body, str)
            self.assertEqual(msg.body.encode('utf-8'), message)
Beispiel #44
0
    def test_channel_close_channel(self):
        channel = Channel(0, FakeConnection(), 360)

        # Set up Fake Channel.
        channel._inbound = [1, 2, 3]
        channel.set_state(channel.OPEN)
        channel._consumer_tags = [1, 2, 3]

        close_frame = specification.Channel.Close(reply_code=200,
                                                  reply_text='travis-ci')
        # Close Channel.
        channel._close_channel(close_frame)

        self.assertEqual(channel._inbound, [])
        self.assertEqual(channel._consumer_tags, [])
        self.assertEqual(channel._state, channel.CLOSED)
Beispiel #45
0
    def test_basic_qos_invalid_parameter(self):
        channel = Channel(0, FakeConnection(), 360)
        channel.set_state(Channel.OPEN)
        basic = Basic(channel)

        self.assertRaisesRegexp(exception.AMQPInvalidArgument,
                                'prefetch_count should be an integer',
                                basic.qos, 'unittest')

        self.assertRaisesRegexp(exception.AMQPInvalidArgument,
                                'prefetch_size should be an integer',
                                basic.qos, 1, 'unittest')

        self.assertRaisesRegexp(exception.AMQPInvalidArgument,
                                'global_ should be a boolean', basic.qos, 1, 1,
                                'unittest')
Beispiel #46
0
    def test_basic_nack_invalid_parameter(self):
        channel = Channel(0, FakeConnection(), 360)
        channel.set_state(Channel.OPEN)
        basic = Basic(channel)

        self.assertRaisesRegexp(exception.AMQPInvalidArgument,
                                'delivery_tag should be an integer or None',
                                basic.nack, 'unittest')

        self.assertRaisesRegexp(exception.AMQPInvalidArgument,
                                'multiple should be a boolean', basic.nack, 1,
                                None)

        self.assertRaisesRegexp(exception.AMQPInvalidArgument,
                                'requeue should be a boolean', basic.nack, 1,
                                True, None)
Beispiel #47
0
    def test_channel_build_message_empty_and_then_break(self):
        """Start building a message with an empty inbound queue,
            and send an empty ContentBody that should be ignored.

        :return:
        """
        channel = Channel(0, FakeConnection(), 360)
        channel.set_state(Channel.OPEN)
        channel._inbound = []

        def add_inbound():
            channel._inbound.append(ContentBody())

        threading.Timer(function=add_inbound, interval=0.1).start()

        self.assertFalse(channel._build_message_body(128))
Beispiel #48
0
    def test_channel_build_message_empty_and_raise(self):
        """Start building a message with an empty inbound queue,
            and raise when the channel is closed.

        :return:
        """
        channel = Channel(0, FakeConnection(), 360)
        channel.set_state(Channel.OPEN)
        channel._inbound = []

        def close_channel():
            channel.set_state(Channel.CLOSED)

        threading.Timer(function=close_channel, interval=0.1).start()

        self.assertRaises(AMQPChannelError, channel._build_message_body, 128)
    def test_basic_publish_invalid_parameter(self):
        channel = Channel(0, FakeConnection(), 360)
        channel.set_state(Channel.OPEN)
        basic = Basic(channel)

        self.assertRaisesRegexp(
            exception.AMQPInvalidArgument,
            'body should be a string',
            basic.publish, None, ''
        )

        self.assertRaisesRegexp(
            exception.AMQPInvalidArgument,
            'routing_key should be a string',
            basic.publish, '', None
        )

        self.assertRaisesRegexp(
            exception.AMQPInvalidArgument,
            'exchange should be a string',
            basic.publish, '', '', None
        )

        self.assertRaisesRegexp(
            exception.AMQPInvalidArgument,
            'properties should be a dict or None',
            basic.publish, '', '', '', []
        )

        self.assertRaisesRegexp(
            exception.AMQPInvalidArgument,
            'properties should be a dict or None',
            basic.publish, '', '', '', 1
        )

        self.assertRaisesRegexp(
            exception.AMQPInvalidArgument,
            'mandatory should be a boolean',
            basic.publish, '', '', '', {}, None
        )

        self.assertRaisesRegexp(
            exception.AMQPInvalidArgument,
            'immediate should be a boolean',
            basic.publish, '', '', '', {}, True, None
        )
Beispiel #50
0
    def test_basic_get_invalid_parameter(self):
        channel = Channel(0, FakeConnection(), 360)
        channel.set_state(Channel.OPEN)
        basic = Basic(channel)

        self.assertRaisesRegexp(exception.AMQPInvalidArgument,
                                'queue should be a string', basic.get, None)

        self.assertRaisesRegexp(exception.AMQPInvalidArgument,
                                'no_ack should be a boolean', basic.get, '',
                                'unittest')

        channel.consumer_tags.append('unittest')

        self.assertRaisesRegexp(
            exception.AMQPChannelError, "Cannot call 'get' when channel "
            "is set to consume", basic.get, '', True, 'unittest')
Beispiel #51
0
    def test_basic_publish_confirms_raises_on_invalid_frame(self):
        message = str(uuid.uuid4())

        def on_publish_return_invalid_frame(*_):
            channel.rpc.on_frame(spec_basic.Cancel())

        connection = FakeConnection(on_write=on_publish_return_invalid_frame)
        channel = Channel(9, connection, 0.01)
        channel.confirming_deliveries = True
        channel.set_state(Channel.OPEN)
        basic = Basic(channel)

        self.assertRaisesRegexp(exception.AMQPChannelError,
                                "rpc requests",
                                basic.publish,
                                body=message,
                                routing_key='unittest')
Beispiel #52
0
    def test_io_use_ssl_true(self):
        connection = FakeConnection()
        connection.parameters['ssl'] = True
        io = IO(connection.parameters)

        self.assertTrue(io.use_ssl)