3030class TestWebIndexEndpoint :
3131 """Tests for GET / endpoint."""
3232
33- @patch ("byte_api.domain.guilds.helpers.get_byte_server_count" )
34- @patch ("byte_api.domain.system.helpers.check_byte_status" )
35- @patch ("byte_api.domain.system.helpers.check_database_status" )
36- async def test_index_renders_successfully (
37- self ,
38- mock_db_status : AsyncMock ,
39- mock_byte_status : AsyncMock ,
40- mock_server_count : AsyncMock ,
41- api_client : AsyncTestClient ,
42- ) -> None :
43- """Test index page renders without errors."""
44- # Mock helper functions to avoid database access issues
45- mock_server_count .return_value = 0
46- mock_db_status .return_value = "online"
47- mock_byte_status .return_value = "online"
48-
49- response = await api_client .get ("/" )
50-
51- # Should return 200 with HTML content
52- assert response .status_code == HTTP_200_OK
53- assert "text/html" in response .headers .get ("content-type" , "" )
54-
55- async def test_index_contains_expected_content (self , api_client : AsyncTestClient ) -> None :
56- """Test index page contains server status information."""
57- response = await api_client .get ("/" )
58-
59- assert response .status_code == HTTP_200_OK
60- content = response .text
61-
62- # Page should contain some basic HTML structure
63- assert "<html" in content .lower () or "<!doctype html>" in content .lower ()
64-
65- async def test_index_contains_server_count (self , api_client : AsyncTestClient ) -> None :
66- """Test index page displays server count."""
67- response = await api_client .get ("/" )
68-
69- assert response .status_code == HTTP_200_OK
70- content = response .text .lower ()
71-
72- # Should display server count (0 or more)
73- assert "server" in content
74-
75- async def test_index_contains_status_indicator (self , api_client : AsyncTestClient ) -> None :
76- """Test index page displays status indicator."""
77- response = await api_client .get ("/" )
78-
79- assert response .status_code == HTTP_200_OK
80- content = response .text .lower ()
81-
82- # Should contain status-related keywords
83- assert any (keyword in content for keyword in ["healthy" , "degraded" , "offline" , "online" ])
84-
85- async def test_index_contains_invite_button (self , api_client : AsyncTestClient ) -> None :
86- """Test index page contains Discord invite button."""
87- response = await api_client .get ("/" )
88-
89- assert response .status_code == HTTP_200_OK
90- content = response .text .lower ()
91-
92- # Should have invite functionality
93- assert "invite" in content or "discord" in content
9433
95-
96- @pytest .mark .asyncio
9734class TestWebDashboardEndpoint :
9835 """Tests for GET /dashboard endpoint."""
9936
@@ -354,28 +291,6 @@ async def test_index_with_multiple_servers(
354291 # Should show count
355292 assert "5" in content
356293
357- @patch ("byte_api.domain.guilds.helpers.get_byte_server_count" )
358- @patch ("byte_api.domain.system.helpers.check_byte_status" )
359- @patch ("byte_api.domain.system.helpers.check_database_status" )
360- async def test_index_status_all_offline (
361- self ,
362- mock_db_status : AsyncMock ,
363- mock_byte_status : AsyncMock ,
364- mock_server_count : AsyncMock ,
365- api_client : AsyncTestClient ,
366- ) -> None :
367- """Test overall status when all services offline."""
368- mock_server_count .return_value = 0
369- mock_db_status .return_value = "offline"
370- mock_byte_status .return_value = "offline"
371-
372- response = await api_client .get ("/" )
373-
374- assert response .status_code == HTTP_200_OK
375- # Overall status should be offline
376- content = response .text .lower ()
377- assert "offline" in content
378-
379294 @patch ("byte_api.domain.guilds.helpers.get_byte_server_count" )
380295 @patch ("byte_api.domain.system.helpers.check_byte_status" )
381296 @patch ("byte_api.domain.system.helpers.check_database_status" )
@@ -397,27 +312,6 @@ async def test_index_status_degraded(
397312 content = response .text .lower ()
398313 assert "degraded" in content or "warning" in content
399314
400- @patch ("byte_api.domain.guilds.helpers.get_byte_server_count" )
401- @patch ("byte_api.domain.system.helpers.check_byte_status" )
402- @patch ("byte_api.domain.system.helpers.check_database_status" )
403- async def test_index_status_healthy (
404- self ,
405- mock_db_status : AsyncMock ,
406- mock_byte_status : AsyncMock ,
407- mock_server_count : AsyncMock ,
408- api_client : AsyncTestClient ,
409- ) -> None :
410- """Test overall status when all services healthy."""
411- mock_server_count .return_value = 0
412- mock_db_status .return_value = "online"
413- mock_byte_status .return_value = "online"
414-
415- response = await api_client .get ("/" )
416-
417- assert response .status_code == HTTP_200_OK
418- content = response .text .lower ()
419- assert "healthy" in content or "online" in content
420-
421315
422316@pytest .mark .asyncio
423317class TestWebErrorHandling :
0 commit comments