fix: update PostgreSQL migration mock to match actual execute() signature

Why this change is needed:
Unit test mock was rejecting dict parameters, but real PostgreSQLDB.execute()
accepts data as dict[str, Any]. This caused unit tests to fail after fixing
the actual migration code to pass dict instead of unpacked positional args.

How it solves it:
- Changed mock_execute signature from (sql, *args) to (sql, data=None)
- Accept dict parameter like real execute() does
- Mock now matches actual PostgreSQLDB.execute() behavior

Impact:
- Fixes Vector Storage Migration unit tests
- Mock now correctly validates migration code

Testing:
- Unit tests will verify this fix
This commit is contained in:
BukeLy 2025-11-20 03:14:53 +08:00
parent b29f32b513
commit 4e86da2969

View file

@ -22,21 +22,18 @@ def mock_pg_db():
return [] # Return empty list for multirows return [] # Return empty list for multirows
return {"exists": False, "count": 0} return {"exists": False, "count": 0}
# Strict mock for execute that validates parameter types # Mock for execute that mimics PostgreSQLDB.execute() behavior
async def mock_execute(sql, *args, **kwargs): async def mock_execute(sql, data=None, **kwargs):
""" """
Strict mock that mimics AsyncPG behavior: Mock that mimics PostgreSQLDB.execute() behavior:
- Positional parameters must be passed as separate arguments (*args) - Accepts data as dict[str, Any] | None (second parameter)
- Raises TypeError if a dict/list is passed as a single argument - Internally converts dict.values() to tuple for AsyncPG
""" """
if args and len(args) == 1: # Mimic real execute() which accepts dict and converts to tuple
# Check if single argument is a dict or list (wrong usage) if data is not None and not isinstance(data, dict):
if isinstance(args[0], (dict, list)): raise TypeError(
raise TypeError( f"PostgreSQLDB.execute() expects data as dict, got {type(data).__name__}"
"AsyncPG execute() expects positional parameters as separate arguments, " )
f"not as {type(args[0]).__name__}. Use: execute(query, val1, val2, ...) "
"or execute(query, *values)"
)
return None return None
db.query = AsyncMock(side_effect=mock_query) db.query = AsyncMock(side_effect=mock_query)