

def test_release_lock(self):
    flexmock(zk.ZKTransaction)
    zk.ZKTransaction.should_receive('check_transaction')
    zk.ZKTransaction.should_receive('get_transaction_path').and_return('/rootpath')
    zk.ZKTransaction.should_receive('get_transaction_lock_list_path').and_return('/rootpath')
    zk.ZKTransaction.should_receive('is_xg').and_return(False)
    fake_zookeeper = flexmock(name='fake_zoo', exists='exists', get='get', delete='delete', delete_async='delete_async', get_children='get_children', connected=(lambda : True))
    fake_zookeeper.should_receive('start')
    fake_zookeeper.should_receive('retry').with_args('exists', str).and_return(True)
    fake_zookeeper.should_receive('retry').with_args('get', str).and_return(['/1/2/3'])
    fake_zookeeper.should_receive('retry').with_args('delete_async', str)
    fake_zookeeper.should_receive('retry').with_args('delete', str)
    fake_zookeeper.should_receive('retry').with_args('get_children', str).and_return(['1', '2'])
    flexmock(kazoo.client)
    kazoo.client.should_receive('KazooClient').and_return(fake_zookeeper)
    transaction = zk.ZKTransaction(host='something', start_gc=False)
    self.assertEquals(True, transaction.release_lock(self.appid, 1))
    zk.ZKTransaction.should_receive('is_xg').and_return(True)
    self.assertEquals(True, transaction.release_lock(self.appid, 1))
    zk.ZKTransaction.should_receive('is_xg').and_return(False)
    fake_zookeeper.should_receive('retry').with_args('get', str).and_raise(kazoo.exceptions.NoNodeError)
    self.assertRaises(zk.ZKTransactionException, transaction.release_lock, self.appid, 1)

dataset/ETHPy150Open AppScale/appscale/AppDB/test/unit/test_zookeeper.py TestZookeeperTransaction.test_release_lock/original