|
1 | 1 | import asyncio |
2 | 2 | import time |
3 | | - |
| 3 | +import httpx |
4 | 4 | import pytest |
5 | 5 | from app.schemas.user import UserCreate |
6 | 6 | from httpx import AsyncClient, HTTPStatusError |
7 | 7 | from motor.motor_asyncio import AsyncIOMotorDatabase |
8 | 8 |
|
9 | | -# Define polling parameters |
10 | 9 | POLL_INTERVAL = 2 # seconds |
11 | 10 | EXECUTION_TIMEOUT = 120 # seconds |
12 | 11 |
|
@@ -146,16 +145,28 @@ async def test_k8s_resource_limits(self) -> None: |
146 | 145 | @pytest.mark.asyncio |
147 | 146 | async def test_execute_endpoint_without_auth(self) -> None: |
148 | 147 | """Test accessing execute endpoint without authentication (should succeed).""" |
149 | | - execution_request = {"script": "print('no auth test should pass')"} |
150 | | - response = await self.client.post("/api/v1/execute", json=execution_request, cookies={}) # No cookies |
151 | | - # Expect 200 OK because the endpoint is public |
152 | | - assert response.status_code == 200 |
153 | | - assert "execution_id" in response.json() |
154 | | - assert "status" in response.json() |
| 148 | + async with httpx.AsyncClient( |
| 149 | + base_url="https://localhost:443", |
| 150 | + verify=False, |
| 151 | + timeout=30.0 |
| 152 | + ) as new_client: |
| 153 | + execution_request = {"script": "print('no auth test should pass')"} |
| 154 | + response = await new_client.post("/api/v1/execute", json=execution_request) |
| 155 | + # Expect 200 OK because the endpoint is public |
| 156 | + assert response.status_code == 200 |
| 157 | + assert "execution_id" in response.json() |
| 158 | + assert "status" in response.json() |
155 | 159 |
|
156 | 160 | @pytest.mark.asyncio |
157 | 161 | async def test_result_endpoint_without_auth(self) -> None: |
158 | | - non_existent_id = "nonexistent-public-id-999" |
159 | | - response = await self.client.get(f"/api/v1/result/{non_existent_id}", cookies={}) # No cookies |
160 | | - # Expect 404 Not Found because the ID doesn't exist, *not* 401 because the endpoint is public |
161 | | - assert response.status_code == 404 |
| 162 | + # Create a new client without cookies to simulate no auth |
| 163 | + import httpx |
| 164 | + async with httpx.AsyncClient( |
| 165 | + base_url="https://localhost:443", |
| 166 | + verify=False, |
| 167 | + timeout=30.0 |
| 168 | + ) as new_client: |
| 169 | + non_existent_id = "nonexistent-public-id-999" |
| 170 | + response = await new_client.get(f"/api/v1/result/{non_existent_id}") |
| 171 | + # Expect 404 Not Found because the ID doesn't exist, *not* 401 because the endpoint is public |
| 172 | + assert response.status_code == 404 |
0 commit comments