mirror of
https://github.com/mwisnowski/mtg_python_deckbuilder.git
synced 2025-09-22 04:50:46 +02:00
test: convert tests to pytest assertions; add server-availability skips; clean up warnings and minor syntax/indent issues
This commit is contained in:
parent
f07daaeb4a
commit
947adacfe2
21 changed files with 374 additions and 311 deletions
|
@ -1,18 +1,21 @@
|
|||
#!/usr/bin/env python3
|
||||
"""
|
||||
Test the web validation endpoint to confirm fuzzy matching works.
|
||||
Skips if the local web server is not running.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'code'))
|
||||
|
||||
import requests
|
||||
import json
|
||||
import pytest
|
||||
|
||||
def test_validation_with_empty_commander():
|
||||
"""Test validation without commander to see basic fuzzy logic."""
|
||||
print("🔍 Testing validation endpoint with empty commander...")
|
||||
# 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': 'Lighning', # Should trigger suggestions
|
||||
|
@ -25,20 +28,25 @@ def test_validation_with_empty_commander():
|
|||
|
||||
try:
|
||||
response = requests.post('http://localhost:8080/build/validate/include_exclude', data=test_data)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
|
||||
# Check expected structure keys exist
|
||||
assert isinstance(data, dict)
|
||||
assert 'includes' in data or 'confirmation_needed' in data or 'invalid' in data
|
||||
print("Response:")
|
||||
print(json.dumps(data, indent=2))
|
||||
|
||||
return data
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Test failed with error: {e}")
|
||||
return None
|
||||
assert False
|
||||
|
||||
def test_validation_with_false_fuzzy():
|
||||
"""Test with fuzzy matching disabled."""
|
||||
print("\n🎯 Testing with fuzzy matching disabled...")
|
||||
# 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': 'Lighning',
|
||||
|
@ -51,29 +59,14 @@ def test_validation_with_false_fuzzy():
|
|||
|
||||
try:
|
||||
response = requests.post('http://localhost:8080/build/validate/include_exclude', data=test_data)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
|
||||
assert isinstance(data, dict)
|
||||
print("Response:")
|
||||
print(json.dumps(data, indent=2))
|
||||
|
||||
return data
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Test failed with error: {e}")
|
||||
return None
|
||||
assert False
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("🧪 Testing Web Validation Endpoint")
|
||||
print("=" * 45)
|
||||
|
||||
data1 = test_validation_with_empty_commander()
|
||||
data2 = test_validation_with_false_fuzzy()
|
||||
|
||||
print("\n📋 Analysis:")
|
||||
if data1:
|
||||
has_confirmation = data1.get('confirmation_needed', [])
|
||||
print(f" With fuzzy enabled: {len(has_confirmation)} confirmations needed")
|
||||
|
||||
if data2:
|
||||
has_confirmation2 = data2.get('confirmation_needed', [])
|
||||
print(f" With fuzzy disabled: {len(has_confirmation2)} confirmations needed")
|
||||
print("🧪 Run this test with pytest for proper reporting")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue