75 lines
2.7 KiB
Python
75 lines
2.7 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Quick validation script to verify function signature matches LoadTestBase expectations
|
|
Run this before load testing to catch signature mismatches early
|
|
"""
|
|
import sys
|
|
from pathlib import Path
|
|
import inspect
|
|
|
|
# Add project root to path
|
|
project_root = Path(__file__).parent.parent.parent
|
|
sys.path.insert(0, str(project_root))
|
|
|
|
from utils.load_test_base import LoadTestBase
|
|
from tests.load_tests.test_generic_load_assessments import complete_assessment_flow_for_student
|
|
|
|
def validate_signature():
|
|
"""Validate that function signature matches LoadTestBase expectations"""
|
|
print("🔍 Validating function signature...\n")
|
|
|
|
# Get function signature
|
|
sig = inspect.signature(complete_assessment_flow_for_student)
|
|
params = list(sig.parameters.keys())
|
|
|
|
print(f"Function: complete_assessment_flow_for_student")
|
|
print(f"Parameters: {params}\n")
|
|
|
|
# Check first parameter is user_id
|
|
if params[0] != 'user_id':
|
|
print(f"❌ ERROR: First parameter must be 'user_id', got '{params[0]}'")
|
|
return False
|
|
|
|
# Check required parameters
|
|
required = ['user_id', 'student_info', 'student_index']
|
|
for req in required:
|
|
if req not in params:
|
|
print(f"❌ ERROR: Missing required parameter '{req}'")
|
|
return False
|
|
|
|
# Check headless is optional (has default)
|
|
if 'headless' in params:
|
|
param = sig.parameters['headless']
|
|
if param.default == inspect.Parameter.empty:
|
|
print(f"⚠️ WARNING: 'headless' parameter has no default value")
|
|
else:
|
|
print(f"✅ 'headless' has default value: {param.default}")
|
|
|
|
# Test call signature
|
|
print("\n🧪 Testing call signature...")
|
|
try:
|
|
# Simulate what LoadTestBase.execute_test_for_user does
|
|
test_user_id = 1
|
|
test_student_info = {'cpid': 'TEST123', 'data': {'password': 'test'}}
|
|
test_index = 0
|
|
test_headless = True
|
|
|
|
# This is how LoadTestBase calls it:
|
|
# test_function(user_id, *args, **kwargs)
|
|
# Which becomes: complete_assessment_flow_for_student(user_id, student_info, index, headless=headless)
|
|
|
|
# Just validate the signature can accept these arguments
|
|
bound = sig.bind(test_user_id, test_student_info, test_index, headless=test_headless)
|
|
print("✅ Function signature is valid!")
|
|
print(f" Can accept: user_id={test_user_id}, student_info={test_student_info}, student_index={test_index}, headless={test_headless}")
|
|
return True
|
|
|
|
except TypeError as e:
|
|
print(f"❌ ERROR: Function signature mismatch: {e}")
|
|
return False
|
|
|
|
if __name__ == "__main__":
|
|
success = validate_signature()
|
|
sys.exit(0 if success else 1)
|
|
|