-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #354 from jsmolar/jsmolar-fix-branch
Fixed caching tests
- Loading branch information
Showing
2 changed files
with
40 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
testsuite/tests/kuadrant/authorino/caching/metadata/test_ttl.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
"""Tests TTL for metadata caching""" | ||
|
||
from time import sleep | ||
|
||
import pytest | ||
|
||
from testsuite.policy.authorization import ValueFrom, Cache | ||
from testsuite.utils import extract_response | ||
|
||
pytestmark = [pytest.mark.authorino] | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def cache_ttl(): | ||
"""Returns TTL in seconds for Cached Metadata""" | ||
return 5 | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def authorization(authorization, module_label, expectation_path, cache_ttl): | ||
"""Adds Cached Metadata to the AuthConfig""" | ||
meta_cache = Cache(cache_ttl, ValueFrom("context.request.http.path")) | ||
authorization.metadata.add_http(module_label, expectation_path, "GET", cache=meta_cache) | ||
return authorization | ||
|
||
|
||
def test_cached_ttl(client, auth, module_label, cache_ttl, mockserver): | ||
"""Tests that cached value expires after ttl""" | ||
response = client.get("/get", auth=auth) | ||
data = extract_response(response)[module_label]["uuid"] % None | ||
sleep(cache_ttl) | ||
response = client.get("/get", auth=auth) | ||
cached_data = extract_response(response)[module_label]["uuid"] % None | ||
|
||
assert cached_data is not None | ||
assert data is not None | ||
assert data != cached_data | ||
assert len(mockserver.retrieve_requests(module_label)) == 2 |