def test_it_with_registry(self): from pyramid.registry import Registry from pyramid.threadlocal import manager registry = Registry() self._callFUT(registry=registry) current = manager.get() self.assertEqual(current['registry'], registry)
def test_it_with_request(self): from pyramid.threadlocal import manager request = object() self._callFUT(request=request) current = manager.get() self.assertEqual(current["request"], request)
def test_it_with_request(self): from pyramid.threadlocal import manager request = object() self._callFUT(request=request) current = manager.get() self.assertEqual(current['request'], request)
def test_miss_w_persistent_context(self): from pyramid.threadlocal import manager context = self._makeContext(_p_jar=object()) request = self._makeRequest(context=context) manager.get()['request'] = request environ = request.environ credentials = {'login': '******', 'password': '******'} plugin = self._makeOne() self.assertEqual(plugin.authenticate(environ, credentials), None)
def test_it_with_request(self): from zope.component import getSiteManager from pyramid.threadlocal import manager request = object() try: self._callFUT(request=request) current = manager.get() self.assertEqual(current['request'], request) finally: getSiteManager.reset() manager.clear()
def test_it_with_registry(self): from pyramid.registry import Registry from zope.component import getSiteManager from pyramid.threadlocal import manager registry = Registry() try: self._callFUT(registry=registry) current = manager.get() self.assertEqual(current['registry'], registry) finally: getSiteManager.reset() manager.clear()
def test_it_defaults(self): from pyramid.threadlocal import manager from pyramid.threadlocal import get_current_registry from pyramid.registry import Registry old = True manager.push(old) config = self._callFUT() current = manager.get() self.assertFalse(current is old) self.assertEqual(config.registry, current['registry']) self.assertEqual(current['registry'].__class__, Registry) self.assertEqual(current['request'], None) self._assertSMHook(get_current_registry)
def test_hit_w_persistent_context_non_root(self): from pyramid.threadlocal import manager root = self._makeContext(_p_jar=object()) self._populate(root) context = self._makeContext(_p_jar=object(), __parent__=root, cartouche=object(), # ignored ) request = self._makeRequest(context=context) manager.get()['request'] = request environ = request.environ credentials = {'login': '******', 'password': '******'} plugin = self._makeOne() self.assertEqual(plugin.authenticate(environ, credentials), 'UUID')
def test_defaults(self): from pyramid.threadlocal import manager registry = DummyRegistry() old = {'registry':registry} hook = lambda *arg: None try: self._setSMHook(hook) manager.push(old) self._callFUT() current = manager.get() self.assertNotEqual(current, old) self.assertEqual(registry.inited, 2) finally: result = getSiteManager.sethook(None) self.assertNotEqual(result, hook)
def _threadContext(self): # IMPORTANT: this assumes that APScheduler invokes jobs in a separate # thread per job (as documented)... # TODO: this needs confirmation! if self.appreg is None: yield else: from pyramid.threadlocal import manager reg = dict(manager.get()) reg['registry'] = self.appreg manager.push(reg) try: yield finally: manager.pop()
def test_registry_cannot_be_inited(self): from pyramid.threadlocal import manager registry = DummyRegistry() def raiseit(name): raise TypeError registry.__init__ = raiseit old = {'registry':registry} try: manager.push(old) self._callFUT() # doesn't blow up current = manager.get() self.assertNotEqual(current, old) self.assertEqual(registry.inited, 1) finally: manager.clear()
def test_hit_w_persistent_context_non_root(self): from pyramid.threadlocal import manager root = self._makeContext(_p_jar=object()) self._populate(root) context = self._makeContext( _p_jar=object(), __parent__=root, cartouche=object(), # ignored ) request = self._makeRequest(context=context) manager.get()['request'] = request environ = request.environ credentials = {'login': '******', 'password': '******'} plugin = self._makeOne() self.assertEqual(plugin.authenticate(environ, credentials), 'UUID')
def test_defaults(self): from pyramid.threadlocal import manager registry = DummyRegistry() old = {'registry': registry} hook = lambda *arg: None try: self._setSMHook(hook) manager.push(old) self._callFUT() current = manager.get() self.assertNotEqual(current, old) self.assertEqual(registry.inited, 2) finally: result = getSiteManager.sethook(None) self.assertNotEqual(result, hook)
def test_it_defaults(self): from pyramid.threadlocal import manager from pyramid.threadlocal import get_current_registry from pyramid.registry import Registry from zope.component import getSiteManager old = True manager.push(old) try: config = self._callFUT() current = manager.get() self.failIf(current is old) self.assertEqual(config.registry, current['registry']) self.assertEqual(current['registry'].__class__, Registry) self.assertEqual(current['request'], None) finally: result = getSiteManager.sethook(None) self.assertEqual(result, get_current_registry) getSiteManager.reset() manager.clear()
def threadlocals(request, dummy_request, registry): from pyramid.threadlocal import manager manager.push({'request': dummy_request, 'registry': registry}) yield manager.get() manager.pop()
def setUp(self): from pyramid.threadlocal import manager self.manager = manager self.default = manager.get()