def test_persistent_false_new(self): """ When *persistent=False* is passed a new pool is returned each time. """ pool1 = default_pool(self.reactor, None, persistent=False) pool2 = default_pool(self.reactor, None, persistent=False) self.assertIsNot(pool1, pool2)
def test_cached_global_pool(self): """ When *persistent=True* or *persistent=None* is passed the pool created is cached as the global pool. """ pool1 = default_pool(self.reactor, None, None) pool2 = default_pool(self.reactor, None, True) self.assertEqual(pool1, pool2)
def test_specified_pool(self): """ When the user passes a pool it is returned directly. The *persistent* argument is ignored. It is not cached as the global pool. """ user_pool = HTTPConnectionPool(self.reactor, persistent=True) pool1 = default_pool(self.reactor, user_pool, None) pool2 = default_pool(self.reactor, user_pool, True) pool3 = default_pool(self.reactor, user_pool, False) self.assertIs(pool1, user_pool) self.assertIs(pool2, user_pool) self.assertIs(pool3, user_pool) self.assertIsNot(get_global_pool(), user_pool)
def test_pool_none_persistent_none(self): """ When *persistent=None* is passed a _persistent_ pool is created for backwards compatibility. """ pool = default_pool(self.reactor, None, None) self.assertTrue(pool.persistent)
def test_persistent_false_not_stored(self): """ When *persistent=False* is passed the resulting pool is not stored as the global pool. """ pool = default_pool(self.reactor, None, persistent=False) self.assertIsNot(pool, get_global_pool())
def test_persistent_false(self): """ When *persistent=False* is passed a non-persistent pool is created. """ pool = default_pool(self.reactor, None, False) self.assertTrue(isinstance(pool, HTTPConnectionPool)) self.assertFalse(pool.persistent)
def test_pool_none_persistent_true(self): """ When *persistent=True* is passed a persistent pool is created and stored as the global pool. """ pool = default_pool(self.reactor, None, True) self.assertTrue(isinstance(pool, HTTPConnectionPool)) self.assertTrue(pool.persistent)
def no_verify_agent(**kwargs): reactor = api.default_reactor(kwargs.get('reactor')) pool = api.default_pool( reactor, kwargs.get('pool'), kwargs.get('persistent')) no_verify_agent.agent = api.Agent( reactor, contextFactory=NoVerifySSLContextFactory(), pool=pool ) return no_verify_agent.agent
def _noVerifyAgent( *args, **kwargs ): """Agent that suppresses TLS verification treq.get(..., agent=_noVerifyAgent()) Returns the same agent every time... """ if getattr(_noVerifyAgent, 'agent',None) is None: from treq import api reactor = api.default_reactor(kwargs.get('reactor')) pool = api.default_pool(reactor, kwargs.get('pool'), kwargs.get('persistent')) _noVerifyAgent.agent = api.Agent( reactor, contextFactory=_NoVerifyContextFactory(), pool=pool ) return _noVerifyAgent.agent