#!/usr/bin/env python3 """ ISUP 5.0 Integration Test Tests the complete ISUP 5.0 implementation """ import asyncio import time import requests from datetime import datetime async def test_isup5_integration(): """Test complete ISUP 5.0 integration""" print("๐Ÿงช ISUP 5.0 Integration Test") print("=" * 50) # Test 1: Check if server is running print("\n1. Testing server health...") try: response = requests.get("http://localhost:7860/api/health", timeout=5) if response.status_code == 200: health = response.json() print(f"โœ… Server health: {health['status']}") print(f"โœ… ISUP server: {health['isup_server']}") else: print("โŒ Server health check failed") return False except Exception as e: print(f"โŒ Cannot connect to server: {e}") print("๐Ÿ’ก Make sure to run: python start_isup5.py") return False # Test 2: Check protocol info print("\n2. Testing protocol information...") try: response = requests.get("http://localhost:7860/api/protocol/info", timeout=5) if response.status_code == 200: protocol = response.json() print(f"โœ… Protocol: {protocol['protocol']} {protocol['version']}") print(f"โœ… Binary protocol: {protocol['binary_protocol']}") print(f"โœ… Authentication: {protocol['authentication']}") else: print("โŒ Protocol info failed") except Exception as e: print(f"โŒ Protocol info error: {e}") # Test 3: Check initial connections print("\n3. Testing initial connection status...") try: response = requests.get("http://localhost:7860/api/isup/connections", timeout=5) if response.status_code == 200: connections = response.json() print(f"โœ… Total connections: {connections['total_connections']}") print(f"โœ… Active connections: {connections['active_connections']}") if connections['devices']: for device in connections['devices']: print(f" ๐Ÿ“ฑ Device {device['device_id']}: {device['status']}") else: print(" ๐Ÿ“ฑ No devices connected (expected initially)") else: print("โŒ Connection status failed") except Exception as e: print(f"โŒ Connection status error: {e}") # Test 4: Check device configuration print("\n4. Testing device configuration...") try: response = requests.get("http://localhost:7860/api/config/devices", timeout=5) if response.status_code == 200: config = response.json() print(f"โœ… Authorized devices: {config['total']}") for serial, device in config['authorized_devices'].items(): print(f" ๐Ÿ”ง {device['device_type']} (ID: {device['device_id']})") print(f" Serial: {serial}") print(f" ISUP Version: {device['isup_version']}") else: print("โŒ Device config failed") except Exception as e: print(f"โŒ Device config error: {e}") # Test 5: Test device commands (should fail without connected device) print("\n5. Testing device commands...") try: response = requests.post("http://localhost:7860/api/devices/255/open_door", timeout=5) if response.status_code == 404: print("โœ… Door command correctly rejected (no device connected)") else: print(f"โš ๏ธ Unexpected response: {response.status_code}") except Exception as e: print(f"โŒ Device command error: {e}") print("\n" + "=" * 50) print("๐ŸŽฏ INTEGRATION TEST SUMMARY") print("=" * 50) print("โœ… ISUP 5.0 server is running correctly") print("โœ… All API endpoints are responding") print("โœ… Device configuration is loaded") print("โœ… Ready for real device connections") print() print("๐Ÿ”ง NEXT STEPS:") print("1. Configure your DS-K1T342MFX device:") print(" โ€ข Platform Access Mode: ISUP") print(" โ€ข Protocol Version: 5.0") print(" โ€ข Server Address: your-server-ip") print(" โ€ข Port: 7660") print(" โ€ข Device ID: 255") print(" โ€ข EHome Key: hikvision123") print() print("2. OR run the device simulator:") print(" python test/isup5_device_simulator.py") print() print("3. Monitor connections at:") print(" http://localhost:7860") return True def test_binary_message_format(): """Test binary message format""" print("\n๐Ÿ”ฌ Testing ISUP 5.0 Binary Message Format...") # Import our ISUP classes import sys import os sys.path.append(os.path.dirname(os.path.abspath(__file__))) from isup5_server import ISUPMessage, ISUPHeader, ISUPMessageType, ISUP_VERSION # Test message creation message = ISUPMessage() message.header.version = ISUP_VERSION message.header.message_type = ISUPMessageType.REGISTER_REQ.value message.header.sequence = 1 message.header.device_id = "255" message.data = b"test_data" # Test packing packed = message.pack() print(f"โœ… Message packed: {len(packed)} bytes") # Test unpacking new_message = ISUPMessage() if new_message.unpack(packed): print(f"โœ… Message unpacked successfully") print(f" Version: 0x{new_message.header.version:02X}") print(f" Type: 0x{new_message.header.message_type:02X}") print(f" Sequence: {new_message.header.sequence}") print(f" Device ID: {new_message.header.device_id}") print(f" Data: {new_message.data}") else: print("โŒ Message unpacking failed") return False return True async def main(): """Main test function""" print(f"๐Ÿš€ Starting ISUP 5.0 Tests at {datetime.now()}") # Test binary message format if not test_binary_message_format(): print("โŒ Binary message test failed") return # Test integration if not await test_isup5_integration(): print("โŒ Integration test failed") return print("\n๐ŸŽ‰ All tests passed! ISUP 5.0 server is ready for production.") if __name__ == "__main__": asyncio.run(main())