@@ -497,3 +497,29 @@ def test_remove_specific_value_invalid_field():
497497 # This should raise ValueError for invalid field name
498498 with pytest .raises (ValueError , match = "no match|did not yield" ):
499499 patch .patch (user )
500+
501+
502+ def test_patch_op_operations_attribute_required_in_patch_context ():
503+ """Test that Operations attribute is required in PATCH request context per RFC 7644."""
504+ # Operations attribute must be present in PATCH request context
505+ with pytest .raises (ValidationError , match = "required value was missing" ):
506+ PatchOp [User ].model_validate (
507+ {"schemas" : ["urn:ietf:params:scim:api:messages:2.0:PatchOp" ]},
508+ context = {"scim" : Context .RESOURCE_PATCH_REQUEST },
509+ )
510+
511+ # Operations can be None when not in PATCH request context
512+ patch_op = PatchOp [User ].model_validate (
513+ {"schemas" : ["urn:ietf:params:scim:api:messages:2.0:PatchOp" ]}
514+ )
515+ assert patch_op .operations is None
516+
517+ # Operations with at least one operation is valid in PATCH request context
518+ patch_op = PatchOp [User ].model_validate (
519+ {
520+ "schemas" : ["urn:ietf:params:scim:api:messages:2.0:PatchOp" ],
521+ "operations" : [{"op" : "add" , "path" : "userName" , "value" : "test" }],
522+ },
523+ context = {"scim" : Context .RESOURCE_PATCH_REQUEST },
524+ )
525+ assert len (patch_op .operations ) == 1
0 commit comments