Spaces:
Paused
Paused
| #!/usr/bin/env python3 | |
| """ | |
| Test script to verify priorities endpoint functionality. | |
| This script tests: | |
| 1. Get priorities endpoint | |
| 2. Verify it returns records with CustomerTypeID = 1 | |
| 3. Verify the data structure matches the expected schema | |
| Usage: | |
| python test_priorities.py | |
| """ | |
| import requests | |
| import json | |
| BASE_URL = "http://localhost:8001" # Adjust port as needed | |
| def test_priorities_endpoint(): | |
| """Test the priorities reference data endpoint""" | |
| print("π§ͺ Testing Priorities Reference Data Endpoint") | |
| print("=" * 50) | |
| # Test 1: Get priorities directly | |
| print(f"\nπ Test 1: Getting priorities from /api/v1/reference/priorities") | |
| try: | |
| response = requests.get(f"{BASE_URL}/api/v1/reference/priorities") | |
| if response.status_code == 200: | |
| priorities = response.json() | |
| print(f"β Priorities endpoint successful") | |
| print(f" Found {len(priorities)} priorities") | |
| if priorities: | |
| print(f"\nπ Sample priority record:") | |
| sample_priority = priorities[0] | |
| print(f" Priority ID: {sample_priority.get('priority_id')}") | |
| print(f" Customer Type ID: {sample_priority.get('customer_type_id')}") | |
| print(f" Description: {sample_priority.get('description')}") | |
| # Verify all have CustomerTypeID = 1 | |
| customer_type_1_count = sum(1 for p in priorities if p.get('customer_type_id') == 1) | |
| print(f"\\nπ Verification:") | |
| print(f" Records with CustomerTypeID = 1: {customer_type_1_count}/{len(priorities)}") | |
| if customer_type_1_count == len(priorities): | |
| print(f" β All priorities have CustomerTypeID = 1") | |
| else: | |
| print(f" β Some priorities have different CustomerTypeID") | |
| else: | |
| print(f" β οΈ No priorities found") | |
| else: | |
| print(f"β Failed to get priorities: {response.status_code} - {response.text}") | |
| except Exception as e: | |
| print(f"β Error accessing priorities endpoint: {e}") | |
| # Test 2: Get priorities from all reference data endpoint | |
| print(f"\\nπ Test 2: Getting priorities from /api/v1/reference/all") | |
| try: | |
| response = requests.get(f"{BASE_URL}/api/v1/reference/all") | |
| if response.status_code == 200: | |
| all_reference_data = response.json() | |
| if 'priorities' in all_reference_data: | |
| priorities = all_reference_data['priorities'] | |
| print(f"β Priorities found in all reference data") | |
| print(f" Found {len(priorities)} priorities") | |
| if priorities: | |
| # Verify structure | |
| sample_priority = priorities[0] | |
| required_fields = ['priority_id', 'customer_type_id', 'description'] | |
| missing_fields = [field for field in required_fields if field not in sample_priority] | |
| if not missing_fields: | |
| print(f" β All required fields present: {required_fields}") | |
| else: | |
| print(f" β Missing fields: {missing_fields}") | |
| else: | |
| print(f" β Priorities not found in all reference data") | |
| else: | |
| print(f"β Failed to get all reference data: {response.status_code} - {response.text}") | |
| except Exception as e: | |
| print(f"β Error accessing all reference data endpoint: {e}") | |
| print(f"\\nπ Priorities endpoint testing completed!") | |
| if __name__ == "__main__": | |
| test_priorities_endpoint() |