feat: Implement a CalDAV client and integrate it as tools within the FastMCP server for calendar and event management.
This commit is contained in:
65
test_client.py
Normal file
65
test_client.py
Normal file
@@ -0,0 +1,65 @@
|
||||
from src.caldav_client import CalDAVClient
|
||||
from datetime import datetime, timedelta
|
||||
import os
|
||||
|
||||
def test_client():
|
||||
print("Testing CalDAV Client...")
|
||||
try:
|
||||
client = CalDAVClient()
|
||||
print("Client initialized.")
|
||||
|
||||
print("\nListing Calendars:")
|
||||
calendars = client.list_calendars()
|
||||
for c in calendars:
|
||||
print(f"- {c['name']} ({c['url']})")
|
||||
|
||||
if not calendars:
|
||||
print("No calendars found.")
|
||||
return
|
||||
|
||||
test_calendar = calendars[0]['name']
|
||||
print(f"\nUsing calendar: {test_calendar}")
|
||||
|
||||
print("\nCreating Test Event...")
|
||||
start = datetime.now()
|
||||
end = start + timedelta(hours=1)
|
||||
uid = client.create_event(test_calendar, "MCP Test Event", start, end, "This is a test event created by MCP")
|
||||
print(f"Event created with UID: {uid}")
|
||||
|
||||
print("\nListing Events (Verification):")
|
||||
events = client.list_events(test_calendar)
|
||||
found = False
|
||||
for e in events:
|
||||
if e['uid'] == uid:
|
||||
print(f"Found event: {e['summary']} - {e['start']}")
|
||||
found = True
|
||||
break
|
||||
|
||||
if found:
|
||||
print("\nUpdating Event...")
|
||||
new_summary = "MCP Test Event (Updated)"
|
||||
client.update_event(test_calendar, uid, summary=new_summary)
|
||||
print("Event updated.")
|
||||
|
||||
print("\nListing ALL Events (Global Filter Test):")
|
||||
all_events = client.list_events() # No calendar name provided
|
||||
global_found = False
|
||||
for e in all_events:
|
||||
if e['uid'] == uid:
|
||||
print(f"Found event in global list: {e['summary']} (Calendar: {e['calendar']})")
|
||||
global_found = True
|
||||
break
|
||||
if not global_found:
|
||||
print("Error: Created event not found in global list.")
|
||||
|
||||
print("\nDeleting Event...")
|
||||
client.delete_event(test_calendar, uid)
|
||||
print("Event deleted.")
|
||||
else:
|
||||
print("Error: Created event not found in list.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"Test failed: {e}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_client()
|
||||
Reference in New Issue
Block a user