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())
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)
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)
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)
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')
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)
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)
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)