Exemplo n.º 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()
Exemplo n.º 2
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()
Exemplo n.º 3
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)
Exemplo n.º 4
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)
Exemplo n.º 5
0
 def test_init(self):
     name = 'test'
     queue = Queue(name)
     self.assertEqual(queue.name, name)
     self.assertEqual(queue.exclusive, False)
     self.assertEqual(queue.auto_delete, False)
     self.assertEqual(queue.expiration, 0)
Exemplo n.º 6
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)
Exemplo n.º 7
0
 def test_all(self):
     cat = Node('cat')
     dog = Queue('dog')
     domain = _Domain()
     domain.add(cat)
     # add
     domain.add(dog)
     self.assertEqual(domain.content, {'Node::cat': cat, 'Queue::dog': dog})
     # contains
     self.assertTrue(domain.contains(dog))
     self.assertFalse(domain.contains(Node('dog')))
     self.assertTrue(dog in domain)
     # find
     self.assertEqual(domain.find(dog.domain_id), dog)
     # not found
     self.assertRaises(NotFound, domain.find, '123')
     # len
     self.assertEqual(len(domain), 2)
     # delete
     domain.delete(dog)
     self.assertEqual(domain.content, {'Node::cat': cat})
Exemplo n.º 8
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)