Spaces:
Sleeping
Sleeping
Create tests/test_adapter_contract.py
Browse files- tests/test_adapter_contract.py +20 -33
tests/test_adapter_contract.py
CHANGED
|
@@ -1,43 +1,30 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
@pytest.mark.asyncio
|
| 11 |
-
async def test_adapters_implement_search():
|
| 12 |
-
"""
|
| 13 |
-
Every adapter must implement an async search() method.
|
| 14 |
-
"""
|
| 15 |
-
adapters = get_all_adapters()
|
| 16 |
-
|
| 17 |
-
assert adapters, "No adapters registered"
|
| 18 |
-
|
| 19 |
-
for name, adapter in adapters.items():
|
| 20 |
-
assert isinstance(adapter, GenericFOIAAdapter), f"{name} not subclassing GenericFOIAAdapter"
|
| 21 |
-
|
| 22 |
-
method = adapter.search
|
| 23 |
-
assert callable(method), f"{name}.search is not callable"
|
| 24 |
-
assert inspect.iscoroutinefunction(method), f"{name}.search must be async"
|
| 25 |
|
| 26 |
|
| 27 |
@pytest.mark.asyncio
|
| 28 |
-
async def
|
| 29 |
"""
|
| 30 |
-
|
| 31 |
"""
|
| 32 |
adapters = get_all_adapters()
|
| 33 |
|
| 34 |
for name, adapter in adapters.items():
|
| 35 |
-
|
| 36 |
-
results = await adapter.search("test")
|
| 37 |
-
except Exception as e:
|
| 38 |
-
pytest.fail(f"{name}.search() raised exception: {e}")
|
| 39 |
-
|
| 40 |
-
assert isinstance(results, list), f"{name}.search did not return a list"
|
| 41 |
|
| 42 |
for r in results:
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
REQUIRED_KEYS = {
|
| 2 |
+
"source",
|
| 3 |
+
"title",
|
| 4 |
+
"url",
|
| 5 |
+
"snippet",
|
| 6 |
+
"live",
|
| 7 |
+
"extended",
|
| 8 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
@pytest.mark.asyncio
|
| 12 |
+
async def test_result_schema():
|
| 13 |
"""
|
| 14 |
+
Enforces normalized result format for UI, export, and citations.
|
| 15 |
"""
|
| 16 |
adapters = get_all_adapters()
|
| 17 |
|
| 18 |
for name, adapter in adapters.items():
|
| 19 |
+
results = await adapter.search("compliance test")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
for r in results:
|
| 22 |
+
missing = REQUIRED_KEYS - set(r.keys())
|
| 23 |
+
assert not missing, f"{name} missing keys: {missing}"
|
| 24 |
+
|
| 25 |
+
assert isinstance(r["source"], str)
|
| 26 |
+
assert isinstance(r["title"], str)
|
| 27 |
+
assert isinstance(r["url"], str)
|
| 28 |
+
assert isinstance(r["snippet"], str)
|
| 29 |
+
assert isinstance(r["live"], bool)
|
| 30 |
+
assert isinstance(r["extended"], bool)
|