コード例 #1
0
    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())
コード例 #2
0
    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))
コード例 #3
0
ファイル: api_test.py プロジェクト: maruel/luci-py
    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())
コード例 #4
0
ファイル: api_test.py プロジェクト: maruel/luci-py
    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))
コード例 #5
0
 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
コード例 #6
0
ファイル: api_test.py プロジェクト: maruel/luci-py
 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