mirror of
https://github.com/Bunsly/HomeHarvest.git
synced 2026-03-04 11:34:32 -08:00
Fix exclude_pending and mls_only filters not working with raw return type
When return_type="raw" was specified, the exclude_pending and mls_only parameters were ignored because these filters only existed in process_property(), which is bypassed for raw data returns. Changes: - Added _apply_raw_data_filters() method to handle client-side filtering for raw data - Applied the filter in search() method after sorting but before returning - Fixed exclude_pending to check flags.is_pending and flags.is_contingent - Fixed mls_only to check source.id (not mls.id which doesn't exist in raw data) - Added comprehensive tests for both filters with raw data Fixes #140 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1269,4 +1269,84 @@ def test_last_status_change_date_hour_filtering():
|
||||
assert pending_date >= cutoff_time, \
|
||||
f"PENDING property pending_date {pending_date} should be within 48 hours of {cutoff_time}"
|
||||
except (ValueError, TypeError):
|
||||
pass # Skip if parsing fails
|
||||
pass # Skip if parsing fails
|
||||
|
||||
|
||||
def test_exclude_pending_with_raw_data():
|
||||
"""Test that exclude_pending parameter works correctly with return_type='raw'"""
|
||||
|
||||
# Query for sale properties with exclude_pending=True and raw data
|
||||
result = scrape_property(
|
||||
location="Phoenix, AZ",
|
||||
listing_type="for_sale",
|
||||
exclude_pending=True,
|
||||
return_type="raw",
|
||||
limit=50
|
||||
)
|
||||
|
||||
assert result is not None and len(result) > 0
|
||||
|
||||
# Verify that no pending or contingent properties are in the results
|
||||
for prop in result:
|
||||
flags = prop.get('flags', {})
|
||||
is_pending = flags.get('is_pending', False)
|
||||
is_contingent = flags.get('is_contingent', False)
|
||||
|
||||
assert not is_pending, f"Property {prop.get('property_id')} should not be pending when exclude_pending=True"
|
||||
assert not is_contingent, f"Property {prop.get('property_id')} should not be contingent when exclude_pending=True"
|
||||
|
||||
|
||||
def test_mls_only_with_raw_data():
|
||||
"""Test that mls_only parameter works correctly with return_type='raw'"""
|
||||
|
||||
# Query with mls_only=True and raw data
|
||||
result = scrape_property(
|
||||
location="Dallas, TX",
|
||||
listing_type="for_sale",
|
||||
mls_only=True,
|
||||
return_type="raw",
|
||||
limit=50
|
||||
)
|
||||
|
||||
assert result is not None and len(result) > 0
|
||||
|
||||
# Verify that all properties have MLS IDs (stored in source.id)
|
||||
for prop in result:
|
||||
source = prop.get('source', {})
|
||||
mls_id = source.get('id') if source else None
|
||||
|
||||
assert mls_id is not None and mls_id != "", \
|
||||
f"Property {prop.get('property_id')} should have an MLS ID (source.id) when mls_only=True, got: {mls_id}"
|
||||
|
||||
|
||||
def test_combined_filters_with_raw_data():
|
||||
"""Test that both exclude_pending and mls_only work together with return_type='raw'"""
|
||||
|
||||
# Query with both filters enabled and raw data
|
||||
result = scrape_property(
|
||||
location="Austin, TX",
|
||||
listing_type="for_sale",
|
||||
exclude_pending=True,
|
||||
mls_only=True,
|
||||
return_type="raw",
|
||||
limit=30
|
||||
)
|
||||
|
||||
assert result is not None and len(result) > 0
|
||||
|
||||
# Verify both filters are applied
|
||||
for prop in result:
|
||||
# Check exclude_pending filter
|
||||
flags = prop.get('flags', {})
|
||||
is_pending = flags.get('is_pending', False)
|
||||
is_contingent = flags.get('is_contingent', False)
|
||||
|
||||
assert not is_pending, f"Property {prop.get('property_id')} should not be pending"
|
||||
assert not is_contingent, f"Property {prop.get('property_id')} should not be contingent"
|
||||
|
||||
# Check mls_only filter
|
||||
source = prop.get('source', {})
|
||||
mls_id = source.get('id') if source else None
|
||||
|
||||
assert mls_id is not None and mls_id != "", \
|
||||
f"Property {prop.get('property_id')} should have an MLS ID (source.id)"
|
||||
Reference in New Issue
Block a user