コード例 #1
0
    def test_procedural_interface(self):
        backend = mock.Mock(spec=LockBackend)
        key = "lock"
        duration = 60
        routing_key = None

        lock = Lock(backend, key, duration, routing_key)

        lock.acquire()
        backend.acquire.assert_called_once_with(key, duration, routing_key)

        lock.locked()
        backend.locked.assert_called_once_with(key, routing_key)

        lock.release()
        backend.release.assert_called_once_with(key, routing_key)

        backend.acquire.side_effect = Exception("Boom!")
        with pytest.raises(UnableToAcquireLock):
            lock.acquire()