Skip to content

Commit 6bdbb6e

Browse files
author
Chris Coutinho
committed
Create sample calendar
1 parent 0b8a3aa commit 6bdbb6e

File tree

3 files changed

+35
-39
lines changed

3 files changed

+35
-39
lines changed

app-hooks/post-installation/install-calendar-app.sh

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,11 @@ php /var/www/html/occ app:enable calendar
99

1010
# Wait for calendar app to be fully initialized
1111
echo "Waiting for calendar app to initialize..."
12-
sleep 10
12+
sleep 5
1313

1414
# Ensure maintenance mode is off before calendar operations
1515
php /var/www/html/occ maintenance:mode --off
1616

17-
# Create a default calendar for the admin user (may already exist, ignore errors)
18-
echo "Creating default calendar..."
19-
php /var/www/html/occ dav:create-calendar admin personal "Personal" "Default personal calendar" || true
20-
2117
# Sync DAV system to ensure proper initialization
2218
echo "Syncing DAV system..."
2319
php /var/www/html/occ dav:sync-system-addressbook
@@ -28,6 +24,6 @@ php /var/www/html/occ maintenance:repair --include-expensive
2824

2925
# Final wait to ensure CalDAV service is fully ready
3026
echo "Final CalDAV initialization wait..."
31-
sleep 10
27+
sleep 5
3228

3329
echo "Calendar app installation complete!"

nextcloud_mcp_server/client/calendar.py

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""CalDAV client for NextCloud calendar operations."""
22

3-
import asyncio
43
import xml.etree.ElementTree as ET
54
import datetime as dt
65
from typing import Dict, Any, List, Optional, Tuple
@@ -46,23 +45,10 @@ async def list_calendars(self) -> List[Dict[str, Any]]:
4645
"Accept": "application/xml",
4746
}
4847

49-
# Retry logic for CalDAV initialization issues
50-
max_retries = 3
51-
for attempt in range(max_retries):
52-
try:
53-
response = await self._client.request(
54-
"PROPFIND", caldav_path, content=propfind_body, headers=headers
55-
)
56-
response.raise_for_status()
57-
break
58-
except HTTPStatusError as e:
59-
if e.response.status_code == 401 and attempt < max_retries - 1:
60-
logger.warning(
61-
f"CalDAV auth failed (attempt {attempt + 1}/{max_retries}), retrying in 2s..."
62-
)
63-
await asyncio.sleep(2)
64-
continue
65-
raise
48+
response = await self._client.request(
49+
"PROPFIND", caldav_path, content=propfind_body, headers=headers
50+
)
51+
response.raise_for_status()
6652

6753
# Parse XML response
6854
root = ET.fromstring(response.content)

tests/integration/test_calendar_operations.py

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,34 @@ async def temporary_calendar(nc_client: NextcloudClient, test_calendar_name: str
2626
calendar_name = test_calendar_name
2727

2828
try:
29-
# Create a test calendar if possible
30-
# Note: Calendar creation might require admin permissions
31-
# For now, we'll use an existing calendar or create events in default calendar
32-
33-
# Try to find an existing calendar to use
34-
calendars = await nc_client.calendar.list_calendars()
35-
if calendars:
36-
calendar_name = calendars[0]["name"]
37-
logger.info(f"Using existing calendar: {calendar_name}")
38-
yield calendar_name
39-
else:
40-
pytest.skip("No calendars available for testing")
29+
# Create a test calendar
30+
logger.info(f"Creating temporary calendar: {calendar_name}")
31+
result = await nc_client.calendar.create_calendar(
32+
calendar_name=calendar_name,
33+
display_name=f"Test Calendar {calendar_name}",
34+
description="Temporary calendar for integration testing",
35+
color="#FF5722",
36+
)
37+
38+
if result["status_code"] not in [200, 201]:
39+
pytest.skip(f"Failed to create temporary calendar: {result}")
40+
41+
logger.info(f"Created temporary calendar: {calendar_name}")
42+
yield calendar_name
4143

4244
except Exception as e:
4345
logger.error(f"Error setting up temporary calendar: {e}")
4446
pytest.skip(f"Calendar setup failed: {e}")
4547

48+
finally:
49+
# Cleanup: Delete the temporary calendar
50+
try:
51+
logger.info(f"Cleaning up temporary calendar: {calendar_name}")
52+
await nc_client.calendar.delete_calendar(calendar_name)
53+
logger.info(f"Successfully deleted temporary calendar: {calendar_name}")
54+
except Exception as e:
55+
logger.error(f"Error deleting temporary calendar {calendar_name}: {e}")
56+
4657

4758
@pytest.fixture
4859
async def temporary_event(nc_client: NextcloudClient, temporary_calendar: str):
@@ -236,11 +247,14 @@ async def test_list_events_in_range(nc_client: NextcloudClient, temporary_event:
236247
calendar_name = temporary_event["calendar_name"]
237248

238249
# Get events for the next week
239-
start_date = datetime.now().strftime("%Y%m%dT000000Z")
240-
end_date = (datetime.now() + timedelta(days=7)).strftime("%Y%m%dT235959Z")
250+
start_datetime = datetime.now()
251+
end_datetime = datetime.now() + timedelta(days=7)
241252

242253
events = await nc_client.calendar.get_calendar_events(
243-
calendar_name=calendar_name, start_date=start_date, end_date=end_date, limit=50
254+
calendar_name=calendar_name,
255+
start_datetime=start_datetime,
256+
end_datetime=end_datetime,
257+
limit=50,
244258
)
245259

246260
assert isinstance(events, list)

0 commit comments

Comments
 (0)