""" Smoke tests - Basic tests to verify the testing framework is working properly """ import pytest import asyncio from tests.test_client import TestWebSocketClient, test_clients class TestSmokeTests: """Basic smoke tests to verify the testing framework""" @pytest.mark.asyncio async def test_single_client_connection(self): """Test that a single client can connect to the server""" client = TestWebSocketClient("smoke_test") # Should be able to connect connected = await client.connect() assert connected == True assert client.connected == True # Should have player data assert client.player_data is not None assert client.player_data["nickname"] == "smoke_test" assert client.get_money() == 100000 # Starting money assert client.get_population() == 0 # Starting population # Clean up await client.disconnect() @pytest.mark.asyncio async def test_context_manager_client(self): """Test the context manager for test clients""" async with test_clients("context_test") as [client]: assert client.connected == True assert client.player_data["nickname"] == "context_test" # Should be able to send a simple action await client.send_cursor_move(5, 10) # Connection should work without errors # Client should be disconnected after context exit assert client.connected == False @pytest.mark.asyncio async def test_multiple_client_context_manager(self): """Test multiple clients using context manager""" async with test_clients("client1", "client2") as [c1, c2]: assert len([c1, c2]) == 2 assert c1.connected == True assert c2.connected == True assert c1.player_data["nickname"] == "client1" assert c2.player_data["nickname"] == "client2" # Both should be disconnected assert c1.connected == False assert c2.connected == False @pytest.mark.asyncio async def test_basic_building_placement(self): """Test basic building placement works""" async with test_clients("builder_unique") as [client]: # Should be able to place a building at unique coordinates import time x, y = int(time.time() % 100), int((time.time() * 2) % 100) await client.place_building("road", x, y) # Should receive confirmation message = await client.receive_message(timeout=2.0) assert message is not None assert message["type"] == "building_placed" assert message["building"]["type"] == "road" @pytest.mark.asyncio async def test_basic_chat(self): """Test basic chat functionality""" async with test_clients("chatter1", "chatter2") as [sender, receiver]: # Clear any initial messages receiver.clear_messages() # Send chat message await sender.send_chat("Hello from smoke test!") # Receiver should get the message message = await receiver.receive_message(timeout=2.0) assert message is not None assert message["type"] == "chat" assert message["message"] == "Hello from smoke test!" assert message["nickname"] == "chatter1"