Files
sdb-back/tests/test_routes.py
JSC 52c60db811 refactor(auth): improve code structure and add user registration endpoint
refactor(main): update index route response and remove greeting service

refactor(decorators): streamline authentication decorators and remove unused ones

test(routes): update tests to reflect changes in main routes and error messages
2025-06-28 20:47:45 +02:00

37 lines
1.1 KiB
Python

"""Tests for routes."""
import pytest
from app import create_app
@pytest.fixture
def client():
"""Create a test client for the Flask application."""
app = create_app()
app.config["TESTING"] = True
with app.test_client() as client:
yield client
class TestMainRoutes:
"""Test cases for main routes."""
def test_index_route(self, client) -> None:
"""Test the index route."""
response = client.get("/api/")
assert response.status_code == 200
assert response.get_json() == {"message": "API is running", "status": "ok"}
def test_health_route(self, client) -> None:
"""Test health check route."""
response = client.get("/api/health")
assert response.status_code == 200
assert response.get_json() == {"status": "ok"}
def test_protected_route_without_auth(self, client) -> None:
"""Test protected route without authentication."""
response = client.get("/api/protected")
assert response.status_code == 401
data = response.get_json()
assert data["error"] == "Authentication required (JWT or API token)"