test: convert tests to pytest assertions; add server-availability skips; clean up warnings and minor syntax/indent issues

This commit is contained in:
matt 2025-09-12 10:50:57 -07:00
parent f07daaeb4a
commit 947adacfe2
21 changed files with 374 additions and 311 deletions

View file

@ -8,11 +8,17 @@ import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'code'))
import requests
import pytest
import json
def test_fuzzy_match_confirmation():
"""Test that fuzzy matching returns confirmation_needed items for low confidence matches."""
print("🔍 Testing fuzzy match confirmation modal backend...")
# Skip if local server isn't running
try:
requests.get('http://localhost:8080/', timeout=0.5)
except Exception:
pytest.skip('Local web server is not running on http://localhost:8080; skipping HTTP-based test')
# Test with a typo that should trigger confirmation
test_data = {
@ -29,19 +35,19 @@ def test_fuzzy_match_confirmation():
if response.status_code != 200:
print(f"❌ Request failed with status {response.status_code}")
return False
assert False
data = response.json()
# Check if confirmation_needed is populated
if 'confirmation_needed' not in data:
print("❌ No confirmation_needed field in response")
return False
assert False
if not data['confirmation_needed']:
print("❌ confirmation_needed is empty")
print(f"Response: {json.dumps(data, indent=2)}")
return False
assert False
confirmation = data['confirmation_needed'][0]
expected_fields = ['input', 'suggestions', 'confidence', 'type']
@ -49,23 +55,25 @@ def test_fuzzy_match_confirmation():
for field in expected_fields:
if field not in confirmation:
print(f"❌ Missing field '{field}' in confirmation")
return False
print(f"✅ Fuzzy match confirmation working!")
assert False
print("✅ Fuzzy match confirmation working!")
print(f" Input: {confirmation['input']}")
print(f" Suggestions: {confirmation['suggestions']}")
print(f" Confidence: {confirmation['confidence']:.2%}")
print(f" Type: {confirmation['type']}")
return True
except Exception as e:
print(f"❌ Test failed with error: {e}")
return False
assert False
def test_exact_match_no_confirmation():
"""Test that exact matches don't trigger confirmation."""
print("\n🎯 Testing exact match (no confirmation)...")
# Skip if local server isn't running
try:
requests.get('http://localhost:8080/', timeout=0.5)
except Exception:
pytest.skip('Local web server is not running on http://localhost:8080; skipping HTTP-based test')
test_data = {
'include_cards': 'Lightning Bolt', # Exact match
@ -81,27 +89,25 @@ def test_exact_match_no_confirmation():
if response.status_code != 200:
print(f"❌ Request failed with status {response.status_code}")
return False
assert False
data = response.json()
# Should not have confirmation_needed for exact match
if data.get('confirmation_needed'):
print(f"❌ Exact match should not trigger confirmation: {data['confirmation_needed']}")
return False
assert False
# Should have legal includes
if not data.get('includes', {}).get('legal'):
print("❌ Exact match should be in legal includes")
print(f"Response: {json.dumps(data, indent=2)}")
return False
assert False
print("✅ Exact match correctly bypasses confirmation!")
return True
except Exception as e:
print(f"❌ Test failed with error: {e}")
return False
assert False
if __name__ == "__main__":
print("🧪 Testing Fuzzy Match Confirmation Modal")