Files
azure-gpt-cursor/tests/test_logging.py
T
2025-09-18 11:03:50 +02:00

52 lines
1.5 KiB
Python

"""Functional tests using WebTest.
See: http://webtest.readthedocs.org/
"""
from app.common.logging import redact_headers
from .replay_base import ReplyBase
class TestModelInvalidJson(ReplyBase):
"""Test logging of context containing an invalid JSON tool call."""
recording = "context_tool_call_invalid_json"
def test(self, testapp, requests_mock, mocker):
"""Test logging of context containing an invalid JSON tool call."""
console_print = mocker.patch(
"rich.console.Console.print", return_value=mocker.Mock()
)
super().test(testapp, requests_mock)
console_print.assert_any_call("[red]Invalid JSON generated by the model:[/red]")
def test_redact_headers():
"""Test redacting headers."""
headers = {
"Authorization": "Bearer test-service-api-key",
"authorization": "Bearer test-service-api-key",
"non-sensitive": "test-value",
"api-key": "", # Empty value
"api_key": "short",
}
redacted_headers = redact_headers(headers)
assert redacted_headers == {
"Authorization": "Bear…-key",
"authorization": "Bear…-key",
"non-sensitive": "test-value",
"api-key": "",
"api_key": "...",
}
def test_should_not_refact(mocker):
"""Test that headers are not redacted if should_redact is False."""
mocker.patch("app.common.logging.should_redact", return_value=False)
headers = {
"api_key": "test",
}
redacted_headers = redact_headers(headers)
assert redacted_headers == headers