Example #1
0
    def test_purge(self, _find, _reader):
        name = 'test'
        _find.return_value = Mock()
        queued = [
            Mock(),
            Mock(),
            None
        ]

        def _open():
            _reader.return_value.open()
            return _reader.return_value

        def _close(*unused):
            _reader.return_value.close()

        _reader.return_value.__enter__.side_effect = _open
        _reader.return_value.__exit__.side_effect = _close
        _reader.return_value.get.side_effect = queued

        # test
        queue = Queue(name)
        queue.purge(TEST_URL)

        # validation
        _reader.assert_called_once_with(queue, url=TEST_URL)
        _reader.return_value.open.assert_called_once_with()
        _reader.return_value.close.assert_called_once_with()
        queued[0].ack.assert_called_once_with()
        queued[1].ack.assert_called_once_with()
Example #2
0
    def test_delete(self, _find):
        plugin = Mock()
        _find.return_value = plugin
        name = 'test'

        # test
        queue = Queue(name)
        queue.delete(TEST_URL)

        # validation
        plugin.Queue.assert_called_with(name)
        impl = plugin.Queue()
        impl.delete.assert_called_with(TEST_URL)
Example #3
0
    def test_declare(self, _find):
        plugin = Mock()
        _find.return_value = plugin
        name = 'test'
        queue = Queue(name)
        queue.durable = 1
        queue.auto_delete = 2
        queue.expiration = 3
        queue.exclusive = 4

        # test
        queue.declare(TEST_URL)

        # validation
        plugin.Queue.assert_called_with(name)
        impl = plugin.Queue()
        impl.declare.assert_called_with(TEST_URL)
        self.assertEqual(impl.durable, queue.durable)
        self.assertEqual(impl.auto_delete, queue.auto_delete)
        self.assertEqual(impl.expiration, queue.expiration)
        self.assertEqual(impl.exclusive, queue.exclusive)