File size: 1,760 Bytes
b79b0dc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import requests
import json

def test_projects_list_endpoint():
    """Test the projects list endpoint"""
    base_url = "http://localhost:8001"
    
    try:
        # Test basic endpoint
        response = requests.get(f"{base_url}/api/v1/projects/")
        print(f"Status Code: {response.status_code}")
        print(f"Response Headers: {dict(response.headers)}")
        
        if response.status_code == 200:
            data = response.json()
            print(f"Response structure: {list(data.keys())}")
            print(f"Number of items: {len(data.get('items', []))}")
            print(f"Page: {data.get('page')}")
            print(f"Page size: {data.get('page_size')}")
            print(f"Total: {data.get('total')}")
            
            if data.get('items'):
                print(f"First item keys: {list(data['items'][0].keys())}")
        else:
            print(f"Error response: {response.text}")
            
        # Test with parameters
        params = {
            "customer_type": 1,
            "order_by": "project_name",
            "order_direction": "desc",
            "page": 1,
            "page_size": 5
        }
        
        response2 = requests.get(f"{base_url}/api/v1/projects/", params=params)
        print(f"\nWith parameters - Status Code: {response2.status_code}")
        
        if response2.status_code == 200:
            data2 = response2.json()
            print(f"Filtered results - Total: {data2.get('total')}, Items: {len(data2.get('items', []))}")
        
    except requests.exceptions.ConnectionError:
        print("Server is not running on port 8001")
    except Exception as e:
        print(f"Error testing endpoint: {e}")

if __name__ == "__main__":
    test_projects_list_endpoint()