def test_get_request_auth_db(self): """Ensure get_request_auth_db() caches AuthDB in request cache.""" api.reinitialize_request_cache() # 'get_request_auth_db()' returns whatever get_process_auth_db() returns # when called for a first time. self.mock(api, 'get_process_auth_db', lambda: 'fake') self.assertEqual('fake', api.get_request_auth_db()) # But then it caches it locally and reuses local copy, instead of calling # 'get_process_auth_db()' all the time. self.mock(api, 'get_process_auth_db', lambda: 'another-fake') self.assertEqual('fake', api.get_request_auth_db())
def test_get_request_cache_different_requests(self): """Ensure get_request_cache() returns new object for a new request.""" # Grab request cache for 'current' request. request_cache = api.reinitialize_request_cache() # Track calls to 'close'. close_calls = [] self.mock(request_cache, 'close', lambda: close_calls.append(1)) # Should return a new instance of request cache now. self.assertTrue(api.reinitialize_request_cache() is not request_cache) # Old one should have been closed. self.assertEqual(1, len(close_calls))
def test_get_request_auth_db(self): """Ensure get_request_auth_db() caches AuthDB in request cache.""" api.reinitialize_request_cache() # 'get_request_auth_db()' returns whatever get_process_auth_db() returns # when called for a first time. self.mock(api, "get_process_auth_db", lambda: "fake") self.assertEqual("fake", api.get_request_auth_db()) # But then it caches it locally and reuses local copy, instead of calling # 'get_process_auth_db()' all the time. self.mock(api, "get_process_auth_db", lambda: "another-fake") self.assertEqual("fake", api.get_request_auth_db())
def test_get_request_cache_different_requests(self): """Ensure get_request_cache() returns new object for a new request.""" # Grab request cache for 'current' request. request_cache = api.reinitialize_request_cache() # Track calls to 'close'. close_calls = [] self.mock(request_cache, "close", lambda: close_calls.append(1)) # Should return a new instance of request cache now. self.assertTrue(api.reinitialize_request_cache() is not request_cache) # Old one should have been closed. self.assertEqual(1, len(close_calls))
def thread_proc(): request_cache = api.reinitialize_request_cache() self.assertTrue(request_cache) # Returns same object in a context of a same request thread. self.assertTrue(api.get_request_cache() is request_cache) return request_cache