e791d3c1ed
Implement changes from MCP_NORMALIZATION_FIX.md to provide consistent
response structure across all MCP tools. This fixes the bot integration
issue where different tools returned data in different structures.
Changes:
- get_valuation_comparables:
- Rename "comparables" → "deals"
- Move "total_comparables" → "market_statistics.deal_breakdown.total_deals"
- Add "search_parameters" section with "filters_applied"
- Move "statistics" → "market_statistics"
- find_recent_deals_for_address:
- Rename "price_stats.average_price" → "price_statistics.mean"
- Rename "price_stats.median_price" → "price_statistics.median"
- Rename "area_stats" → "area_statistics"
- Rename "price_per_sqm_stats" → "price_per_sqm_statistics"
- get_deal_statistics:
- Add "search_parameters" section
- Move "statistics" → "market_statistics"
- Add "market_statistics.deal_breakdown.total_deals"
- analyze_market_trends:
- Add "market_statistics.deal_breakdown.total_deals"
- Keep existing tool-specific fields (yearly_trends, etc.)
- get_market_activity_metrics:
- Add "market_statistics.deal_breakdown.total_deals"
- Keep existing tool-specific metrics
All tools now follow standard structure:
{
"search_parameters" or "analysis_parameters": {...},
"market_statistics": {
"deal_breakdown": {"total_deals": N},
"price_statistics": {"mean": ..., "median": ...},
"area_statistics": {...},
"price_per_sqm_statistics": {...}
},
"deals": [...]
}
Updated tests to match new normalized structure.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
193 lines
7.1 KiB
Python
193 lines
7.1 KiB
Python
"""
|
|
End-to-end tests for all MCP tools.
|
|
|
|
These tests make real API calls to verify the complete functionality
|
|
of each MCP tool from end to end.
|
|
|
|
Mark as integration tests since they hit real APIs.
|
|
"""
|
|
|
|
import json
|
|
|
|
import pytest
|
|
|
|
from nadlan_mcp.fastmcp_server import (
|
|
analyze_market_trends,
|
|
autocomplete_address,
|
|
compare_addresses,
|
|
find_recent_deals_for_address,
|
|
get_deal_statistics,
|
|
get_deals_by_radius,
|
|
get_market_activity_metrics,
|
|
get_neighborhood_deals,
|
|
get_street_deals,
|
|
get_valuation_comparables,
|
|
)
|
|
|
|
|
|
@pytest.mark.integration
|
|
class TestMCPToolsE2E:
|
|
"""End-to-end tests for all 10 MCP tools."""
|
|
|
|
# Test addresses
|
|
TEST_ADDRESS_1 = "סוקולוב 38 חולון"
|
|
TEST_ADDRESS_2 = "דיזנגוף 50 תל אביב"
|
|
TEST_POLYGON_ID = "52385050" # Known polygon with data
|
|
# ITM coordinates for Holon (lat, lon format for MCP tool)
|
|
TEST_LAT = 3766290.19
|
|
TEST_LON = 3870928.84
|
|
|
|
def test_autocomplete_address(self):
|
|
"""Test address autocomplete returns results."""
|
|
result = autocomplete_address("חולון סוקולוב")
|
|
data = json.loads(result)
|
|
|
|
assert isinstance(data, list)
|
|
assert len(data) > 0
|
|
|
|
# Check first result has expected structure
|
|
first = data[0]
|
|
assert "text" in first
|
|
assert "coordinates" in first or "id" in first
|
|
|
|
def test_find_recent_deals_for_address(self):
|
|
"""Test finding recent deals for an address."""
|
|
result = find_recent_deals_for_address(self.TEST_ADDRESS_1, max_deals=100)
|
|
data = json.loads(result)
|
|
|
|
# Check response structure
|
|
assert "search_parameters" in data
|
|
assert "market_statistics" in data
|
|
assert "deals" in data
|
|
|
|
# Verify some deals were found
|
|
assert isinstance(data["deals"], list)
|
|
assert len(data["deals"]) > 0
|
|
|
|
# Check deal structure
|
|
deal = data["deals"][0]
|
|
assert "deal_amount" in deal
|
|
assert "deal_date" in deal
|
|
assert "settlement_name_heb" in deal
|
|
|
|
def test_analyze_market_trends(self):
|
|
"""Test market trend analysis."""
|
|
result = analyze_market_trends(self.TEST_ADDRESS_1, years_back=3, radius_meters=100)
|
|
data = json.loads(result)
|
|
|
|
# Check response structure (normalized in MCP_NORMALIZATION_FIX)
|
|
assert "market_statistics" in data
|
|
assert "deal_breakdown" in data["market_statistics"]
|
|
assert "total_deals" in data["market_statistics"]["deal_breakdown"]
|
|
assert isinstance(data["market_statistics"]["deal_breakdown"]["total_deals"], int)
|
|
assert data["market_statistics"]["deal_breakdown"]["total_deals"] >= 0
|
|
|
|
def test_get_valuation_comparables(self):
|
|
"""Test getting valuation comparables."""
|
|
result = get_valuation_comparables(
|
|
self.TEST_ADDRESS_1, years_back=3, min_rooms=3.0, max_rooms=5.0
|
|
)
|
|
data = json.loads(result)
|
|
|
|
# Normalized structure: total_comparables -> market_statistics.deal_breakdown.total_deals
|
|
assert "market_statistics" in data
|
|
assert "deal_breakdown" in data["market_statistics"]
|
|
assert "total_deals" in data["market_statistics"]["deal_breakdown"]
|
|
assert isinstance(data["market_statistics"]["deal_breakdown"]["total_deals"], int)
|
|
assert data["market_statistics"]["deal_breakdown"]["total_deals"] >= 0
|
|
|
|
# Normalized structure: comparables -> deals
|
|
if data["market_statistics"]["deal_breakdown"]["total_deals"] > 0:
|
|
assert "deals" in data
|
|
comp = data["deals"][0]
|
|
assert "deal_amount" in comp
|
|
# rooms field is optional and excluded when None
|
|
# Just verify the comparable has basic required fields
|
|
assert "deal_date" in comp
|
|
|
|
def test_get_deal_statistics(self):
|
|
"""Test deal statistics calculation."""
|
|
result = get_deal_statistics(self.TEST_ADDRESS_1, years_back=3)
|
|
data = json.loads(result)
|
|
|
|
# Check response structure (normalized: statistics -> market_statistics)
|
|
assert "market_statistics" in data
|
|
# Check for total_deals in normalized location
|
|
if "deal_breakdown" in data["market_statistics"]:
|
|
assert "total_deals" in data["market_statistics"]["deal_breakdown"]
|
|
assert isinstance(data["market_statistics"]["deal_breakdown"]["total_deals"], int)
|
|
assert data["market_statistics"]["deal_breakdown"]["total_deals"] >= 0
|
|
|
|
def test_get_market_activity_metrics(self):
|
|
"""Test market activity metrics."""
|
|
result = get_market_activity_metrics(self.TEST_ADDRESS_1, years_back=3)
|
|
data = json.loads(result)
|
|
|
|
# Check response structure
|
|
assert "market_activity" in data
|
|
if data["market_activity"] is not None:
|
|
assert "activity_score" in data["market_activity"]
|
|
|
|
def test_compare_addresses(self):
|
|
"""Test comparing multiple addresses."""
|
|
result = compare_addresses([self.TEST_ADDRESS_1, self.TEST_ADDRESS_2])
|
|
data = json.loads(result)
|
|
|
|
assert isinstance(data, dict)
|
|
assert "addresses_compared" in data
|
|
assert "all_results" in data
|
|
|
|
def test_get_street_deals(self):
|
|
"""Test getting street-level deals."""
|
|
result = get_street_deals(self.TEST_POLYGON_ID, limit=100, deal_type=2)
|
|
data = json.loads(result)
|
|
|
|
assert "total_deals" in data
|
|
assert isinstance(data["total_deals"], int)
|
|
assert data["total_deals"] > 0 # Known polygon should have deals
|
|
|
|
assert "deals" in data
|
|
assert len(data["deals"]) > 0
|
|
|
|
# Check deal structure
|
|
deal = data["deals"][0]
|
|
assert "deal_amount" in deal
|
|
assert "deal_date" in deal
|
|
|
|
def test_get_neighborhood_deals(self):
|
|
"""Test getting neighborhood-level deals."""
|
|
result = get_neighborhood_deals(self.TEST_POLYGON_ID, limit=100, deal_type=2)
|
|
data = json.loads(result)
|
|
|
|
assert "total_deals" in data
|
|
assert isinstance(data["total_deals"], int)
|
|
assert data["total_deals"] > 0 # Known polygon should have deals
|
|
|
|
assert "deals" in data
|
|
assert len(data["deals"]) > 0
|
|
|
|
def test_get_deals_by_radius(self):
|
|
"""Test getting polygon metadata by radius."""
|
|
result = get_deals_by_radius(self.TEST_LAT, self.TEST_LON, radius_meters=500)
|
|
data = json.loads(result)
|
|
|
|
assert "total_polygons" in data
|
|
assert isinstance(data["total_polygons"], int)
|
|
assert data["total_polygons"] > 0 # Known coords should have polygons
|
|
|
|
assert "polygons" in data
|
|
assert len(data["polygons"]) > 0
|
|
|
|
# Check polygon metadata structure
|
|
polygon = data["polygons"][0]
|
|
assert "polygon_id" in polygon or "objectid" in polygon
|
|
|
|
def test_get_deals_by_radius_no_results(self):
|
|
"""Test get_deals_by_radius with coords that have no data."""
|
|
# Use coordinates unlikely to have data
|
|
result = get_deals_by_radius(37.66, 38.71, radius_meters=10)
|
|
|
|
# Should return a message string, not JSON
|
|
assert isinstance(result, str)
|
|
assert "No polygons found" in result or "total_polygons" in result
|