Skip to content

Commit a513420

Browse files
rakduttakevalmahajan
authored andcommitted
pytest
Signed-off-by: rakdutta <rakhibiswas@yahoo.com>
1 parent a25fb71 commit a513420

File tree

6 files changed

+62
-62
lines changed

6 files changed

+62
-62
lines changed

tests/unit/mcpgateway/services/test_prompt_service_extended.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ async def test_prompt_name_conflict_error_init(self):
4949
# Test active prompt conflict
5050
error = PromptNameConflictError("test_prompt")
5151
assert error.name == "test_prompt"
52-
assert error.is_active is True
52+
assert error.enabled is True
5353
assert error.prompt_id is None
5454
assert "test_prompt" in str(error)
5555

5656
# Test inactive prompt conflict
5757
error_inactive = PromptNameConflictError("inactive_prompt", False, 123)
5858
assert error_inactive.name == "inactive_prompt"
59-
assert error_inactive.is_active is False
59+
assert error_inactive.enabled is False
6060
assert error_inactive.prompt_id == 123
6161
assert "inactive_prompt" in str(error_inactive)
6262
assert "currently inactive, ID: 123" in str(error_inactive)

tests/unit/mcpgateway/services/test_server_service.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def mock_server(mock_tool, mock_resource, mock_prompt):
8080
server.modified_by = "test_user"
8181
server.created_at = "2023-01-01T00:00:00"
8282
server.updated_at = "2023-01-01T00:00:00"
83-
server.is_active = True
83+
server.enabled = True
8484

8585
# Ownership fields for RBAC
8686
server.owner_email = "user@example.com" # Match default test user
@@ -215,7 +215,7 @@ def query_side_effect(model):
215215
icon="http://example.com/image.jpg",
216216
created_at="2023-01-01T00:00:00",
217217
updated_at="2023-01-01T00:00:00",
218-
is_active=True,
218+
enabled=True,
219219
associated_tools=[],
220220
associated_resources=[],
221221
associated_prompts=[],
@@ -260,7 +260,7 @@ async def test_register_server(self, server_service, test_db, mock_tool, mock_re
260260
mock_db_server.modified_by = "test_user"
261261
mock_db_server.created_at = "2023-01-01T00:00:00"
262262
mock_db_server.updated_at = "2023-01-01T00:00:00"
263-
mock_db_server.is_active = True
263+
mock_db_server.enabled = True
264264
mock_db_server.metrics = []
265265

266266
# Create mock lists with append methods
@@ -307,8 +307,8 @@ def capture_add(server):
307307
test_db.get = Mock(
308308
side_effect=lambda cls, _id: {
309309
(DbTool, "101"): mock_tool,
310-
(DbResource, 201): mock_resource,
311-
(DbPrompt, 301): mock_prompt,
310+
(DbResource, "201"): mock_resource,
311+
(DbPrompt, "301"): mock_prompt,
312312
}.get((cls, _id))
313313
)
314314

@@ -322,10 +322,10 @@ def capture_add(server):
322322
icon="server-icon",
323323
created_at="2023-01-01T00:00:00",
324324
updated_at="2023-01-01T00:00:00",
325-
is_active=True,
325+
enabled=True,
326326
associated_tools=["101"],
327-
associated_resources=[201],
328-
associated_prompts=[301],
327+
associated_resources=["201"],
328+
associated_prompts=["301"],
329329
metrics={
330330
"total_executions": 0,
331331
"successful_executions": 0,
@@ -359,8 +359,8 @@ def capture_add(server):
359359

360360
assert result.name == "test_server"
361361
assert "101" in result.associated_tools
362-
assert 201 in result.associated_resources
363-
assert 301 in result.associated_prompts
362+
assert "201" in result.associated_resources
363+
assert "301" in result.associated_prompts
364364

365365
@pytest.mark.asyncio
366366
async def test_register_server_name_conflict(self, server_service, mock_server, test_db):
@@ -428,10 +428,10 @@ async def test_list_servers(self, server_service, mock_server, test_db):
428428
icon="http://example.com/image.jgp",
429429
created_at="2023-01-01T00:00:00",
430430
updated_at="2023-01-01T00:00:00",
431-
is_active=True,
431+
enabled=True,
432432
associated_tools=["101"],
433-
associated_resources=[201],
434-
associated_prompts=[301],
433+
associated_resources=["201"],
434+
associated_prompts=["301"],
435435
metrics={
436436
"total_executions": 0,
437437
"successful_executions": 0,
@@ -464,10 +464,10 @@ async def test_get_server(self, server_service, mock_server, test_db):
464464
icon="http://example.com/image.jpg",
465465
created_at="2023-01-01T00:00:00",
466466
updated_at="2023-01-01T00:00:00",
467-
is_active=True,
467+
enabled=True,
468468
associated_tools=["101"],
469-
associated_resources=[201],
470-
associated_prompts=[301],
469+
associated_resources=["201"],
470+
associated_prompts=["301"],
471471
metrics={
472472
"total_executions": 0,
473473
"successful_executions": 0,
@@ -568,10 +568,10 @@ async def test_update_server(self, server_service, mock_server, test_db, mock_to
568568
icon="http://example.com/image.jpg",
569569
created_at="2023-01-01T00:00:00",
570570
updated_at="2023-01-01T00:00:00",
571-
is_active=True,
571+
enabled=True,
572572
associated_tools=["102"],
573-
associated_resources=[202],
574-
associated_prompts=[302],
573+
associated_resources=["202"],
574+
associated_prompts=["302"],
575575
metrics={
576576
"total_executions": 0,
577577
"successful_executions": 0,
@@ -660,7 +660,7 @@ async def test_update_server_name_conflict(self, server_service, mock_server, te
660660
server_team.visibility = "team"
661661
server_team.team_id = "teamA"
662662

663-
conflict_team_server = types.SimpleNamespace(id="3", name="existing_server", is_active=True, visibility="team", team_id="teamA")
663+
conflict_team_server = types.SimpleNamespace(id="3", name="existing_server", enabled=True, visibility="team", team_id="teamA")
664664

665665
test_db.get = Mock(return_value=server_team)
666666
mock_scalar = Mock()
@@ -688,7 +688,7 @@ async def test_update_server_name_conflict(self, server_service, mock_server, te
688688
server_public.visibility = "public"
689689
server_public.team_id = None
690690

691-
conflict_public_server = types.SimpleNamespace(id="5", name="existing_server", is_active=True, visibility="public", team_id=None)
691+
conflict_public_server = types.SimpleNamespace(id="5", name="existing_server", enabled=True, visibility="public", team_id=None)
692692

693693
test_db.get = Mock(return_value=server_public)
694694
mock_scalar = Mock()
@@ -727,10 +727,10 @@ async def test_toggle_server_status(self, server_service, mock_server, test_db):
727727
icon="server-icon",
728728
created_at="2023-01-01T00:00:00",
729729
updated_at="2023-01-01T00:00:00",
730-
is_active=False,
730+
enabled=False,
731731
associated_tools=["101"],
732-
associated_resources=[201],
733-
associated_prompts=[301],
732+
associated_resources=["201"],
733+
associated_prompts=["301"],
734734
metrics={
735735
"total_executions": 0,
736736
"successful_executions": 0,
@@ -750,7 +750,7 @@ async def test_toggle_server_status(self, server_service, mock_server, test_db):
750750
test_db.commit.assert_called_once()
751751
test_db.refresh.assert_called_once()
752752
server_service._notify_server_deactivated.assert_called_once()
753-
assert result.is_active is False
753+
assert result.enabled is False
754754

755755
# --------------------------- delete -------------------------------- #
756756
@pytest.mark.asyncio
@@ -821,7 +821,7 @@ def capture_add(server):
821821
icon=None,
822822
created_at="2023-01-01T00:00:00",
823823
updated_at="2023-01-01T00:00:00",
824-
is_active=True,
824+
enabled=True,
825825
associated_tools=[],
826826
associated_resources=[],
827827
associated_prompts=[],
@@ -892,7 +892,7 @@ def capture_add(server):
892892
icon=None,
893893
created_at="2023-01-01T00:00:00",
894894
updated_at="2023-01-01T00:00:00",
895-
is_active=True,
895+
enabled=True,
896896
associated_tools=[],
897897
associated_resources=[],
898898
associated_prompts=[],
@@ -956,7 +956,7 @@ def capture_add(server):
956956
icon=None,
957957
created_at="2023-01-01T00:00:00",
958958
updated_at="2023-01-01T00:00:00",
959-
is_active=True,
959+
enabled=True,
960960
associated_tools=[],
961961
associated_resources=[],
962962
associated_prompts=[],
@@ -1018,7 +1018,7 @@ async def test_update_server_uuid_normalization(self, server_service, test_db):
10181018
existing_server = MagicMock(spec=DbServer)
10191019
existing_server.id = "oldserverid"
10201020
existing_server.name = "Old Name"
1021-
existing_server.is_active = True
1021+
existing_server.enabled = True
10221022
existing_server.tools = []
10231023
existing_server.resources = []
10241024
existing_server.prompts = []
@@ -1053,7 +1053,7 @@ async def test_update_server_uuid_normalization(self, server_service, test_db):
10531053
icon=None,
10541054
created_at="2023-01-01T00:00:00",
10551055
updated_at="2023-01-01T00:00:00",
1056-
is_active=True,
1056+
enabled=True,
10571057
associated_tools=[],
10581058
associated_resources=[],
10591059
associated_prompts=[],

tests/unit/mcpgateway/test_display_name_uuid_features.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def test_server_create_with_custom_uuid(self, db_session):
160160
custom_uuid = "12345678-1234-1234-1234-123456789abc"
161161

162162
# Create server with custom UUID
163-
db_server = DbServer(id=custom_uuid, name="Test Server", description="Test server with custom UUID", is_active=True)
163+
db_server = DbServer(id=custom_uuid, name="Test Server", description="Test server with custom UUID", enabled=True)
164164

165165
db_session.add(db_server)
166166
db_session.commit()
@@ -173,7 +173,7 @@ def test_server_create_with_custom_uuid(self, db_session):
173173
def test_server_create_without_uuid(self, db_session):
174174
"""Test creating a server without specifying UUID (auto-generated)."""
175175
# Create server without specifying UUID
176-
db_server = DbServer(name="Auto UUID Server", description="Test server with auto UUID", is_active=True)
176+
db_server = DbServer(name="Auto UUID Server", description="Test server with auto UUID", enabled=True)
177177

178178
db_session.add(db_server)
179179
db_session.commit()
@@ -190,7 +190,7 @@ def test_server_update_uuid(self, db_session):
190190
new_uuid = "new-uuid-5678"
191191

192192
# Create server with original UUID
193-
db_server = DbServer(id=original_uuid, name="UUID Update Server", description="Test server for UUID update", is_active=True)
193+
db_server = DbServer(id=original_uuid, name="UUID Update Server", description="Test server for UUID update", enabled=True)
194194

195195
db_session.add(db_server)
196196
db_session.commit()
@@ -211,12 +211,12 @@ def test_server_uuid_uniqueness(self, db_session):
211211
duplicate_uuid = "duplicate-uuid-1234"
212212

213213
# Create first server with UUID
214-
db_server1 = DbServer(id=duplicate_uuid, name="First Server", description="First server", is_active=True)
214+
db_server1 = DbServer(id=duplicate_uuid, name="First Server", description="First server", enabled=True)
215215
db_session.add(db_server1)
216216
db_session.commit()
217217

218218
# Try to create second server with same UUID
219-
db_server2 = DbServer(id=duplicate_uuid, name="Second Server", description="Second server", is_active=True)
219+
db_server2 = DbServer(id=duplicate_uuid, name="Second Server", description="Second server", enabled=True)
220220

221221
db_session.add(db_server2)
222222

@@ -333,7 +333,7 @@ def capture_add(server):
333333
icon=None,
334334
created_at="2023-01-01T00:00:00",
335335
updated_at="2023-01-01T00:00:00",
336-
is_active=True,
336+
enabled=True,
337337
associated_tools=[],
338338
associated_resources=[],
339339
associated_prompts=[],
@@ -401,7 +401,7 @@ def capture_add(server):
401401
icon=None,
402402
created_at="2023-01-01T00:00:00",
403403
updated_at="2023-01-01T00:00:00",
404-
is_active=True,
404+
enabled=True,
405405
associated_tools=[],
406406
associated_resources=[],
407407
associated_prompts=[],
@@ -465,7 +465,7 @@ def capture_add(server):
465465
icon=None,
466466
created_at="2023-01-01T00:00:00",
467467
updated_at="2023-01-01T00:00:00",
468-
is_active=True,
468+
enabled=True,
469469
associated_tools=[],
470470
associated_resources=[],
471471
associated_prompts=[],
@@ -561,7 +561,7 @@ def test_database_storage_format_verification(self, db_session):
561561
id=expected_hex, # Simulate the normalized UUID
562562
name="Storage Test Server",
563563
description="Test UUID storage format",
564-
is_active=True,
564+
enabled=True,
565565
)
566566

567567
db_session.add(db_server)
@@ -616,7 +616,7 @@ def capture_add(server):
616616
icon=None,
617617
created_at="2023-01-01T00:00:00",
618618
updated_at="2023-01-01T00:00:00",
619-
is_active=True,
619+
enabled=True,
620620
associated_tools=[],
621621
associated_resources=[],
622622
associated_prompts=[],

tests/unit/mcpgateway/test_main.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@
5555
"icon": "server-icon",
5656
"created_at": "2023-01-01T00:00:00+00:00",
5757
"updated_at": "2023-01-01T00:00:00+00:00",
58-
"is_active": True,
58+
"enabled": True,
5959
"associated_tools": ["101"],
60-
"associated_resources": [201],
61-
"associated_prompts": [301],
60+
"associated_resources": ["201"],
61+
"associated_prompts": ["301"],
6262
"metrics": MOCK_METRICS,
6363
}
6464

@@ -125,7 +125,7 @@ def camel_to_snake_tool(d: dict) -> dict:
125125
"size": 12,
126126
"created_at": "2023-01-01T00:00:00+00:00",
127127
"updated_at": "2023-01-01T00:00:00+00:00",
128-
"is_active": True,
128+
"enabled": True,
129129
"metrics": MOCK_METRICS,
130130
}
131131

@@ -137,7 +137,7 @@ def camel_to_snake_tool(d: dict) -> dict:
137137
"arguments": [],
138138
"created_at": "2023-01-01T00:00:00+00:00",
139139
"updated_at": "2023-01-01T00:00:00+00:00",
140-
"is_active": True,
140+
"enabled": True,
141141
"metrics": MOCK_METRICS,
142142
}
143143

@@ -505,7 +505,7 @@ def test_update_server_endpoint(self, mock_update, test_client, auth_headers):
505505
def test_toggle_server_status(self, mock_toggle, test_client, auth_headers):
506506
"""Test toggling server active/inactive status."""
507507
updated_server = MOCK_SERVER_READ.copy()
508-
updated_server["is_active"] = False
508+
updated_server["enabled"] = False
509509
mock_toggle.return_value = ServerRead(**updated_server)
510510
response = test_client.post("/servers/1/toggle?activate=false", headers=auth_headers)
511511
assert response.status_code == 200
@@ -740,7 +740,7 @@ def test_list_resource_templates(self, mock_list, test_client, auth_headers):
740740
def test_toggle_resource_status(self, mock_toggle, test_client, auth_headers):
741741
"""Test toggling resource active/inactive status."""
742742
mock_resource = MagicMock()
743-
mock_resource.model_dump.return_value = {"id": 1, "is_active": False}
743+
mock_resource.model_dump.return_value = {"id": "1", "enabled": False}
744744
mock_toggle.return_value = mock_resource
745745
response = test_client.post("/resources/1/toggle?activate=false", headers=auth_headers)
746746
assert response.status_code == 200

tests/unit/mcpgateway/test_main_extended.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ def test_server_toggle_edge_cases(self, test_client, auth_headers):
290290
"icon": None,
291291
"created_at": "2023-01-01T00:00:00+00:00",
292292
"updated_at": "2023-01-01T00:00:00+00:00",
293-
"is_active": True,
293+
"enabled": True,
294294
"associated_tools": [],
295295
"associated_resources": [],
296296
"associated_prompts": [],
@@ -313,7 +313,7 @@ def test_server_toggle_edge_cases(self, test_client, auth_headers):
313313
assert response.status_code == 200
314314

315315
# Test activate=false
316-
mock_server_data["is_active"] = False
316+
mock_server_data["enabled"] = False
317317
mock_toggle.return_value = ServerRead(**mock_server_data)
318318
response = test_client.post("/servers/1/toggle?activate=false", headers=auth_headers)
319319
assert response.status_code == 200

0 commit comments

Comments
 (0)