@@ -1171,6 +1171,11 @@ def test_prebuilt_auth_object_takes_precedence(self):
11711171from calendaring_jmap ._methods .task import parse_task_set
11721172from calendaring_jmap .client import _JMAPClientBase
11731173
1174+ #: A response entry for a method name no test here is looking for. Shared by
1175+ #: every "skips/raises without a matching response in the batch" test below
1176+ #: and in the get_availability test classes further down the file.
1177+ _UNRELATED_RESPONSE : tuple [str , dict , str ] = ("Calendar/changes" , {}, "unrelated-0" )
1178+
11741179
11751180class TestJMAPClientBaseParsers :
11761181 """Direct unit tests for the response-fallthrough branches of each
@@ -1205,7 +1210,7 @@ def test_parse_get_event_response_skips_unrelated_responses_in_batch(self):
12051210 }
12061211 matching = ("CalendarEvent/get" , {"list" : [raw_event ], "notFound" : []}, "c1" )
12071212 result = _JMAPClientBase ._parse_get_event_response (
1208- [self . _UNRELATED_RESPONSE , matching ], api_url = _API_URL , event_id = "ev1"
1213+ [_UNRELATED_RESPONSE , matching ], api_url = _API_URL , event_id = "ev1"
12091214 )
12101215 assert result .id == "ev1"
12111216
@@ -1237,12 +1242,10 @@ def test_parse_event_changes_response_without_match_returns_empty_defaults(self)
12371242 result = _JMAPClientBase ._parse_event_changes_response ([], api_url = _API_URL )
12381243 assert result == ([], [], [], "" )
12391244
1240- _UNRELATED_RESPONSE : tuple [str , dict , str ] = ("Calendar/changes" , {}, "unrelated-0" )
1241-
12421245 def test_unsupported_null_keys_returns_none_without_match (self ):
12431246 assert (
12441247 _JMAPClientBase ._unsupported_null_keys (
1245- [self . _UNRELATED_RESPONSE ], "ev1" , patch = {}, nulled = frozenset ()
1248+ [_UNRELATED_RESPONSE ], "ev1" , patch = {}, nulled = frozenset ()
12461249 )
12471250 is None
12481251 )
@@ -1255,7 +1258,7 @@ def test_unsupported_null_keys_skips_unrelated_responses_in_batch(self):
12551258 )
12561259 assert (
12571260 _JMAPClientBase ._unsupported_null_keys (
1258- [self . _UNRELATED_RESPONSE , matching ],
1261+ [_UNRELATED_RESPONSE , matching ],
12591262 "ev1" ,
12601263 patch = {"title" : "x" },
12611264 nulled = frozenset (),
@@ -1265,34 +1268,30 @@ def test_unsupported_null_keys_skips_unrelated_responses_in_batch(self):
12651268
12661269 def test_parse_get_calendars_skips_unrelated_responses_in_batch (self ):
12671270 assert (
1268- _JMAPClientBase ._parse_get_calendars (
1269- [self ._UNRELATED_RESPONSE ], client = None , is_async = False
1270- )
1271+ _JMAPClientBase ._parse_get_calendars ([_UNRELATED_RESPONSE ], client = None , is_async = False )
12711272 == []
12721273 )
12731274
12741275 def test_parse_create_response_skips_unrelated_responses_in_batch (self ):
12751276 for set_method , parse_set in self ._SET_METHODS_BY_OBJECT .items ():
12761277 with pytest .raises (JMAPMethodError , match = f"No { set_method } response" ):
12771278 _JMAPClientBase ._parse_create_response (
1278- [self . _UNRELATED_RESPONSE ], _API_URL , set_method , parse_set
1279+ [_UNRELATED_RESPONSE ], _API_URL , set_method , parse_set
12791280 )
12801281
12811282 def test_parse_update_response_skips_unrelated_responses_in_batch (self ):
12821283 for set_method , parse_set in self ._SET_METHODS_BY_OBJECT .items ():
12831284 with pytest .raises (JMAPMethodError , match = f"No { set_method } response" ):
12841285 _JMAPClientBase ._parse_update_response (
1285- [self . _UNRELATED_RESPONSE ], _API_URL , set_method , parse_set , "id1"
1286+ [_UNRELATED_RESPONSE ], _API_URL , set_method , parse_set , "id1"
12861287 )
12871288
12881289 def test_parse_search_response_skips_unrelated_responses_in_batch (self ):
1289- assert _JMAPClientBase ._parse_search_response ([self . _UNRELATED_RESPONSE ], parent = None ) == []
1290+ assert _JMAPClientBase ._parse_search_response ([_UNRELATED_RESPONSE ], parent = None ) == []
12901291
12911292 def test_parse_get_sync_token_response_skips_unrelated_responses_in_batch (self ):
12921293 with pytest .raises (JMAPMethodError , match = "No CalendarEvent/get response" ):
1293- _JMAPClientBase ._parse_get_sync_token_response (
1294- [self ._UNRELATED_RESPONSE ], api_url = _API_URL
1295- )
1294+ _JMAPClientBase ._parse_get_sync_token_response ([_UNRELATED_RESPONSE ], api_url = _API_URL )
12961295
12971296 def test_parse_event_changes_response_skips_unrelated_responses_in_batch (self ):
12981297 result = _JMAPClientBase ._parse_event_changes_response (
@@ -1304,16 +1303,16 @@ def test_parse_delete_response_skips_unrelated_responses_in_batch(self):
13041303 for set_method , parse_set in self ._SET_METHODS_BY_OBJECT .items ():
13051304 with pytest .raises (JMAPMethodError , match = f"No { set_method } response" ):
13061305 _JMAPClientBase ._parse_delete_response (
1307- [self . _UNRELATED_RESPONSE ], _API_URL , set_method , parse_set , "id1"
1306+ [_UNRELATED_RESPONSE ], _API_URL , set_method , parse_set , "id1"
13081307 )
13091308
13101309 def test_parse_get_task_lists_response_skips_unrelated_responses_in_batch (self ):
1311- assert _JMAPClientBase ._parse_get_task_lists_response ([self . _UNRELATED_RESPONSE ]) == []
1310+ assert _JMAPClientBase ._parse_get_task_lists_response ([_UNRELATED_RESPONSE ]) == []
13121311
13131312 def test_parse_get_task_response_skips_unrelated_responses_in_batch (self ):
13141313 with pytest .raises (JMAPMethodError , match = "No Task/get response" ):
13151314 _JMAPClientBase ._parse_get_task_response (
1316- [self . _UNRELATED_RESPONSE ], api_url = _API_URL , task_id = "t1"
1315+ [_UNRELATED_RESPONSE ], api_url = _API_URL , task_id = "t1"
13171316 )
13181317
13191318 def test_assemble_sync_token_result_skips_unrelated_responses_in_batch (self ):
@@ -1325,7 +1324,7 @@ def test_assemble_sync_token_result_skips_unrelated_responses_in_batch(self):
13251324 }
13261325 get_response = ("CalendarEvent/get" , {"list" : [raw_event ], "notFound" : []}, "c1" )
13271326 added , modified , deleted , token = _JMAPClientBase ._assemble_sync_token_result (
1328- [self . _UNRELATED_RESPONSE , get_response ], ["ev1" ], [], [], "new-state"
1327+ [_UNRELATED_RESPONSE , get_response ], ["ev1" ], [], [], "new-state"
13291328 )
13301329 assert len (added ) == 1
13311330 assert added [0 ].id == "ev1"
@@ -4101,6 +4100,44 @@ def test_get_availability_fallback_computes_intervals_from_events(self, monkeypa
41014100 assert result ["user1" ][0 ].start == "2026-09-21T10:00:00Z"
41024101 assert result ["user1" ][0 ].end == "2026-09-21T11:00:00Z"
41034102
4103+ def test_get_availability_falls_back_when_capability_present_but_no_principal_id (
4104+ self , monkeypatch
4105+ ):
4106+ # Base capability present, but the account's own accountCapabilities
4107+ # entry has no currentUserPrincipalId, so there is nothing to call
4108+ # Principal/getAvailability with. This must go straight to the
4109+ # fallback rather than raising or calling with a None id.
4110+ caps = {"urn:ietf:params:jmap:principals" : {}}
4111+ client = self ._client_with_capabilities (caps )
4112+ self ._mock_http (client , response = self ._make_mock (self ._query_get_response ([])))
4113+ result = client .get_availability (["user1" ], "2026-09-21T00:00:00" , "2026-09-22T00:00:00" )
4114+ assert result == {"user1" : []}
4115+
4116+ def test_get_availability_via_principal_skips_unrelated_responses_in_batch (self , monkeypatch ):
4117+ period = {
4118+ "utcStart" : "2026-09-21T10:00:00Z" ,
4119+ "utcEnd" : "2026-09-21T11:00:00Z" ,
4120+ "busyStatus" : "confirmed" ,
4121+ "event" : None ,
4122+ }
4123+ resp = {
4124+ "methodResponses" : [
4125+ _UNRELATED_RESPONSE ,
4126+ ["Principal/getAvailability" , {"list" : [period ]}, "c1" ],
4127+ ]
4128+ }
4129+ client = self ._client_with_capabilities (self ._PRINCIPALS_CAPS )
4130+ self ._mock_http (client , response = self ._make_mock (resp ))
4131+ result = client .get_availability (["user1" ], "2026-09-21T00:00:00" , "2026-09-22T00:00:00" )
4132+ assert result ["user1" ][0 ].busy_status == "confirmed"
4133+
4134+ def test_get_availability_via_principal_raises_without_matching_response (self , monkeypatch ):
4135+ resp = {"methodResponses" : [_UNRELATED_RESPONSE ]}
4136+ client = self ._client_with_capabilities (self ._PRINCIPALS_CAPS )
4137+ self ._mock_http (client , response = self ._make_mock (resp ))
4138+ with pytest .raises (JMAPMethodError , match = "No Principal/getAvailability response" ):
4139+ client .get_availability (["user1" ], "2026-09-21T00:00:00" , "2026-09-22T00:00:00" )
4140+
41044141
41054142class TestJMAPClientCalendars (_MockedClientMixin ):
41064143 def _set_response (self , ** kwargs ):
@@ -5573,6 +5610,53 @@ async def test_get_availability_fallback_computes_intervals_from_events(self, mo
55735610 assert result ["user1" ][0 ].start == "2026-09-21T10:00:00Z"
55745611 assert result ["user1" ][0 ].end == "2026-09-21T11:00:00Z"
55755612
5613+ @pytest .mark .asyncio
5614+ async def test_get_availability_falls_back_when_capability_present_but_no_principal_id (
5615+ self , monkeypatch
5616+ ):
5617+ # Same case as the sync mirror: base capability present, but no
5618+ # currentUserPrincipalId to call Principal/getAvailability with.
5619+ caps = {"urn:ietf:params:jmap:principals" : {}}
5620+ client = self ._client_with_capabilities (caps )
5621+ self ._patch_async_session (monkeypatch , self ._query_get_resp ([]))
5622+ result = await client .get_availability (
5623+ ["user1" ], "2026-09-21T00:00:00" , "2026-09-22T00:00:00"
5624+ )
5625+ assert result == {"user1" : []}
5626+
5627+ @pytest .mark .asyncio
5628+ async def test_get_availability_via_principal_skips_unrelated_responses_in_batch (
5629+ self , monkeypatch
5630+ ):
5631+ period = {
5632+ "utcStart" : "2026-09-21T10:00:00Z" ,
5633+ "utcEnd" : "2026-09-21T11:00:00Z" ,
5634+ "busyStatus" : "confirmed" ,
5635+ "event" : None ,
5636+ }
5637+ resp = {
5638+ "methodResponses" : [
5639+ _UNRELATED_RESPONSE ,
5640+ ["Principal/getAvailability" , {"list" : [period ]}, "c1" ],
5641+ ]
5642+ }
5643+ client = self ._client_with_capabilities (self ._PRINCIPALS_CAPS )
5644+ self ._patch_async_session (monkeypatch , resp )
5645+ result = await client .get_availability (
5646+ ["user1" ], "2026-09-21T00:00:00" , "2026-09-22T00:00:00"
5647+ )
5648+ assert result ["user1" ][0 ].busy_status == "confirmed"
5649+
5650+ @pytest .mark .asyncio
5651+ async def test_get_availability_via_principal_raises_without_matching_response (
5652+ self , monkeypatch
5653+ ):
5654+ resp = {"methodResponses" : [_UNRELATED_RESPONSE ]}
5655+ client = self ._client_with_capabilities (self ._PRINCIPALS_CAPS )
5656+ self ._patch_async_session (monkeypatch , resp )
5657+ with pytest .raises (JMAPMethodError , match = "No Principal/getAvailability response" ):
5658+ await client .get_availability (["user1" ], "2026-09-21T00:00:00" , "2026-09-22T00:00:00" )
5659+
55765660 @pytest .mark .asyncio
55775661 async def test_get_sync_token_sends_empty_ids (self , monkeypatch ):
55785662 resp = {
0 commit comments