File size: 2,766 Bytes
177c40c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""
REST API endpoint tests.

Tests for the FastAPI endpoints including the source code viewer API.
"""

import pytest
from fastapi.testclient import TestClient
from my_quickstart.rest_api import app


@pytest.fixture
def client():
    """Create a test client for the API."""
    return TestClient(app)


# =============================================================================
# SOURCE CODE VIEWER TESTS
# =============================================================================

class TestSourceCodeEndpoints:
    """Tests for the /source-code endpoints."""

    def test_list_source_files(self, client):
        """GET /source-code should return list of available files."""
        response = client.get("/source-code")
        assert response.status_code == 200
        files = response.json()
        assert isinstance(files, list)
        assert "domain.py" in files
        assert "constraints.py" in files
        assert "rest_api.py" in files

    def test_get_domain_py(self, client):
        """GET /source-code/domain.py should return file contents."""
        response = client.get("/source-code/domain.py")
        assert response.status_code == 200
        data = response.json()
        assert "filename" in data
        assert "content" in data
        assert data["filename"] == "domain.py"
        assert "@planning_entity" in data["content"]

    def test_get_constraints_py(self, client):
        """GET /source-code/constraints.py should return file contents."""
        response = client.get("/source-code/constraints.py")
        assert response.status_code == 200
        data = response.json()
        assert "content" in data
        assert "@constraint_provider" in data["content"]

    def test_get_nonexistent_file(self, client):
        """GET /source-code/nonexistent.py should return error."""
        response = client.get("/source-code/nonexistent.py")
        assert response.status_code != 200


# =============================================================================
# DEMO DATA TESTS
# =============================================================================

class TestDemoDataEndpoints:
    """Tests for the /demo-data endpoints."""

    def test_list_demo_data(self, client):
        """GET /demo-data should return list of datasets."""
        response = client.get("/demo-data")
        assert response.status_code == 200
        datasets = response.json()
        assert isinstance(datasets, list)

    def test_get_small_dataset(self, client):
        """GET /demo-data/SMALL should return a schedule."""
        response = client.get("/demo-data/SMALL")
        assert response.status_code == 200
        data = response.json()
        assert "resources" in data
        assert "tasks" in data