Exemple #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())
Exemple #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())
Exemple #3
0
    def test_open_already(self):
        url = 'test-url'

        # test
        sender = Sender(url)
        sender.is_open = Mock(return_value=True)
        sender.open()

        # validation
        self.assertFalse(sender.connection.open.called)
Exemple #4
0
    def test_open_already(self):
        url = 'test-url'

        # test
        sender = Sender(url)
        sender.is_open = Mock(return_value=True)
        sender.open()

        # validation
        self.assertFalse(sender.connection.open.called)
Exemple #5
0
    def test_open(self, connection):
        url = 'test-url'

        # test
        sender = Sender(url)
        sender.is_open = Mock(return_value=False)
        sender.open()

        # validation
        connection.return_value.open.assert_called_once_with()
        connection.return_value.channel.assert_called_once_with()
        self.assertEqual(sender.channel, connection.return_value.channel.return_value)
Exemple #6
0
    def test_open(self, connection):
        url = 'test-url'

        # test
        sender = Sender(url)
        sender.is_open = Mock(return_value=False)
        sender.open()

        # validation
        connection.return_value.open.assert_called_once_with()
        connection.return_value.channel.assert_called_once_with()
        self.assertEqual(sender.channel, connection.return_value.channel.return_value)
Exemple #7
0
    def test_repair(self, connection):
        url = 'test-url'

        # test
        sender = Sender(url)
        sender.close = Mock()
        sender.repair()

        # validation
        sender.close.assert_called_once_with()
        sender.connection.close.assert_called_once_with()
        connection.return_value.open.assert_called_once_with()
        connection.return_value.channel.assert_called_once_with()
        self.assertEqual(sender.channel, connection.return_value.channel.return_value)
Exemple #8
0
    def test_repair(self, connection):
        url = 'test-url'

        # test
        sender = Sender(url)
        sender.close = Mock()
        sender.repair()

        # validation
        sender.close.assert_called_once_with()
        sender.connection.close.assert_called_once_with()
        connection.return_value.open.assert_called_once_with()
        connection.return_value.channel.assert_called_once_with()
        self.assertEqual(sender.channel, connection.return_value.channel.return_value)
Exemple #9
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')
Exemple #10
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)
Exemple #11
0
    def test_init(self, connection):
        url = 'test-url'

        # test
        sender = Sender(url)

        # validation
        connection.assert_called_once_with(url)
        self.assertTrue(isinstance(sender, BaseSender))
        self.assertEqual(sender.url, url)
        self.assertEqual(sender.connection, connection.return_value)
        self.assertEqual(sender.channel, None)
Exemple #12
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)
Exemple #13
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')
Exemple #14
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)