File size: 8,315 Bytes
fb8df06
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import json
import urllib.request
import sys

if sys.platform == "win32" and hasattr(sys.stdout, "reconfigure"):
    sys.stdout.reconfigure(encoding="utf-8")

def test_endpoints():
    print("==================================================")
    print("  PALATE GLOBAL MULTI-CITY PILOT VERIFICATION")
    print("==================================================")

    # 1. Test /api/cities
    print("\n1. Testing /api/cities...")
    with urllib.request.urlopen("http://localhost:3050/api/cities") as resp:
        cities = json.loads(resp.read().decode())
        print(f"   Indexed Global Cities: {len(cities)}")
        for c in cities:
            print(f"   - {c['flag']} {c['name']} ({c['country']}): {c['total_eateries']} total, {c['authentic_eateries']} authentic, {c['craft_artisans_detected']} craft artisans")
            assert 'dining_guide' in c, f"Missing dining_guide in city {c['name']}"
            assert 'water_norm' in c['dining_guide'], f"Missing water_norm in {c['name']}"
        city_ids = [c["id"] for c in cities]
        assert "amsterdam" in city_ids
        assert "dubai" in city_ids
        assert "istanbul" in city_ids

    # 2. Test Amsterdam
    print("\n2. Testing Amsterdam (/api/stats?city=amsterdam & search)...")
    with urllib.request.urlopen("http://localhost:3050/api/stats?city=amsterdam") as resp:
        stats = json.loads(resp.read().decode())
        print(f"   Amsterdam Total: {stats['total_eateries_indexed']}")
        print(f"   Independent: {stats['independent_artisans']}")
        print(f"   Celiac Safe: {stats['celiac_safe_kitchens']}")
        print(f"   Scratch Kitchens: {stats['scratch_kitchens']}")
        print(f"   Tap Water: {stats['tap_water_welcoming']}")
        assert stats["total_eateries_indexed"] > 4500
        assert stats["google_api_cost"] == "$0.00"

    with urllib.request.urlopen("http://localhost:3050/api/taxonomy?city=amsterdam") as resp:
        tax_ams = json.loads(resp.read().decode())
        assert 'dining_guide' in tax_ams
        print(f"   Amsterdam Dining Guide verified: {tax_ams['dining_guide']['water_norm'][:60]}...")

    with urllib.request.urlopen("http://localhost:3050/api/search?city=amsterdam&q=shawarma&diet=halal") as resp:
        results = json.loads(resp.read().decode())
        print(f"   Found {len(results)} Halal shawarma results in Amsterdam.")
        top = results[0]
        print(f"   Top Pick: {top['name']} ({top['quality_score']} pts)")
        assert any("Halal" in d for d in top.get("dietary_badges", []))

    # 3. Test Dubai Pilot (Calibrated Data)
    print("\n3. Testing Dubai Pilot (/api/stats?city=dubai & search)...")
    with urllib.request.urlopen("http://localhost:3050/api/stats?city=dubai") as resp:
        stats_dxb = json.loads(resp.read().decode())
        print(f"   Dubai Total Eateries: {stats_dxb['total_eateries_indexed']}")
        print(f"   Craft Artisans: {stats_dxb['craft_artisans_detected']}")
        print(f"   Independent Artisans: {stats_dxb['independent_artisans']}")
        print(f"   Celiac Safe Kitchens: {stats_dxb['celiac_safe_kitchens']} (Dedicated Verified Facilities)")
        print(f"   Scratch Kitchens: {stats_dxb['scratch_kitchens']} (Stone Ovens & Roasters)")
        print(f"   Tap Water Welcoming: {stats_dxb['tap_water_welcoming']}")
        assert stats_dxb["total_eateries_indexed"] >= 800
        assert stats_dxb["independent_artisans"] >= 400
        assert stats_dxb["celiac_safe_kitchens"] == 1, "Only verified dedicated GF facilities should qualify"

    with urllib.request.urlopen("http://localhost:3050/api/taxonomy?city=dubai") as resp:
        tax_dxb = json.loads(resp.read().decode())
        assert 'dining_guide' in tax_dxb
        print(f"   Dubai Dining Guide verified: {tax_dxb['dining_guide']['water_norm'][:60]}...")
        facet_ids = [f['id'] for f in tax_dxb['row2_facets']]
        assert 'water' not in facet_ids or stats_dxb['tap_water_welcoming'] > 0

    with urllib.request.urlopen("http://localhost:3050/api/search?city=dubai&q=mandi&limit=5") as resp:
        results_mandi = json.loads(resp.read().decode())
        print(f"   Dubai Mandi Search: Found {len(results_mandi)} spots.")
        for r in results_mandi[:3]:
            print(f"   - [{r['quality_score']} pts] {r['name']} ({r.get('neighborhood', '')}): {r.get('craft_badges', [])}")
        assert len(results_mandi) > 0

    # 4. Test Istanbul Pilot (Calibrated Data)
    print("\n4. Testing Istanbul Pilot (/api/stats?city=istanbul & search)...")
    with urllib.request.urlopen("http://localhost:3050/api/stats?city=istanbul") as resp:
        stats_ist = json.loads(resp.read().decode())
        print(f"   Istanbul Total Eateries: {stats_ist['total_eateries_indexed']}")
        print(f"   Craft Artisans: {stats_ist['craft_artisans_detected']}")
        print(f"   Independent Artisans: {stats_ist['independent_artisans']}")
        print(f"   Celiac Safe Kitchens: {stats_ist['celiac_safe_kitchens']} (Verified Certified Dedicated Facility)")
        print(f"   Scratch Kitchens: {stats_ist['scratch_kitchens']} (Stone Ovens, Mangals, Esnaf)")
        print(f"   Tap Water Welcoming: {stats_ist['tap_water_welcoming']} (Honest 0 - Bottled Spring Water Norm)")
        assert stats_ist["total_eateries_indexed"] >= 900
        assert stats_ist["independent_artisans"] >= 200
        assert stats_ist["celiac_safe_kitchens"] == 1, "Glutensiz Ada verified celiac facility"
        assert stats_ist["tap_water_welcoming"] == 0, "Istanbul uses bottled spring water norm"

    with urllib.request.urlopen("http://localhost:3050/api/taxonomy?city=istanbul") as resp:
        tax_ist = json.loads(resp.read().decode())
        assert 'dining_guide' in tax_ist
        facet_ids_ist = [f['id'] for f in tax_ist['row2_facets']]
        assert 'water' not in facet_ids_ist, "Tap water with 0 count should be omitted"
        assert 'celiac' in facet_ids_ist, "Celiac with 1 count should be included"

    with urllib.request.urlopen("http://localhost:3050/api/search?city=istanbul&q=doner&limit=5") as resp:
        results_doner = json.loads(resp.read().decode())
        print(f"   Istanbul Döner Search: Found {len(results_doner)} spots.")
        for r in results_doner[:3]:
            print(f"   - [{r['quality_score']} pts] {r['name']} ({r.get('neighborhood', '')}): {r.get('craft_badges', [])}")
        assert len(results_doner) > 0

    # 5. Test 5 New Scalable Global Signals
    print("\n5. Testing 5 Scalable Global Signals...")
    with urllib.request.urlopen("http://localhost:3050/api/search?city=istanbul&q=kebab&limit=20") as resp:
        results = json.loads(resp.read().decode())
        result_ids = [r['id'] for r in results]
        assert 'ist_ghost_dark_kitchen_1' not in result_ids, "Ghost dark kitchen should be excluded from discovery"
        print("   ✓ Signal 1 (Ghost Kitchen Exclusion): Cloud dark kitchens successfully filtered from discovery")
        
        has_habitat = any("Resident Food Habitat" in b for r in results for b in r.get('craft_badges', []))
        print(f"   ✓ Signal 2 (Urban Food Habitat Matrix): Verified neighbor density detection ({has_habitat})")

        has_rhythm = any("Artisan Shift Rhythm" in b or "Daily Batch" in b for r in results for b in r.get('craft_badges', []))
        print(f"   ✓ Signal 3 (Operational Shift Rhythm): Verified shift discipline detection ({has_rhythm})")

    with urllib.request.urlopen("http://localhost:3050/api/search?city=dubai&q=burger&limit=20") as resp:
        results_dxb = json.loads(resp.read().decode())
        dxb_ids = [r['id'] for r in results_dxb]
        assert 'dxb_ghost_cloud_1' not in dxb_ids, "Dubai ghost kitchen should be excluded from discovery"
        print("   ✓ Signal 4 (Virtual Brand Filter): Dubai Kitopi dark kitchen excluded")
        
        has_digital = any((r.get('website') or '').endswith('.ae') for r in results_dxb)
        print(f"   ✓ Signal 5 (Digital Independence Score): Custom country-level domains verified ({has_digital})")

    print("\n=======================================================")
    print("ALL MULTI-CITY TESTS & 5 GLOBAL SIGNALS PASSED!")
    print("=======================================================")

if __name__ == "__main__":
    test_endpoints()