Files
Maison/samba-api/tests/test_main.py
2026-02-10 12:12:11 +01:00

66 lines
2.4 KiB
Python

import pytest
from unittest.mock import patch, AsyncMock
def test_app_startup(client):
"""Test application startup and health endpoint"""
response = client.get("/health")
assert response.status_code == 200
assert response.json() == {"status": "healthy", "service": "samba-api"}
def test_root_endpoint(client):
"""Test root endpoint"""
response = client.get("/")
assert response.status_code == 200
data = response.json()
assert data["message"] == "Samba API is running"
assert data["version"] == "1.0.0"
def test_docs_endpoint(client):
"""Test API documentation endpoint"""
response = client.get("/docs")
assert response.status_code == 200
def test_openapi_schema(client):
"""Test OpenAPI schema endpoint"""
response = client.get("/openapi.json")
assert response.status_code == 200
schema = response.json()
assert schema["info"]["title"] == "Samba API"
assert schema["info"]["version"] == "1.0.0"
class TestAPIEndpoints:
"""Test API endpoint structure"""
def test_user_endpoints_exist(self, client):
"""Test that user endpoints exist (will return 401 without auth)"""
# These should return 401/403 without authentication, not 404
response = client.get("/api/v1/users")
assert response.status_code in [401, 403]
response = client.post("/api/v1/users", json={})
assert response.status_code in [401, 403, 422]
def test_auth_endpoints_exist(self, client):
"""Test that auth endpoints exist"""
# Login endpoint should exist and return 422 for invalid data
response = client.post("/api/v1/auth/login", json={})
assert response.status_code == 422 # Validation error
# Me endpoint should return 401 without auth
response = client.get("/api/v1/auth/me")
assert response.status_code in [401, 403]
def test_group_endpoints_exist(self, client):
"""Test that group endpoints exist"""
response = client.get("/api/v1/groups")
assert response.status_code in [401, 403]
def test_ou_endpoints_exist(self, client):
"""Test that OU endpoints exist"""
response = client.get("/api/v1/ous")
assert response.status_code in [401, 403]
def test_computer_endpoints_exist(self, client):
"""Test that computer endpoints exist"""
response = client.get("/api/v1/computers")
assert response.status_code in [401, 403]