Exemple #1
0
 def test_reply_already_exists(self):
     values = {"error_code": model.EEXIST, "error_text": "just failed"}
     body = {"_values": values}
     properties = {"qmf.opcode": "_exception"}
     reply = Mock(body=body, properties=properties)
     method = Method("", "", {})
     method.on_reply(reply)
Exemple #2
0
 def test_reply_already_exists(self):
     values = {'error_code': model.EEXIST, 'error_text': 'just failed'}
     body = {'_values': values}
     properties = {'qmf.opcode': '_exception'}
     reply = Mock(body=body, properties=properties)
     method = Method('', '', {})
     method.on_reply(reply)
Exemple #3
0
    def test_repair(self, _connection, uuid):
        url = 'url-test'
        uuid.return_value = '5138'
        connection = Mock()
        _connection.return_value = connection
        sender = Mock()
        sender.close.side_effect = ValueError
        receiver = Mock()
        receiver.close.side_effect = ValueError
        connection.receiver.return_value = receiver
        connection.sender.return_value = sender

        # test
        method = Method(url, '', {})
        method.close = Mock()
        method.repair()

        # validation
        method.close.assert_called_once_with()
        connection.close.assert_called_once_with()
        connection.open.assert_called_once_with()
        connection.sender.assert_called_once_with(model.ADDRESS)
        connection.receiver.assert_called_once_with(model.ADDRESS,
                                                    dynamic=True)
        self.assertEqual(method.connection, connection)
        self.assertEqual(method.sender, sender)
        self.assertEqual(method.receiver, receiver)
Exemple #4
0
    def test_repair(self, _connection, uuid):
        url = "url-test"
        uuid.return_value = "5138"
        connection = Mock()
        _connection.return_value = connection
        sender = Mock()
        sender.close.side_effect = ValueError
        receiver = Mock()
        receiver.close.side_effect = ValueError
        connection.receiver.return_value = receiver
        connection.sender.return_value = sender

        # test
        method = Method(url, "", {})
        method.close = Mock()
        method.repair()

        # validation
        method.close.assert_called_once_with()
        connection.close.assert_called_once_with()
        connection.open.assert_called_once_with()
        connection.sender.assert_called_once_with(model.ADDRESS)
        connection.receiver.assert_called_once_with(model.ADDRESS, dynamic=True)
        self.assertEqual(method.connection, connection)
        self.assertEqual(method.sender, sender)
        self.assertEqual(method.receiver, receiver)
Exemple #5
0
 def test_reply_succeeded(self):
     body = ''
     properties = {
         'qmf.opcode': ''
     }
     reply = Mock(body=body, properties=properties)
     method = Method('', '', {})
     method.on_reply(reply)
Exemple #6
0
 def test_reply_already_exists(self):
     values = {
         'error_code': model.EEXIST,
         'error_text': 'just failed'
     }
     body = {'_values': values}
     properties = {
         'qmf.opcode': '_exception'
     }
     reply = Mock(body=body, properties=properties)
     method = Method('', '', {})
     method.on_reply(reply)
Exemple #7
0
 def test_reply_failed(self):
     values = {'error_code': 18, 'error_text': 'just failed'}
     body = {'_values': values}
     properties = {'qmf.opcode': '_exception'}
     reply = Mock(body=body, properties=properties)
     method = Method('', '', {})
     self.assertRaises(Error, method.on_reply, reply)
Exemple #8
0
 def test_properties(self):
     method = Method('', model.CREATE, {})
     self.assertEqual(
         method.properties, {
             'qmf.opcode': '_method_request',
             'x-amqp-0-10.app-id': 'qmf2',
             'method': 'request'
         })
Exemple #9
0
 def test_body(self):
     name = model.CREATE
     arguments = {'a': 1}
     method = Method('', name, arguments)
     self.assertEqual(
         method.body, {
             '_object_id': model.OBJECT_ID,
             '_method_name': name,
             '_arguments': arguments
         })
Exemple #10
0
 def test_init(self, _connection):
     url = 'test-url'
     name = model.CREATE
     arguments = {'a': 1}
     method = Method(url, name, arguments)
     _connection.assert_called_once_with(url)
     self.assertEqual(method.url, url)
     self.assertEqual(method.name, name)
     self.assertEqual(method.arguments, arguments)
     self.assertEqual(method.connection, _connection.return_value)
     self.assertEqual(method.sender, None)
     self.assertEqual(method.receiver, None)
Exemple #11
0
    def test_call(self, _connection, message, uuid):
        url = "url-test"
        name = model.CREATE
        arguments = {"a": 1}
        uuid.return_value = "5138"
        connection = Mock()
        _connection.return_value = connection
        sender = Mock()
        sender.close.side_effect = ValueError
        receiver = Mock()
        receiver.close.side_effect = ValueError
        connection.receiver.return_value = receiver
        connection.sender.return_value = sender

        # test
        method = Method(url, name, arguments)
        method.send = Mock()
        method.on_reply = Mock()
        method()

        # validation
        _connection.assert_called_once_with(url)
        connection.open.assert_called_once_with()

        connection.sender.assert_called_once_with(model.ADDRESS)
        connection.receiver.assert_called_once_with(model.ADDRESS, dynamic=True)

        message.assert_called_once_with(
            body=method.body,
            reply_to=receiver.remote_source.address,
            properties=method.properties,
            correlation_id=str(uuid.return_value),
            subject=model.SUBJECT,
        )

        method.send.assert_called_once_with(message.return_value)
        method.on_reply.assert_called_once_with(receiver.receive.return_value)
        sender.close.assert_called_once_with()
        receiver.close.assert_called_once_with()
Exemple #12
0
    def test_call(self, _connection, message, uuid):
        url = 'url-test'
        name = model.CREATE
        arguments = {'a': 1}
        uuid.return_value = '5138'
        connection = Mock()
        _connection.return_value = connection
        sender = Mock()
        sender.close.side_effect = ValueError
        receiver = Mock()
        receiver.close.side_effect = ValueError
        connection.receiver.return_value = receiver
        connection.sender.return_value = sender

        # test
        method = Method(url, name, arguments)
        method.send = Mock()
        method.on_reply = Mock()
        method()

        # validation
        _connection.assert_called_once_with(url)
        connection.open.assert_called_once_with()

        connection.sender.assert_called_once_with(model.ADDRESS)
        connection.receiver.assert_called_once_with(model.ADDRESS,
                                                    dynamic=True)

        message.assert_called_once_with(
            body=method.body,
            reply_to=receiver.remote_source.address,
            properties=method.properties,
            correlation_id=str(uuid.return_value),
            subject=model.SUBJECT)

        method.send.assert_called_once_with(message.return_value)
        method.on_reply.assert_called_once_with(receiver.receive.return_value)
        sender.close.assert_called_once_with()
        receiver.close.assert_called_once_with()
Exemple #13
0
    def test_close(self):
        connection = Mock()
        sender = Mock()
        receiver = Mock()
        method = Method('', '', {})
        method.connection = connection
        method.sender = sender
        method.receiver = receiver

        # test
        method.close()

        # validation
        receiver.close.assert_called_once_with()
        sender.close.assert_called_once_with()
Exemple #14
0
    def test_close(self):
        connection = Mock()
        sender = Mock()
        receiver = Mock()
        method = Method("", "", {})
        method.connection = connection
        method.sender = sender
        method.receiver = receiver

        sender.close.side_effect = ValueError
        receiver.close.side_effect = ValueError

        # test
        method.close()

        # validation
        receiver.close.assert_called_once_with()
        sender.close.assert_called_once_with()
Exemple #15
0
 def test_open_already(self):
     method = Method('', '', {})
     method.is_open = Mock(return_value=True)
     method.open()
     self.assertFalse(method.connection.open.called)
Exemple #16
0
 def test_send(self):
     request = Mock()
     method = Method('', '', {})
     method.sender = Mock()
     method.send(request)
     method.sender.send.assert_called_with(request)
Exemple #17
0
 def test_open_already(self):
     method = Method("", "", {})
     method.is_open = Mock(return_value=True)
     method.open()
     self.assertFalse(method.connection.open.called)
Exemple #18
0
 def test_reply_succeeded(self):
     body = ""
     properties = {"qmf.opcode": ""}
     reply = Mock(body=body, properties=properties)
     method = Method("", "", {})
     method.on_reply(reply)
Exemple #19
0
 def test_send(self):
     request = Mock()
     method = Method("", "", {})
     method.sender = Mock()
     method.send(request)
     method.sender.send.assert_called_with(request)