|
| 1 | +"""Tests for the commits API endpoints.""" |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | + |
| 6 | +@pytest.mark.asyncio |
| 7 | +async def test_list_commits_empty(client): |
| 8 | + response = await client.get("/api/commits") |
| 9 | + assert response.status_code == 200 |
| 10 | + assert response.json() == [] |
| 11 | + |
| 12 | + |
| 13 | +@pytest.mark.asyncio |
| 14 | +async def test_list_commits(client, sample_commit): |
| 15 | + response = await client.get("/api/commits") |
| 16 | + assert response.status_code == 200 |
| 17 | + data = response.json() |
| 18 | + assert len(data) == 1 |
| 19 | + assert data[0]["sha"] == sample_commit.sha |
| 20 | + assert data[0]["author"] == "Test Author" |
| 21 | + assert data[0]["python_version"]["major"] == 3 |
| 22 | + assert data[0]["python_version"]["minor"] == 14 |
| 23 | + |
| 24 | + |
| 25 | +@pytest.mark.asyncio |
| 26 | +async def test_list_commits_pagination(client, sample_commit): |
| 27 | + response = await client.get("/api/commits", params={"skip": 0, "limit": 1}) |
| 28 | + assert response.status_code == 200 |
| 29 | + assert len(response.json()) == 1 |
| 30 | + |
| 31 | + response = await client.get("/api/commits", params={"skip": 1, "limit": 1}) |
| 32 | + assert response.status_code == 200 |
| 33 | + assert len(response.json()) == 0 |
| 34 | + |
| 35 | + |
| 36 | +@pytest.mark.asyncio |
| 37 | +async def test_get_commit_by_sha(client, sample_commit): |
| 38 | + response = await client.get(f"/api/commits/{sample_commit.sha}") |
| 39 | + assert response.status_code == 200 |
| 40 | + data = response.json() |
| 41 | + assert data["sha"] == sample_commit.sha |
| 42 | + assert data["message"] == "Test commit" |
| 43 | + |
| 44 | + |
| 45 | +@pytest.mark.asyncio |
| 46 | +async def test_get_commit_not_found(client): |
| 47 | + response = await client.get("/api/commits/" + "f" * 40) |
| 48 | + assert response.status_code == 404 |
| 49 | + |
| 50 | + |
| 51 | +@pytest.mark.asyncio |
| 52 | +async def test_python_versions_empty(client): |
| 53 | + response = await client.get("/api/python-versions") |
| 54 | + assert response.status_code == 200 |
| 55 | + assert response.json() == [] |
| 56 | + |
| 57 | + |
| 58 | +@pytest.mark.asyncio |
| 59 | +async def test_python_versions(client, sample_benchmark_result): |
| 60 | + response = await client.get("/api/python-versions") |
| 61 | + assert response.status_code == 200 |
| 62 | + data = response.json() |
| 63 | + assert len(data) == 1 |
| 64 | + assert data[0]["major"] == 3 |
| 65 | + assert data[0]["minor"] == 14 |
0 commit comments