| """ |
| Tests for stateful database emulation and network blocking. |
| """ |
|
|
|
|
| import httpx |
| import pytest |
|
|
|
|
| @pytest.mark.asyncio |
| async def test_stateful_crud_operations(mock_supabase_client): |
| """Test that the stateful emulator retains values on insert, update, select, and delete.""" |
| client = mock_supabase_client |
|
|
| |
| res = client.table("projects").select("*").execute() |
| assert len(res.data) == 0 |
|
|
| |
| inserted = client.table("projects").insert([ |
| {"title": "Project A", "status": "active"}, |
| {"title": "Project B", "status": "archived"} |
| ]).execute() |
|
|
| assert len(inserted.data) == 2 |
| assert inserted.data[0]["title"] == "Project A" |
| assert "id" in inserted.data[0] |
|
|
| |
| selected = client.table("projects").select("*").execute() |
| assert len(selected.data) == 2 |
|
|
| |
| filtered = client.table("projects").select("*").eq("title", "Project A").execute() |
| assert len(filtered.data) == 1 |
| assert filtered.data[0]["title"] == "Project A" |
|
|
| |
| updated = client.table("projects").update({"status": "completed"}).eq("title", "Project A").execute() |
| assert len(updated.data) == 1 |
| assert updated.data[0]["status"] == "completed" |
|
|
| |
| verify = client.table("projects").select("*").eq("title", "Project A").execute() |
| assert verify.data[0]["status"] == "completed" |
|
|
| |
| client.table("projects").delete().eq("title", "Project B").execute() |
|
|
| |
| remaining = client.table("projects").select("*").execute() |
| assert len(remaining.data) == 1 |
| assert remaining.data[0]["title"] == "Project A" |
|
|
|
|
| @pytest.mark.asyncio |
| async def test_respx_network_blocking(): |
| """Test that any real HTTPX network calls to supabase.co are blocked by respx.""" |
| |
| |
| async with httpx.AsyncClient() as client: |
| with pytest.raises(httpx.ConnectError) as exc_info: |
| await client.get("https://xyz.supabase.co/rest/v1/projects") |
|
|
| assert "Blocked connection to Supabase" in str(exc_info.value) |
|
|