Files
geutebruck/geutebruck-api/test_action_mappings.py
Administrator 14893e62a5 feat: Geutebruck GeViScope/GeViSoft Action Mapping System - MVP
This MVP release provides a complete full-stack solution for managing action mappings
in Geutebruck's GeViScope and GeViSoft video surveillance systems.

## Features

### Flutter Web Application (Port 8081)
- Modern, responsive UI for managing action mappings
- Action picker dialog with full parameter configuration
- Support for both GSC (GeViScope) and G-Core server actions
- Consistent UI for input and output actions with edit/delete capabilities
- Real-time action mapping creation, editing, and deletion
- Server categorization (GSC: prefix for GeViScope, G-Core: prefix for G-Core servers)

### FastAPI REST Backend (Port 8000)
- RESTful API for action mapping CRUD operations
- Action template service with comprehensive action catalog (247 actions)
- Server management (G-Core and GeViScope servers)
- Configuration tree reading and writing
- JWT authentication with role-based access control
- PostgreSQL database integration

### C# SDK Bridge (gRPC, Port 50051)
- Native integration with GeViSoft SDK (GeViProcAPINET_4_0.dll)
- Action mapping creation with correct binary format
- Support for GSC and G-Core action types
- Proper Camera parameter inclusion in action strings (fixes CrossSwitch bug)
- Action ID lookup table with server-specific action IDs
- Configuration reading/writing via SetupClient

## Bug Fixes
- **CrossSwitch Bug**: GSC and G-Core actions now correctly display camera/PTZ head parameters in GeViSet
- Action strings now include Camera parameter: `@ PanLeft (Comment: "", Camera: 101028)`
- Proper filter flags and VideoInput=0 for action mappings
- Correct action ID assignment (4198 for GSC, 9294 for G-Core PanLeft)

## Technical Stack
- **Frontend**: Flutter Web, Dart, Dio HTTP client
- **Backend**: Python FastAPI, PostgreSQL, Redis
- **SDK Bridge**: C# .NET 8.0, gRPC, GeViSoft SDK
- **Authentication**: JWT tokens
- **Configuration**: GeViSoft .set files (binary format)

## Credentials
- GeViSoft/GeViScope: username=sysadmin, password=masterkey
- Default admin: username=admin, password=admin123

## Deployment
All services run on localhost:
- Flutter Web: http://localhost:8081
- FastAPI: http://localhost:8000
- SDK Bridge gRPC: localhost:50051
- GeViServer: localhost (default port)

Generated with Claude Code (https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-31 18:10:54 +01:00

160 lines
5.3 KiB
Python

#!/usr/bin/env python3
"""
Test script for action mappings endpoint
"""
import requests
import json
import sys
# API endpoint
BASE_URL = "http://localhost:8000"
LOGIN_ENDPOINT = f"{BASE_URL}/api/v1/auth/login"
ACTION_MAPPINGS_ENDPOINT = f"{BASE_URL}/api/v1/configuration/action-mappings/export"
# Default admin credentials (from init_db.py or common defaults)
USERNAME = "admin"
PASSWORD = "admin"
def main():
print("=" * 60)
print("Testing Action Mappings Endpoint")
print("=" * 60)
# Step 1: Login to get token
print(f"\n[1/3] Logging in as '{USERNAME}'...")
try:
login_response = requests.post(
LOGIN_ENDPOINT,
data={
"username": USERNAME,
"password": PASSWORD
},
headers={"Content-Type": "application/x-www-form-urlencoded"}
)
if login_response.status_code != 200:
print(f" ❌ Login failed: {login_response.status_code}")
print(f" Response: {login_response.text}")
print(f"\n Trying alternative credentials...")
# Try alternative common credentials
alternatives = [
("admin", "masterkey"),
("sysadmin", "masterkey"),
("administrator", "admin"),
]
for alt_user, alt_pass in alternatives:
print(f" Trying {alt_user}:{alt_pass}...")
login_response = requests.post(
LOGIN_ENDPOINT,
data={"username": alt_user, "password": alt_pass},
headers={"Content-Type": "application/x-www-form-urlencoded"}
)
if login_response.status_code == 200:
print(f" ✅ Login successful with {alt_user}")
break
else:
print(f"\n ❌ All login attempts failed")
print(f"\n You may need to create a test user first.")
return 1
else:
print(f" ✅ Login successful")
token_data = login_response.json()
access_token = token_data.get("access_token")
if not access_token:
print(f" ❌ No access token in response")
return 1
except requests.exceptions.ConnectionError:
print(f" ❌ Cannot connect to API server at {BASE_URL}")
print(f" Make sure the services are running")
return 1
except Exception as e:
print(f" ❌ Login error: {e}")
return 1
# Step 2: Call action mappings endpoint
print(f"\n[2/3] Calling action mappings endpoint...")
try:
headers = {
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/json"
}
mappings_response = requests.get(
ACTION_MAPPINGS_ENDPOINT,
headers=headers,
timeout=30
)
if mappings_response.status_code != 200:
print(f" ❌ Request failed: {mappings_response.status_code}")
print(f" Response: {mappings_response.text}")
return 1
print(f" ✅ Request successful")
except Exception as e:
print(f" ❌ Request error: {e}")
return 1
# Step 3: Parse and display results
print(f"\n[3/3] Analyzing results...")
try:
result = mappings_response.json()
print(f"\n Success: {result.get('success', False)}")
print(f" Total Count: {result.get('total_count', 0)}")
mappings = result.get('mappings', [])
print(f" Mappings Found: {len(mappings)}")
if result.get('error_message'):
print(f" Error: {result['error_message']}")
# Display detailed results
print("\n" + "=" * 60)
print("RESULTS")
print("=" * 60)
if mappings:
total_actions = sum(len(m.get('actions', [])) for m in mappings)
print(f"\n✅ SUCCESS: Found {len(mappings)} Rules markers with {total_actions} total actions")
print(f"\nFirst 5 mappings:")
for i, mapping in enumerate(mappings[:5], 1):
actions = mapping.get('actions', [])
print(f"\n [{i}] Rules marker at offset {mapping.get('start_offset', 0)}")
print(f" Actions ({len(actions)}):")
for action in actions[:3]:
print(f" - {action}")
if len(actions) > 3:
print(f" ... and {len(actions) - 3} more")
if len(mappings) > 5:
print(f"\n ... and {len(mappings) - 5} more Rules markers")
print(f"\n{'='*60}")
print(f"✅ TEST PASSED: Action mappings endpoint is working!")
print(f"{'='*60}")
return 0
else:
print(f"\n❌ FAILED: No mappings found (expected ~60)")
print(f"\nFull response:")
print(json.dumps(result, indent=2))
print(f"\n{'='*60}")
print(f"❌ TEST FAILED: Action mappings endpoint returns empty array")
print(f"{'='*60}")
return 1
except Exception as e:
print(f" ❌ Parse error: {e}")
print(f" Raw response: {mappings_response.text[:500]}")
return 1
if __name__ == "__main__":
sys.exit(main())