def testAcquireAccount(self): account1 = Account('user1', 'test') self.assertRaises(ValueError, self.am.acquire_account) self.am.add_account(account1) self.assertEqual(self.am.acquire_account(), account1) account1.release() account2 = Account('user2', 'test') self.am.add_account(account2) self.assertEqual(self.am.acquire_account(account2), account2) account2.release() account = self.am.acquire_account() self.assertNotEqual(account, None) account.release() account3 = Account('user3', 'test') pool = AccountPool() pool.add_account(account3) self.am.add_pool(pool) self.assertEqual(self.am.acquire_account(account2), account2) account2.release() self.assertEqual(self.am.acquire_account(account3), account3) account3.release() account = self.am.acquire_account() self.assertNotEqual(account, None) account.release()
def setUp(self): self.user1 = 'testuser1' self.password1 = 'test1' self.account1 = Account(self.user1, self.password1) self.user2 = 'testuser2' self.password2 = 'test2' self.account2 = Account(self.user2, self.password2) self.accm = AccountPool()
def testGetAccountFromHash(self): pool1 = AccountPool() acc1 = Account('user1') pool1.add_account(acc1) self.am.add_pool(pool1) acc2 = Account('user2') self.am.add_account(acc2) self.assertEqual(self.am.get_account_from_hash(acc1.__hash__()), acc1) self.assertEqual(self.am.get_account_from_hash(acc2.__hash__()), acc2)
def testAddPool(self): self.assertEqual(0, self.am.default_pool.n_accounts()) account = Account('user', 'test') self.am.add_account(account) self.assertEqual(1, self.am.default_pool.n_accounts()) def match_cb(host): self.data['match-called'] = True self.data['host'] = host return True # Replace the default pool. pool1 = AccountPool() self.am.add_pool(pool1) self.assertEqual(self.am.default_pool, pool1) # Add another pool, making sure that it does not replace # the default pool. pool2 = AccountPool() pool2.add_account(self.account) self.am.add_pool(pool2, match_cb) self.assertEqual(self.am.default_pool, pool1)
def testReleaseAccounts(self): account1 = Account('foo') account2 = Account('bar') pool = AccountPool() pool.add_account(account1) pool.add_account(account2) pool.acquire_account(account1, 'one') pool.acquire_account(account2, 'two') self.assert_(account1 not in pool.unlocked_accounts) self.assert_(account2 not in pool.unlocked_accounts) pool.release_accounts('one') self.assert_(account1 in pool.unlocked_accounts) self.assert_(account2 not in pool.unlocked_accounts) pool.release_accounts('one') self.assert_(account1 in pool.unlocked_accounts) self.assert_(account2 not in pool.unlocked_accounts) pool.release_accounts('two') self.assert_(account1 in pool.unlocked_accounts) self.assert_(account2 in pool.unlocked_accounts)
def testReleaseAccounts(self): account1 = Account('foo') pool = AccountPool() pool.add_account(account1) pool.acquire_account(account1, 'one') self.am.add_pool(pool, lambda x: None) account2 = Account('bar') self.am.add_account(account2) self.am.acquire_account(account2, 'two') self.assert_(account1 not in pool.unlocked_accounts) self.assert_(account2 not in self.am.default_pool.unlocked_accounts) self.am.release_accounts('two') self.assert_(account1 not in pool.unlocked_accounts) self.assert_(account2 in self.am.default_pool.unlocked_accounts) self.am.release_accounts('one') self.assert_(account1 in pool.unlocked_accounts) self.assert_(account2 in self.am.default_pool.unlocked_accounts)
def _init_account_pool_from_name(self, name): accounts = self._get_account_list_from_name(name) return AccountPool(accounts)
def testConstructor(self): accm = AccountPool() self.assertEqual(accm.n_accounts(), 0) accm = AccountPool([self.account1, self.account2]) self.assertEqual(accm.n_accounts(), 2)
def reset(self): """ Removes all account pools. """ self.default_pool = AccountPool() self.pools = []
def _init_account_pool_from_name(self, name): print 'Creating account pool "%s"...' % name accounts = self._get_account_list_from_name(name) return AccountPool(accounts)