-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_app.py
More file actions
176 lines (139 loc) · 5.92 KB
/
test_app.py
File metadata and controls
176 lines (139 loc) · 5.92 KB
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
"""
Test suite for OMI GitHub Issues Integration
"""
import pytest
from fastapi.testclient import TestClient
from main import app
import os
# Test client
client = TestClient(app)
class TestHealthAndBasics:
"""Test health checks and basic endpoints"""
def test_health_endpoint(self):
"""Test health check endpoint returns 200"""
response = client.get("/health")
assert response.status_code == 200
data = response.json()
assert data["status"] == "healthy"
assert data["service"] == "omi-github-issues"
def test_root_endpoint_without_uid(self):
"""Test root endpoint without UID returns info"""
response = client.get("/")
assert response.status_code == 200
data = response.json()
assert data["app"] == "OMI GitHub Issues Integration"
assert data["version"] == "2.0.0"
assert "endpoints" in data
class TestManifest:
"""Test Omi tools manifest endpoint"""
def test_manifest_endpoint(self):
"""Test manifest endpoint returns tools"""
response = client.get("/.well-known/omi-tools.json")
assert response.status_code == 200
data = response.json()
assert "tools" in data
assert len(data["tools"]) > 0
def test_manifest_tools_structure(self):
"""Test each tool has required fields"""
response = client.get("/.well-known/omi-tools.json")
data = response.json()
tools = data["tools"]
required_fields = ["name", "description", "endpoint", "method", "parameters"]
for tool in tools:
for field in required_fields:
assert field in tool, f"Tool missing field: {field}"
# Verify tool names
assert tool["name"] in [
"create_issue", "list_repos", "list_issues",
"get_issue", "list_labels", "add_comment", "code_feature"
]
class TestChatTools:
"""Test chat tool endpoints (without authentication)"""
def test_create_issue_without_uid(self):
"""Test create_issue returns error without UID"""
response = client.post("/tools/create_issue", json={})
assert response.status_code == 200
data = response.json()
assert "error" in data
assert "User ID is required" in data["error"]
def test_create_issue_without_title(self):
"""Test create_issue returns error without title"""
response = client.post("/tools/create_issue", json={"uid": "test-user"})
assert response.status_code == 200
data = response.json()
assert "error" in data
assert "title is required" in data["error"]
def test_list_repos_without_uid(self):
"""Test list_repos returns error without UID"""
response = client.post("/tools/list_repos", json={})
assert response.status_code == 200
data = response.json()
assert "error" in data
def test_list_issues_without_uid(self):
"""Test list_issues returns error without UID"""
response = client.post("/tools/list_issues", json={})
assert response.status_code == 200
data = response.json()
assert "error" in data
def test_get_issue_without_uid(self):
"""Test get_issue returns error without UID"""
response = client.post("/tools/get_issue", json={})
assert response.status_code == 200
data = response.json()
assert "error" in data
def test_list_labels_without_uid(self):
"""Test list_labels returns error without UID"""
response = client.post("/tools/list_labels", json={})
assert response.status_code == 200
data = response.json()
assert "error" in data
def test_add_comment_without_uid(self):
"""Test add_comment returns error without UID"""
response = client.post("/tools/add_comment", json={})
assert response.status_code == 200
data = response.json()
assert "error" in data
class TestSetupEndpoints:
"""Test setup and configuration endpoints"""
def test_setup_completed_unauthenticated(self):
"""Test setup-completed returns false for new user"""
response = client.get("/setup-completed?uid=new-test-user")
assert response.status_code == 200
data = response.json()
assert "is_setup_completed" in data
assert data["is_setup_completed"] == False
def test_auth_endpoint_requires_uid(self):
"""Test auth endpoint requires UID parameter"""
response = client.get("/auth")
assert response.status_code == 422 # Validation error
class TestModuleImports:
"""Test that all modules can be imported"""
def test_import_github_client(self):
"""Test GitHub client can be imported"""
import github_client
assert hasattr(github_client, 'GitHubClient')
def test_import_issue_detector(self):
"""Test issue detector can be imported"""
import issue_detector
assert hasattr(issue_detector, 'ai_select_labels')
def test_import_simple_storage(self):
"""Test simple storage can be imported"""
import simple_storage
assert hasattr(simple_storage, 'SimpleUserStorage')
def test_import_models(self):
"""Test models can be imported"""
import models
assert hasattr(models, 'ChatToolResponse')
class TestEnvironment:
"""Test environment configuration"""
def test_required_env_vars(self):
"""Test that environment variables are loaded"""
# These should be loaded from .env or .env.example
from dotenv import load_dotenv
load_dotenv()
# Check that at least some env vars exist
assert os.getenv("APP_HOST") is not None
assert os.getenv("APP_PORT") is not None
if __name__ == "__main__":
# Run tests with pytest
pytest.main([__file__, "-v", "--tb=short"])