53 lines
1.6 KiB
Python
53 lines
1.6 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."""
|
|
mocker.patch("rich.console.Console.print")
|
|
console_print = mocker.patch("rich.padding.Padding.__init__", return_value=None)
|
|
super().test(testapp, requests_mock)
|
|
console_print.assert_any_call(
|
|
"[red]Invalid JSON generated by the model:[/red]", (0, 4)
|
|
)
|
|
|
|
|
|
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
|