

def test_check_transaction(self):
    flexmock(zk.ZKTransaction)
    zk.ZKTransaction.should_receive('get_transaction_prefix_path').with_args(self.appid).and_return('/rootpath')
    zk.ZKTransaction.should_receive('is_blacklisted').and_return(False)
    fake_zookeeper = flexmock(name='fake_zoo', exists='exists', connected=(lambda : True))
    fake_zookeeper.should_receive('start')
    fake_zookeeper.should_receive('retry').with_args('exists', str).and_return(True)
    flexmock(kazoo.client)
    kazoo.client.should_receive('KazooClient').and_return(fake_zookeeper)
    transaction = zk.ZKTransaction(host='something', start_gc=False)
    self.assertEquals(True, transaction.check_transaction(self.appid, 1))
    zk.ZKTransaction.should_receive('is_blacklisted').and_return(True)
    self.assertRaises(zk.ZKTransactionException, transaction.check_transaction, self.appid, 1)
    zk.ZKTransaction.should_receive('is_blacklisted').and_return(False)
    fake_zookeeper.should_receive('retry').with_args('exists', str).and_return(False)
    self.assertRaises(zk.ZKTransactionException, transaction.check_transaction, self.appid, 1)

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