示例#1
0
 def test_is_open(self):
     url = 'test-url'
     sender = Sender(url)
     sender.connection = Mock()
     sender.connection.is_open.return_value = False
     # closed
     self.assertFalse(sender.is_open())
     # open
     sender.connection = Mock()
     sender.connection.is_open.return_value = True
     self.assertTrue(sender.is_open())
示例#2
0
    def test_close(self):
        connection = Mock()
        connection.close.side_effect = ValueError

        # test
        sender = Sender(None)
        sender.connection = connection
        sender.is_open = Mock(return_value=True)
        sender.close()

        # validation
        self.assertFalse(connection.close.called)
示例#3
0
    def test_send(self, builder):
        ttl = 10
        address = 'q1'
        content = 'hello'

        # test
        sender = Sender('')
        sender.durable = 18
        sender.connection = Mock()
        sender.send(address, content, ttl=ttl)

        # validation
        builder.assert_called_once_with(content, ttl, sender.durable)
        sender.connection.sender.assert_called_once_with(address)
        _sender = sender.connection.sender.return_value
        _sender.send.assert_called_once_with(builder.return_value)
        _sender.close.assert_called_once_with()