File size: 1,734 Bytes
af1d8cd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
50
51
52
53
54
55
56
57
58
59
import requests
import json
import time

BASE_URL = "http://localhost:8000"

def test_monetization():
    print("Testing Monetization API...")
    
    # 1. Seed Data
    print("\n1. Seeding Data...")
    try:
        res = requests.post(f"{BASE_URL}/monetization/seed")
        print(res.json())
    except Exception as e:
        print(f"❌ Seed failed: {e}")
        return

    # 2. Get Products
    print("\n2. Fetching Products...")
    products = []
    try:
        res = requests.get(f"{BASE_URL}/monetization/products")
        products = res.json()
        print(f"βœ… Found {len(products)} products")
    except Exception as e:
        print(f"❌ Fetch products failed: {e}")
        return

    if not products:
        print("❌ No products found, skipping click test")
        return

    # 3. Simulate Click
    target_id = products[0]['id']
    print(f"\n3. Simulating Click on Product {target_id}...")
    try:
        res = requests.get(f"{BASE_URL}/monetization/redirect/{target_id}?user_id=1")
        data = res.json()
        print(f"βœ… Redirect Info: {data}")
        if data['tracked']:
            print("   (Click tracked successfully)")
    except Exception as e:
        print(f"❌ Click tracking failed: {e}")

    # 4. Check Dashboard
    print("\n4. Checking Dashboard Stats...")
    try:
        res = requests.get(f"{BASE_URL}/monetization/dashboard")
        stats = res.json()
        print(f"βœ… Total Revenue: ${stats['total_revenue']}")
        print(f"βœ… Total Clicks: {stats['total_clicks']}")
        print(json.dumps(stats['brand_performance'], indent=2))
    except Exception as e:
        print(f"❌ Dashboard stats failed: {e}")

if __name__ == "__main__":
    test_monetization()