def test_coopyproxy_take_snapshot(self): from coopy.base import CoopyProxy import os os.mkdir('wiki') class PassPublisher(object): def close(self): pass def receive(self, message): pass def receive_before(self, message): pass def receive_exception(self, message): pass proxy = CoopyProxy(Wiki(), [PassPublisher()]) # mock testing proxy.lock = mock.MagicMock() proxy.create_page('id', 'content', None) proxy.take_snapshot() proxy.lock.acquire.assert_called() proxy.lock.release.assert_called() proxy.close()
def test_coopyproxy_unlocked(self): from coopy.base import CoopyProxy import os os.mkdir('wiki') class PassPublisher(object): def close(self): pass def receive(self, message): pass def receive_before(self, message): pass def receive_exception(self, message): pass proxy = CoopyProxy(Wiki(), [PassPublisher()]) proxy.create_page('id', 'content', None) # we're checking that system remains unlocked after a method execution # thus raising a RuntimeError on a release() with pytest.raises(RuntimeError): proxy.lock.release() # mock testing proxy.lock = mock.MagicMock() proxy.create_page('id', 'content', None) proxy.lock.acquire.assert_called_with(1) proxy.lock.release.assert_called() proxy.unlocked_method() proxy.lock.acquire.assert_not_called() proxy.close()