File size: 5,920 Bytes
cc036ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
"""Contract tests for canvas API endpoints using Schemathesis schema validation."""
import pytest
from fastapi.testclient import TestClient
from main_api_app import app
from tests.contract.conftest import schema


class TestCanvasEndpoints:
    """Contract tests for canvas presentation endpoints."""

    def test_canvas_submit_contracts(self):
        """Test POST /api/canvas/submit conforms to OpenAPI spec."""
        operation = schema["/api/canvas/submit"]["POST"]
        with TestClient(app) as client:
            response = client.post(
                "/api/canvas/submit",
                json={
                    "canvas_id": "test-canvas",
                    "form_data": {"field1": "value1"},
                    "agent_execution_id": None,
                    "agent_id": None
                }
            )
            operation.validate_response(response)
            # Schemathesis validates schema
            assert response.status_code in [200, 400, 401, 422]

    def test_canvas_status_contracts(self):
        """Test GET /api/canvas/status conforms to OpenAPI spec."""
        operation = schema["/api/canvas/status"]["GET"]
        with TestClient(app) as client:
            response = client.get("/api/canvas/status")
            operation.validate_response(response)
            # Schemathesis validates schema
            assert response.status_code in [200, 401, 404, 422]

    def test_canvas_state_contracts(self):
        """Test GET /api/canvas/state/{canvas_id} conforms to OpenAPI spec."""
        operation = schema["/api/canvas/state/{canvas_id}"]["GET"]
        with TestClient(app) as client:
            response = client.get("/api/canvas/state/test-canvas-id")
            operation.validate_response(response)
            # Schemathesis validates schema
            assert response.status_code in [200, 401, 404, 422]


class TestCanvasTypeEndpoints:
    """Contract tests for specialized canvas type endpoints."""

    def test_canvas_docs_contracts(self):
        """Test POST /api/canvas/docs/create conforms to OpenAPI spec."""
        operation = schema["/api/canvas/docs/create"]["POST"]
        with TestClient(app) as client:
            response = client.post(
                "/api/canvas/docs/create",
                json={
                    "canvas_id": "test-docs-canvas",
                    "title": "Test Document",
                    "content": "Test content"
                }
            )
            operation.validate_response(response)
            assert response.status_code in [200, 400, 401, 422]

    def test_canvas_sheets_contracts(self):
        """Test POST /api/canvas/sheets/create conforms to OpenAPI spec."""
        operation = schema["/api/canvas/sheets/create"]["POST"]
        with TestClient(app) as client:
            response = client.post(
                "/api/canvas/sheets/create",
                json={
                    "canvas_id": "test-sheets-canvas",
                    "title": "Test Spreadsheet"
                }
            )
            operation.validate_response(response)
            assert response.status_code in [200, 400, 401, 422]

    def test_canvas_email_contracts(self):
        """Test POST /api/canvas/email/create conforms to OpenAPI spec."""
        operation = schema["/api/canvas/email/create"]["POST"]
        with TestClient(app) as client:
            response = client.post(
                "/api/canvas/email/create",
                json={
                    "canvas_id": "test-email-canvas",
                    "to": "test@example.com",
                    "subject": "Test Email"
                }
            )
            operation.validate_response(response)
            assert response.status_code in [200, 400, 401, 422]

    def test_canvas_orchestration_contracts(self):
        """Test POST /api/canvas/orchestration/create conforms to OpenAPI spec."""
        operation = schema["/api/canvas/orchestration/create"]["POST"]
        with TestClient(app) as client:
            response = client.post(
                "/api/canvas/orchestration/create",
                json={
                    "canvas_id": "test-orchestration-canvas",
                    "title": "Test Orchestration"
                }
            )
            operation.validate_response(response)
            assert response.status_code in [200, 400, 401, 422]

    def test_canvas_terminal_contracts(self):
        """Test POST /api/canvas/terminal/create conforms to OpenAPI spec."""
        operation = schema["/api/canvas/terminal/create"]["POST"]
        with TestClient(app) as client:
            response = client.post(
                "/api/canvas/terminal/create",
                json={
                    "canvas_id": "test-terminal-canvas",
                    "title": "Test Terminal"
                }
            )
            operation.validate_response(response)
            assert response.status_code in [200, 400, 401, 422]

    def test_canvas_coding_contracts(self):
        """Test POST /api/canvas/coding/create conforms to OpenAPI spec."""
        operation = schema["/api/canvas/coding/create"]["POST"]
        with TestClient(app) as client:
            response = client.post(
                "/api/canvas/coding/create",
                json={
                    "canvas_id": "test-coding-canvas",
                    "title": "Test Coding Canvas"
                }
            )
            operation.validate_response(response)
            assert response.status_code in [200, 400, 401, 422]

    def test_canvas_types_contracts(self):
        """Test GET /api/canvas/types conforms to OpenAPI spec."""
        operation = schema["/api/canvas/types"]["GET"]
        with TestClient(app) as client:
            response = client.get("/api/canvas/types")
            operation.validate_response(response)
            assert response.status_code in [200, 401, 422]