|
31 | 31 | recorded_body_matcher, |
32 | 32 | ) |
33 | 33 | from tests.recorded.sanitization import FILTERED_HEADERS |
34 | | -from tests.recorded.utils import api_key_for_record_mode |
| 34 | +from tests.recorded.utils import api_key_for_record_mode, set_api_key_for_record_mode |
35 | 35 |
|
36 | 36 | pytestmark = [pytest.mark.recorded] |
37 | 37 |
|
@@ -124,6 +124,13 @@ def test_recorded_cassette_serializer_keeps_json_bodies_readable(): |
124 | 124 | assert ReadableYamlSerializer.deserialize(text)["interactions"][0]["response"]["body"]["string"].startswith("{") |
125 | 125 |
|
126 | 126 |
|
| 127 | +def test_recorded_cassette_serializer_handles_null_interactions(): |
| 128 | + cassette = {"version": 1, "interactions": None} |
| 129 | + |
| 130 | + assert yaml.safe_load(ReadableYamlSerializer.serialize(cassette)) == cassette |
| 131 | + assert ReadableYamlSerializer.deserialize("version: 1\ninteractions:\n") == cassette |
| 132 | + |
| 133 | + |
127 | 134 | def test_recorded_cassette_serializer_redacts_access_tokens_from_parsed_bodies(): |
128 | 135 | request = Request( |
129 | 136 | method="POST", |
@@ -513,6 +520,13 @@ def test_recorded_refresh_uses_api_key_without_live_mode_gate(monkeypatch): |
513 | 520 | assert api_key_for_record_mode("OPENAI_API_KEY", "dummy-key", "rewrite") == "real-key" |
514 | 521 |
|
515 | 522 |
|
| 523 | +def test_recorded_refresh_fixture_returns_selected_api_key(monkeypatch): |
| 524 | + monkeypatch.setenv("OPENAI_API_KEY", "real-key") |
| 525 | + |
| 526 | + assert set_api_key_for_record_mode(monkeypatch, "OPENAI_API_KEY", "dummy-key", "rewrite") == "real-key" |
| 527 | + assert set_api_key_for_record_mode(monkeypatch, "OPENAI_API_KEY", "dummy-key", "none") == "dummy-key" |
| 528 | + |
| 529 | + |
516 | 530 | def test_recorded_body_matcher_compares_sanitized_json_bodies(): |
517 | 531 | cassette_request = Request( |
518 | 532 | method="POST", |
|
0 commit comments