gateway/test_outlook_filters.py
2025-08-20 01:04:53 +02:00

51 lines
1.8 KiB
Python

#!/usr/bin/env python3
"""
Test script for Outlook filter logic
"""
def test_build_graph_filter():
"""Test the filter building logic"""
# Mock the _buildGraphFilter method
def _buildGraphFilter(filter_text):
if not filter_text:
return {}
filter_text = filter_text.strip()
# Handle email address filters
if '@' in filter_text and '.' in filter_text and ' ' not in filter_text:
return {"$filter": f"from/fromAddress/address eq '{filter_text}'"}
# Handle search queries (from:, to:, subject:, etc.)
if any(filter_text.startswith(prefix) for prefix in ['from:', 'to:', 'subject:', 'received:', 'hasattachment:']):
return {"$search": f'"{filter_text}"'}
# Handle text content - search in subject
return {"$filter": f"contains(subject,'{filter_text}')"}
# Test cases
test_cases = [
("peter.muster@domain.com", {"$filter": "from/fromAddress/address eq 'peter.muster@domain.com'"}),
("from:user@example.com", {"$search": '"from:user@example.com"'}),
("subject:meeting", {"$search": '"subject:meeting"'}),
("project update", {"$filter": "contains(subject,'project update')"}),
("", {}),
(" hello world ", {"$filter": "contains(subject,'hello world')"}),
]
print("Testing Outlook filter logic:")
print("=" * 50)
for test_input, expected_output in test_cases:
result = _buildGraphFilter(test_input)
status = "✓ PASS" if result == expected_output else "✗ FAIL"
print(f"{status} | Input: '{test_input}'")
print(f" | Expected: {expected_output}")
print(f" | Got: {result}")
print()
print("Test completed!")
if __name__ == "__main__":
test_build_graph_filter()