test(sap): check the token refreshes inside the expiry buffer

This commit is contained in:
Tuan Pham 2026-10-30 15:15:04 +08:00
parent 7ad39b6b4b
commit 121f39acc9

View file

@ -160,3 +160,17 @@ def test_credentials_without_authentication_mode(monkeypatch):
# validate_credentials should raise because no authentication mode is provided
with pytest.raises(ValueError, match="SAP AI Core credentials are incomplete"):
sap_credentials.validate_credentials(**creds)
@pytest.mark.parametrize(
"expires_in, expected_token_requests",
[(43200, 1), (3000, 3)],
ids=["reused-while-valid", "refreshed-inside-60-minute-buffer"],
)
def test_token_is_shared_across_token_creators_until_refresh_buffer(aicore, expires_in, expected_token_requests):
aicore.token.respond(json={"access_token": "mock-token", "expires_in": expires_in})
tokens = tuple(sap_credentials.get_token_creator()[0]() for _ in range(3))
assert tokens == ("Bearer mock-token",) * 3
assert aicore.token.call_count == expected_token_requests