def testRequestRequired(self):
        s = RequestScope()

        a = A()
        self.assertRaises(NoRequestError, s.bind, A, a)
        self.assertRaises(NoRequestError, s.unbind, A)
        self.assertRaises(NoRequestError, s.get, A)

        self.assertFalse(s.is_bound(A))
 def testRequestRequired(self):
     s = RequestScope()
     
     a = A()
     self.assertRaises(NoRequestError, s.bind, A, a)
     self.assertRaises(NoRequestError, s.unbind, A)
     self.assertRaises(NoRequestError, s.get, A)
     
     self.assertFalse(s.is_bound(A))
 def testContextManager(self):
     '''RequestScope should support the context manager protocol.'''
     s = RequestScope()
     self.assertRaises(NoRequestError, s.get, A)
     
     with s:
         a = A()
         s.bind(A, a)
         self.assertTrue(s.get(A) is a)
     
     self.assertRaises(NoRequestError, s.get, A)
     
     with s:
         self.assertTrue(s.get(A) is None)
Beispiel #4
0
    def _default_config(self):
        '''Bind Injector to self, and create and bind ThreadScope
        and RequestScope.
        '''
        self.bind(Injector, to=self)

        thread_scope = ThreadScope()
        self.bind_scope(ThreadScope, thread_scope)

        reqscope = RequestScope()
        self.bind_scope(RequestScope, reqscope)

        self.logger.info('Loaded the default configuration.')
    def testRequestLocal(self):
        s = RequestScope()
        s.start()

        self.assertFalse(s.is_bound(A))
        a = A()
        s.bind(A, a)
        self.assertTrue(s.get(A) is a)

        def run():
            a2 = A()
            s.start()
            self.assertFalse(s.is_bound(A))
            s.bind(A, a2)
            self.assertTrue(s.get(A) is a2)

        thread = threading.Thread(target=run)
        thread.start()
        thread.join()

        self.assertTrue(s.is_bound(A))
        self.assertTrue(s.get(A) is a)
 def testRequestLocal(self):
     s = RequestScope()
     s.start()
     
     self.assertFalse(s.is_bound(A))
     a = A()
     s.bind(A, a)
     self.assertTrue(s.get(A) is a)
     
     def run():
         a2 = A()
         s.start()
         self.assertFalse(s.is_bound(A))
         s.bind(A, a2)
         self.assertTrue(s.get(A) is a2)
     
     thread = threading.Thread(target=run)
     thread.start()
     thread.join()
     
     self.assertTrue(s.is_bound(A))
     self.assertTrue(s.get(A) is a)
    def testContextManager(self):
        '''RequestScope should support the context manager protocol.'''
        s = RequestScope()
        self.assertRaises(NoRequestError, s.get, A)

        with s:
            a = A()
            s.bind(A, a)
            self.assertTrue(s.get(A) is a)

        self.assertRaises(NoRequestError, s.get, A)

        with s:
            self.assertTrue(s.get(A) is None)
 def testRequestLocalAndFactories(self):
     s = RequestScope()
     s.start()
     
     s.bind_factory(A, A)
     self.assertTrue(s.is_factory_bound(A))
     self.assertFalse(s.is_bound(A))
     
     a = s.get(A)
     self.assertTrue(s.is_bound(A))
     
     s.end()
     self.assertTrue(s.is_factory_bound(A))
     self.assertFalse(s.is_bound(A))
     
     s.start()
     a2 = s.get(A)
     self.assertFalse(a2 is a)
     s.end()
 def new_scope(self):
     s = RequestScope()
     s.start();
     return s
    def testRequestLocalAndFactories(self):
        s = RequestScope()
        s.start()

        s.bind_factory(A, A)
        self.assertTrue(s.is_factory_bound(A))
        self.assertFalse(s.is_bound(A))

        a = s.get(A)
        self.assertTrue(s.is_bound(A))

        s.end()
        self.assertTrue(s.is_factory_bound(A))
        self.assertFalse(s.is_bound(A))

        s.start()
        a2 = s.get(A)
        self.assertFalse(a2 is a)
        s.end()
 def new_scope(self):
     s = RequestScope()
     s.start()
     return s