Skip to content

Commit f24de82

Browse files
committed
tests for checkpointer
1 parent ca661de commit f24de82

4 files changed

Lines changed: 65 additions & 6 deletions

File tree

src/client/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
from client.agent_client import AgentClient
2-
3-
__all__ = ["AgentClient"]

test/checkpointer/conftest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""Checkpoint-specific test configuration that doesn't require service imports."""
2+
import sys
3+
from pathlib import Path
4+
import pytest
5+
6+
# Add project root to path
7+
sys.path.insert(0, str(Path(__file__).parent.parent.parent))
8+
9+
@pytest.fixture(scope="module")
10+
def anyio_backend():
11+
"""Use asyncio only for these tests."""
12+
return "asyncio"
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import pytest
2+
from unittest.mock import AsyncMock, MagicMock
3+
from src.checkpointer.obp_checkpoint_saver import OBPCheckpointSaver
4+
5+
@pytest.mark.anyio
6+
async def test_check_existing_setup_returns_true_when_entities_exist():
7+
# Mock the OBPClient
8+
mock_client = MagicMock()
9+
mock_response = MagicMock()
10+
mock_response.json.return_value = {
11+
"dynamic_entities": [
12+
{"OpeyCheckpoint": {}},
13+
{"OpeyCheckpointWrite": {}}
14+
]
15+
}
16+
mock_client.get = AsyncMock(return_value=mock_response)
17+
18+
# Create saver and test
19+
saver = OBPCheckpointSaver(client=mock_client)
20+
result = await saver._check_existing_setup()
21+
22+
assert result is True
23+
mock_client.get.assert_called_once_with("/obp/v6.0.0/management/system-dynamic-entities")
24+
25+
@pytest.mark.anyio
26+
async def test_check_existing_setup_returns_false_when_entities_missing():
27+
mock_client = MagicMock()
28+
mock_response = MagicMock()
29+
mock_response.json.return_value = {"dynamic_entities": []}
30+
mock_client.get = AsyncMock(return_value=mock_response)
31+
32+
saver = OBPCheckpointSaver(client=mock_client)
33+
result = await saver._check_existing_setup()
34+
35+
assert result is False
36+
37+
@pytest.mark.anyio
38+
async def test_check_existing_setup_raises_on_api_error():
39+
mock_client = MagicMock()
40+
mock_client.get = AsyncMock(side_effect=Exception("API Error"))
41+
42+
saver = OBPCheckpointSaver(client=mock_client)
43+
44+
with pytest.raises(RuntimeError, match="Error checking existing OBP setup"):
45+
await saver._check_existing_setup()

test/conftest.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@
88
from unittest.mock import patch, MagicMock
99

1010
import pytest
11-
from service.service import app
12-
from httpx import AsyncClient, ASGITransport
13-
from asgi_lifespan import LifespanManager
11+
12+
# Conditionally import service to avoid loading issues in unit tests
13+
try:
14+
from service.service import app
15+
from httpx import AsyncClient, ASGITransport
16+
from asgi_lifespan import LifespanManager
17+
except Exception:
18+
app = None
1419

1520
# @pytest_asyncio.fixture(scope="session", loop_scope="session")
1621
# def anyio_backend():

0 commit comments

Comments
 (0)