Beispiel #1
0
 def test_is_open(self):
     url = 'test-url'
     sender = Sender(url)
     # closed
     self.assertFalse(sender.is_open())
     # open
     sender.channel = Mock()
     self.assertTrue(sender.is_open())
Beispiel #2
0
 def test_is_open(self):
     url = 'test-url'
     sender = Sender(url)
     # closed
     self.assertFalse(sender.is_open())
     # open
     sender.channel = Mock()
     self.assertTrue(sender.is_open())
Beispiel #3
0
    def test_close(self):
        connection = Mock()
        channel = Mock()
        # test
        sender = Sender(None)
        sender.connection = connection
        sender.channel = channel
        sender.is_open = Mock(return_value=True)
        sender.close()

        # validation
        channel.close.assert_called_once_with()
        self.assertFalse(connection.close.called)
Beispiel #4
0
    def test_send(self, build):
        ttl = 10
        address = 'jeff'
        content = 'hello'

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

        # validation
        build.assert_called_once_with(content, ttl, sender.durable)
        sender.channel.basic_publish.assert_called_once_with(
            build.return_value,
            mandatory=True,
            exchange='',
            routing_key='jeff')
Beispiel #5
0
    def test_send(self, build):
        ttl = 10
        address = 'jeff'
        content = 'hello'

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

        # validation
        build.assert_called_once_with(content, ttl, sender.durable)
        sender.channel.basic_publish.assert_called_once_with(
            build.return_value,
            mandatory=True,
            exchange='',
            routing_key='jeff')
Beispiel #6
0
    def test_send_exchange(self, build):
        ttl = 10
        exchange = 'amq.direct'
        key = 'bar'
        address = '/'.join((exchange, key))
        content = 'hello'

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

        # validation
        build.assert_called_once_with(content, ttl, sender.durable)
        sender.channel.basic_publish.assert_called_once_with(
            build.return_value,
            mandatory=True,
            exchange=exchange,
            routing_key=key)
Beispiel #7
0
    def test_send_exchange(self, build):
        ttl = 10
        exchange = 'amq.direct'
        key = 'bar'
        address = '/'.join((exchange, key))
        content = 'hello'

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

        # validation
        build.assert_called_once_with(content, ttl, sender.durable)
        sender.channel.basic_publish.assert_called_once_with(
            build.return_value,
            mandatory=True,
            exchange=exchange,
            routing_key=key)