فهرست منبع

Fix test drift and unconfigured user_cal resilience

- diff: handle ImportError/ValueError from user_cal gracefully (returns []
  when user_cal CalDAV is not configured, matching fetch_reservations behavior)
- test_ical_feeds: remove stale CalendarEntry(caldav=) reference and test
  (caldav field removed from CalendarEntry long ago)
- config-all.json: regenerate (key ordering and default values drifted)
- conftest: add require_user_cal fixture to skip CalDAV tests when unconfigured
- test_user_cal, test_action_chains: mark CalDAV-dependent tests with fixture
ZiB 4 ماه پیش
والد
کامیت
7d421d833b
6فایلهای تغییر یافته به همراه34 افزوده شده و 25 حذف شده
  1. 10 7
      room_cal/actions/diff.py
  2. 12 11
      room_cal/config-all.json
  3. 9 0
      tests/conftest.py
  4. 1 0
      tests/test_action_chains.py
  5. 0 7
      tests/test_ical_feeds.py
  6. 2 0
      tests/test_user_cal.py

+ 10 - 7
room_cal/actions/diff.py

@@ -311,14 +311,17 @@ async def _diff_user_cal_closed(
 
   Each row: {'date', 'in_room': bool, 'in_user_cal': bool}
   """
-  from room_cal.user_cal import UserCal
   closed_cal = Closed()
-  user_cal = UserCal()
-
-  room_events, user_cal_events = await asyncio.gather(
-    closed_cal.list(start_date, end_date),
-    user_cal.find_closed(start_date, end_date),
-  )
+  try:
+    from room_cal.user_cal import UserCal
+    user_cal = UserCal()
+    room_events, user_cal_events = await asyncio.gather(
+      closed_cal.list(start_date, end_date),
+      user_cal.find_closed(start_date, end_date),
+    )
+  except (ImportError, ValueError):
+    room_events = await closed_cal.list(start_date, end_date)
+    user_cal_events = []
 
   room_dates: set[date] = set()
   for e in room_events:

+ 12 - 11
room_cal/config-all.json

@@ -41,6 +41,12 @@
       }
     }
   },
+  "ical_feeds": [
+    {
+      "name": "Fire",
+      "url": "webcal://cal.4114.us/fire.ics"
+    }
+  ],
   "store": {
     "active": "caldav",
     "caldav": {
@@ -80,8 +86,8 @@
       "checkout_hour": 12
     },
     "prices": {
-      "weekday": 62,
-      "weekend": 72
+      "weekday": 72,
+      "weekend": 80
     },
     "reservation_window_days": 90,
     "long_window_days": 400
@@ -94,8 +100,8 @@
       "hotel_id": "",
       "rate_id": "",
       "fees": {
-        "commission": 0.03,
-        "client_fee": 0.1411235955
+        "commission": 0.155,
+        "client_fee": 0.0
       },
       "taxes": {
         "flat_tax": 4
@@ -117,11 +123,6 @@
       }
     }
   },
-  "ical_feeds": [
-    {
-      "name": "Fire",
-      "url": "webcal://cal.4114.us/fire.ics"
-    }
-  ],
-  "api_url": "http://localhost:8000/"
+  "api_url": "http://localhost:8000/",
+  "calendars": []
 }

+ 9 - 0
tests/conftest.py

@@ -0,0 +1,9 @@
+import pytest
+from room_cal._utils import get_config
+
+
+@pytest.fixture
+def require_user_cal():
+  cfg = get_config()
+  if not getattr(cfg, 'user_cal', None) or not cfg.user_cal.url:
+    pytest.skip('user_cal CalDAV not configured')

+ 1 - 0
tests/test_action_chains.py

@@ -65,6 +65,7 @@ async def _delete_price_event(cal: CalPrice, target: date) -> None:
 
 
 @pytest.mark.asyncio
+@pytest.mark.usefixtures('require_user_cal')
 async def test_fetch_user_cal_closed():
   """House closed events → Room Closed after import; removed on re-import."""
   ucal = UserCal()

+ 0 - 7
tests/test_ical_feeds.py

@@ -4,7 +4,6 @@ from room_cal.ical_feeds import fetch_calendar
 from room_cal.store._backend import EventRecord
 
 _FIRE_ENTRY = CalendarEntry(name='Fire', url='webcal://cal.4114.us/fire.ics')
-_HOUSE_ENTRY = CalendarEntry(name='House', caldav='House')
 
 
 def _assert_events(events: list[EventRecord], expected_calendar: str):
@@ -19,9 +18,3 @@ def _assert_events(events: list[EventRecord], expected_calendar: str):
 async def test_fire_http_ical():
   events = await fetch_calendar(_FIRE_ENTRY)
   _assert_events(events, 'Fire')
-
-
-@pytest.mark.asyncio
-async def test_house_caldav():
-  events = await fetch_calendar(_HOUSE_ENTRY)
-  _assert_events(events, 'House')

+ 2 - 0
tests/test_user_cal.py

@@ -4,6 +4,8 @@ from datetime import date, timedelta
 from room_cal.user_cal import UserCal
 from room_cal._utils import service_name as _service_name
 
+pytestmark = pytest.mark.usefixtures('require_user_cal')
+
 
 @pytest.mark.asyncio
 async def test_set_and_find_services_round_trip():