1
1
from __future__ import annotations
2
2
3
- import os
4
3
import tempfile
5
4
import time
6
5
from pathlib import Path
7
- from unittest .mock import patch
8
6
9
7
import pytest
8
+
9
+ pytest .importorskip ("cryptography" ) # Skip tests if cryptography is not installed
10
+
10
11
from cryptography .fernet import Fernet
11
12
12
13
from agents import Agent , Runner , SQLiteSession , TResponseInputItem
@@ -27,7 +28,7 @@ def agent() -> Agent:
27
28
@pytest .fixture
28
29
def encryption_key () -> str :
29
30
"""Fixture for a valid Fernet encryption key."""
30
- return Fernet .generate_key ().decode ("utf-8" )
31
+ return str ( Fernet .generate_key ().decode ("utf-8" ) )
31
32
32
33
33
34
@pytest .fixture
@@ -229,36 +230,6 @@ async def test_encrypted_session_pop_mixed_expired_valid(
229
230
underlying_session .close ()
230
231
231
232
232
- async def test_encrypted_session_env_key (underlying_session : SQLiteSession ):
233
- """Test encryption key from environment variable."""
234
- key = Fernet .generate_key ().decode ("utf-8" )
235
-
236
- with patch .dict (os .environ , {"ENCRYPTION_KEY" : key }):
237
- session = EncryptedSession (
238
- session_id = "test_session" ,
239
- underlying_session = underlying_session ,
240
- )
241
-
242
- await session .add_items ([{"role" : "user" , "content" : "Test" }])
243
- items = await session .get_items ()
244
- assert len (items ) == 1
245
- assert items [0 ].get ("content" ) == "Test"
246
-
247
- underlying_session .close ()
248
-
249
-
250
- async def test_encrypted_session_missing_key (underlying_session : SQLiteSession ):
251
- """Test error handling for missing encryption key."""
252
- with pytest .raises (ValueError , match = "ENCRYPTION_KEY missing" ):
253
- EncryptedSession (
254
- session_id = "test_session" ,
255
- underlying_session = underlying_session ,
256
- encryption_key = None ,
257
- )
258
-
259
- underlying_session .close ()
260
-
261
-
262
233
async def test_encrypted_session_raw_string_key (underlying_session : SQLiteSession ):
263
234
"""Test using raw string as encryption key (not base64)."""
264
235
session = EncryptedSession (
0 commit comments