parthpetkar/metahackathon
0
1"""Basic tests for the sample API service."""
2
3import pytest
4import sys
5import os
6
7# Add project root to path
8sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
9
10from services.api.app import create_app
11
12
13@pytest.fixture
14def client():
15 app = create_app()
16 app.config["TESTING"] = True
17 with app.test_client() as client:
18 yield client
19
20
21def test_health_endpoint(client):
22 """Test the health check endpoint returns healthy status."""
23 response = client.get("/health")
24 assert response.status_code == 200
25 data = response.get_json()
26 assert data["status"] == "healthy"
27 assert data["service"] == "api"
28
29
30def test_list_items(client):
31 """Test listing all items returns expected data."""
32 response = client.get("/items")
33 assert response.status_code == 200
34 data = response.get_json()
35 assert "items" in data
36 assert data["count"] == 3
37 assert len(data["items"]) == 3
38
39
40def test_get_item_exists(client):
41 """Test getting an existing item by ID."""
42 response = client.get("/items/1")
43 assert response.status_code == 200
44 data = response.get_json()
45 assert data["id"] == 1
46 assert data["name"] == "Widget A"
47
48
49def test_get_item_not_found(client):
50 """Test getting a non-existent item returns 404."""
51 response = client.get("/items/999")
52 assert response.status_code == 404
53 data = response.get_json()
54 assert "error" in data
55 