| |
| """ |
| Test Stock Consistency Algorithm |
| Simulates conversation flow to ensure stock information remains consistent |
| """ |
|
|
| |
| import sys |
| sys.path.insert(0, '/home/samikoen/bf_wab_space') |
|
|
| def test_stock_consistency(): |
| print("🧪 STOK TUTARLILİK TESTİ") |
| print("="*50) |
| |
| |
| test_phone = "+905551111111" |
| |
| |
| try: |
| from app import get_conversation_context, cache_product_info, get_cached_product_info |
| |
| |
| print("\n1️⃣ İLK ÜRÜN ARAMASI") |
| search_term = "FX 3 var mı" |
| product_info = """📦 FX 3 (2024) - Şehir Bisikleti |
| 💰 Fiyat: 73.000 TL |
| 🏪 Stok: İzmir Alsancak, İstanbul Ortaköy |
| 📏 L beden mevcut""" |
| |
| |
| cache_product_info(test_phone, search_term, product_info) |
| print(f"✅ Cached: {search_term}") |
| print(f" Info: {product_info[:100]}...") |
| |
| |
| print("\n2️⃣ İKINCİ MESAJ - BENZERİ SORGU") |
| follow_up = "boyum 190 cm L boy olur mu" |
| |
| cached_result = get_cached_product_info(test_phone, follow_up) |
| if cached_result: |
| print(f"✅ CACHED bulundu: {follow_up}") |
| print(f" Cached data: {cached_result[:100]}...") |
| else: |
| print(f"❌ Cache BULUNAMADI: {follow_up}") |
| |
| |
| print("\n3️⃣ ÜÇÜNCÜ MESAJ - AYNI ÜRÜN") |
| third_msg = "ayırtmak istiyorum" |
| |
| cached_result = get_cached_product_info(test_phone, third_msg) |
| if cached_result: |
| print(f"✅ CACHED bulundu: {third_msg}") |
| print(f" Cached data: {cached_result[:100]}...") |
| else: |
| print(f"❌ Cache BULUNAMADI: {third_msg}") |
| |
| |
| print("\n4️⃣ CONVERSATION CONTEXT") |
| context = get_conversation_context(test_phone) |
| print(f"Context keys: {list(context.keys())}") |
| print(f"Last search term: {context.get('last_search_term')}") |
| print(f"Has product info: {'Yes' if context.get('last_product_info') else 'No'}") |
| |
| |
| print("\n5️⃣ FARKLI ÜRÜN ARAMASI") |
| new_search = "Marlin 5 var mı" |
| |
| cached_result = get_cached_product_info(test_phone, new_search) |
| if cached_result: |
| print(f"⚠️ Yanlış cache bulundu (beklenmeyen): {new_search}") |
| else: |
| print(f"✅ Doğru: Farklı ürün için cache yok: {new_search}") |
| |
| |
| print("\n6️⃣ CACHE EXPIRATION TEST") |
| import datetime |
| context = get_conversation_context(test_phone) |
| |
| |
| old_time = datetime.datetime.now() - datetime.timedelta(minutes=31) |
| context["last_search_time"] = old_time |
| |
| cached_result = get_cached_product_info(test_phone, "FX 3 fiyat") |
| if cached_result: |
| print(f"❌ Cache expire olmadı (sorun)") |
| else: |
| print(f"✅ Cache doğru şekilde expire oldu") |
| |
| print("\n" + "="*50) |
| print("✅ STOK TUTARLILİK TESTİ TAMAMLANDI!") |
| |
| except ImportError as e: |
| print(f"❌ Import hatası: {e}") |
| print("Bu test app.py ile aynı dizinde çalışmalı") |
|
|
| if __name__ == "__main__": |
| test_stock_consistency() |