BF-WAB / test_stock_consistency.py
samikoen
Deploy from GitHub Actions
6ea7409
#!/usr/bin/env python3
"""
Test Stock Consistency Algorithm
Simulates conversation flow to ensure stock information remains consistent
"""
# Test conversation memory functions
import sys
sys.path.insert(0, '/home/samikoen/bf_wab_space')
def test_stock_consistency():
print("🧪 STOK TUTARLILİK TESTİ")
print("="*50)
# Simulate phone number
test_phone = "+905551111111"
# Import the conversation functions
try:
from app import get_conversation_context, cache_product_info, get_cached_product_info
# Test 1: İlk ürün araması
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
cache_product_info(test_phone, search_term, product_info)
print(f"✅ Cached: {search_term}")
print(f" Info: {product_info[:100]}...")
# Test 2: İkinci mesaj - benzer sorgu
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}")
# Test 3: Üçüncü mesaj - aynı ürün hakkında
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}")
# Test 4: Conversation context
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'}")
# Test 5: Farklı ürün araması
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}")
# Test 6: Cache expiration (30 dakika sonrası simülasyonu)
print("\n6️⃣ CACHE EXPIRATION TEST")
import datetime
context = get_conversation_context(test_phone)
# Zamanı geriye al (31 dakika önce)
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()