Example #1
0
    def test_open(self, _connection, uuid):
        url = 'url-test'
        uuid.return_value = '5138'
        connection = Mock()
        _connection.return_value = connection
        session = Mock()
        session.close.side_effect = ValueError
        sender = Mock()
        sender.close.side_effect = ValueError
        receiver = Mock()
        receiver.close.side_effect = ValueError
        connection.session.return_value = session
        session.receiver.return_value = receiver
        session.sender.return_value = sender
        reply_to = model.REPLY_TO % uuid.return_value

        # test
        method = Method(url, '', {})
        method.open()

        # validation
        connection.open.assert_called_once_with()
        session.sender.assert_called_once_with(model.ADDRESS)
        session.receiver.assert_called_once_with(reply_to)
        self.assertEqual(method.connection, connection)
        self.assertEqual(method.sender, sender)
        self.assertEqual(method.receiver, receiver)
Example #2
0
    def test_open_already(self):
        # test
        method = Method('', '', {})
        method.is_open = Mock(return_value=True)
        method.open()

        # validation
        self.assertFalse(method.connection.open.called)
Example #3
0
    def test_call(self, message, uuid):
        url = 'url-test'
        name = model.CREATE
        arguments = {'a': 1}

        # test
        method = Method(url, name, arguments)
        method.reply_to = '234'
        method.open = Mock()
        method.close = Mock()
        method.session = Mock()
        method.sender = Mock()
        method.receiver = Mock()
        method.on_reply = Mock()
        method()

        # validation
        method.open.assert_called_once_with()
        message.assert_called_once_with(
            content=method.content,
            reply_to=method.reply_to,
            properties=method.properties,
            correlation_id=str(uuid.return_value).encode(),
            subject=model.SUBJECT
        )

        method.session.acknowledge.assert_called_once_with()
        method.sender.send.assert_called_once_with(message.return_value)
        method.on_reply.assert_called_once_with(method.receiver.fetch.return_value)
        method.close.assert_called_once_with()