@@ -371,7 +371,7 @@ def test_patch_add_modify_result_incorrect_value(testing_context):
371371
372372
373373def test_patch_add_query_failure_after_patch (httpserver , testing_context ):
374- """Test PATCH add when query fails after successful patch ."""
374+ """Test PATCH add when attribute appears in PATCH response but not in GET ."""
375375 httpserver .expect_request (uri = "/Users" , method = "POST" ).respond_with_json (
376376 {
377377 "schemas" : ["urn:ietf:params:scim:schemas:core:2.0:User" ],
@@ -381,24 +381,40 @@ def test_patch_add_query_failure_after_patch(httpserver, testing_context):
381381 status = 201 ,
382382 )
383383
384- httpserver .expect_request (uri = "/Users/123" , method = "PATCH" ).respond_with_json (
385- {
386- "schemas" : ["urn:ietf:params:scim:schemas:core:2.0:User" ],
387- "id" : "123" ,
388- "userName" : "test@example.com" ,
389- "displayName" : "test_display" ,
390- },
391- status = 200 ,
392- )
384+ resource_state = {
385+ "schemas" : ["urn:ietf:params:scim:schemas:core:2.0:User" ],
386+ "id" : "123" ,
387+ "userName" : "test@example.com" ,
388+ }
393389
394- httpserver .expect_request (uri = "/Users/123" , method = "GET" ).respond_with_json (
395- {
396- "schemas" : ["urn:ietf:params:scim:schemas:core:2.0:User" ],
397- "id" : "123" ,
398- "userName" : "test@example.com" ,
399- # displayName missing - attribute not actually added
400- },
401- status = 200 ,
390+ def patch_handler (request ):
391+ patch_data = json .loads (request .get_data (as_text = True ))
392+ operation = patch_data ["Operations" ][0 ]
393+ path = operation ["path" ]
394+ value = operation ["value" ]
395+
396+ response_state = resource_state .copy ()
397+ if path == "displayName" :
398+ response_state ["displayName" ] = value
399+
400+ return Response (
401+ json .dumps (response_state ),
402+ status = 200 ,
403+ headers = {"Content-Type" : "application/scim+json" },
404+ )
405+
406+ def get_handler (request ):
407+ return Response (
408+ json .dumps (resource_state ),
409+ status = 200 ,
410+ headers = {"Content-Type" : "application/scim+json" },
411+ )
412+
413+ httpserver .expect_request (uri = "/Users/123" , method = "PATCH" ).respond_with_handler (
414+ patch_handler
415+ )
416+ httpserver .expect_request (uri = "/Users/123" , method = "GET" ).respond_with_handler (
417+ get_handler
402418 )
403419
404420 results = check_add_attribute (testing_context , User )
@@ -408,6 +424,9 @@ def test_patch_add_query_failure_after_patch(httpserver, testing_context):
408424 for r in results
409425 if r .status == Status .ERROR
410426 and "was not added or has unexpected value" in r .reason
427+ and hasattr (r , "data" )
428+ and r .data
429+ and r .data .get ("urn" ) == "displayName"
411430 ]
412431 assert len (error_results ) > 0
413432
@@ -416,7 +435,6 @@ def test_patch_not_supported(testing_context):
416435 """Test PATCH add returns SKIPPED when PATCH is not supported."""
417436 from unittest .mock import Mock
418437
419- # Mock ServiceProviderConfig with patch.supported = False
420438 mock_service_provider_config = Mock ()
421439 mock_service_provider_config .patch .supported = False
422440 testing_context .client .service_provider_config = mock_service_provider_config
0 commit comments