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 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 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)