Esempio n. 1
0
 def testCreatePipe(self):
     account = Account('user', 'test')
     self.accm.add_account(account)
     pipe = self.queue._create_pipe()
     pipe.send(('acquire-account', None))
     response = pipe.recv()
     expected = (account.__hash__(), account.get_name(),
                 account.get_password(),
                 account.get_authorization_password(), account.get_key())
     self.assertEqual(response, expected)
     pipe.send(('release-account', account.__hash__()))
     response = pipe.recv()
     self.assertEqual(response, 'ok')
     pipe.close()
Esempio n. 2
0
 def testCreatePipe(self):
     account = Account('user', 'test')
     self.accm.add_account(account)
     pipe = self.queue._create_pipe()
     pipe.send(('acquire-account', None))
     response = pipe.recv()
     expected = (account.__hash__(),
                 account.get_name(),
                 account.get_password(),
                 account.get_authorization_password(),
                 account.get_key())
     self.assertEqual(response, expected)
     pipe.send(('release-account', account.__hash__()))
     response = pipe.recv()
     self.assertEqual(response, 'ok')
     pipe.close()
Esempio n. 3
0
    def testAddAccountPool(self):
        self.assertEqual(0, self.accm.default_pool.n_accounts())
        account = Account('user', 'test')
        self.queue.add_account(account)
        self.assertEqual(1, self.accm.default_pool.n_accounts())

        def match_cb(data, host):
            data['match-called'].value = True
            return True

        def start_cb(data, job, host, conn):
            account = conn.account_factory(None)
            data['start-called'].value = True
            data['account-hash'].value = account.__hash__()
            account.release()

        # Replace the default pool.
        pool1 = AccountPool()
        self.queue.add_account_pool(pool1)
        self.assertEqual(self.accm.default_pool, pool1)

        # Add another pool, making sure that it does not replace
        # the default pool.
        pool2 = AccountPool()
        account2 = Account('user', 'test')
        pool2.add_account(account2)

        match_called = Value(ctypes.c_bool, False)
        start_called = Value(ctypes.c_bool, False)
        account_hash = Value(ctypes.c_long, 0)
        data = {
            'match-called': match_called,
            'start-called': start_called,
            'account-hash': account_hash
        }
        self.queue.add_account_pool(pool2, partial(match_cb, data))
        self.assertEqual(self.accm.default_pool, pool1)

        # Make sure that pool2 is chosen (because the match function
        # returns True).
        self.queue.run('dummy://dummy', partial(start_cb, data))
        self.queue.shutdown()
        data = dict((k, v.value) for (k, v) in data.iteritems())
        self.assertEqual(
            data, {
                'match-called': True,
                'start-called': True,
                'account-hash': account2.__hash__()
            })
Esempio n. 4
0
    def testAddAccountPool(self):
        self.assertEqual(0, self.accm.default_pool.n_accounts())
        account = Account('user', 'test')
        self.queue.add_account(account)
        self.assertEqual(1, self.accm.default_pool.n_accounts())

        def match_cb(data, host):
            data['match-called'].value = True
            return True

        def start_cb(data, job, host, conn):
            account = conn.account_factory(None)
            data['start-called'].value = True
            data['account-hash'].value = account.__hash__()
            account.release()

        # Replace the default pool.
        pool1 = AccountPool()
        self.queue.add_account_pool(pool1)
        self.assertEqual(self.accm.default_pool, pool1)

        # Add another pool, making sure that it does not replace
        # the default pool.
        pool2 = AccountPool()
        account2 = Account('user', 'test')
        pool2.add_account(account2)

        match_called = Value(ctypes.c_bool, False)
        start_called = Value(ctypes.c_bool, False)
        account_hash = Value(ctypes.c_long, 0)
        data = {'match-called': match_called,
                'start-called': start_called,
                'account-hash': account_hash}
        self.queue.add_account_pool(pool2, partial(match_cb, data))
        self.assertEqual(self.accm.default_pool, pool1)

        # Make sure that pool2 is chosen (because the match function
        # returns True).
        self.queue.run('dummy://dummy', partial(start_cb, data))
        self.queue.shutdown()
        data = dict((k, v.value) for (k, v) in list(data.items()))
        self.assertEqual(data, {'match-called': True,
                                'start-called': True,
                                'account-hash': account2.__hash__()})
Esempio n. 5
0
 def testGetAccountFromHash(self):
     account = Account('user', 'test')
     thehash = account.__hash__()
     self.accm.add_account(account)
     self.assertEqual(self.accm.get_account_from_hash(thehash), account)
Esempio n. 6
0
 def testGetAccountFromHash(self):
     account = Account('user', 'test')
     thehash = account.__hash__()
     self.accm.add_account(account)
     self.assertEqual(self.accm.get_account_from_hash(thehash), account)