예제 #1
0
 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)
예제 #2
0
    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)
예제 #3
0
 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)
예제 #4
0
    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)
예제 #5
0
 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)
예제 #6
0
 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)
예제 #7
0
 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()
예제 #8
0
 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()
예제 #9
0
 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()
예제 #10
0
 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()
예제 #11
0
 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)
예제 #12
0
 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)
예제 #13
0
 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')
예제 #14
0
 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)
예제 #15
0
 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()
예제 #16
0
 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()
예제 #17
0
 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()
예제 #18
0
 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()
예제 #19
0
 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')
예제 #20
0
 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)
예제 #21
0
 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()
예제 #22
0
 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()
예제 #23
0
def threadlocals(request, dummy_request, registry):
    from pyramid.threadlocal import manager
    manager.push({'request': dummy_request, 'registry': registry})
    yield manager.get()
    manager.pop()
예제 #24
0
 def setUp(self):
     from pyramid.threadlocal import manager
     self.manager = manager
     self.default = manager.get()
예제 #25
0
 def setUp(self):
     from pyramid.threadlocal import manager
     self.manager = manager
     self.default = manager.get()