@@ -148,3 +148,35 @@ def test_openapi_schema_unauthenticated_access(unauthenticated_api_client):
148148 if response .status_code == 200 :
149149 schema = response .data
150150 assert 'openapi' in schema
151+
152+
153+ def test_role_user_assignment_create_schema (admin_api_client ):
154+ """
155+ Test that RoleUserAssignmentViewSet's create operation has proper schema constraints.
156+
157+ Generated by Claude Code (claude-sonnet-4-5@20250929)
158+
159+ Verifies that the request body schema properly enforces:
160+ - Exactly one of 'user' or 'user_ansible_id' is required
161+ - At most one of 'object_id' or 'object_ansible_id' can be specified
162+ """
163+ url = '/api/v1/docs/schema/'
164+ response = admin_api_client .get (url )
165+ assert response .status_code == 200
166+
167+ # Navigate directly to the schema - will raise KeyError if path doesn't exist
168+ all_of = response .data ['paths' ]['/api/v1/role_user_assignments/' ]['post' ]['requestBody' ]['content' ]['application/json' ]['schema' ]['allOf' ]
169+
170+ # Verify structure: [base_schema, user_constraint, object_constraint]
171+ assert len (all_of ) == 3 , "Should have 3 items: base schema + 2 constraint sets"
172+ assert all_of [0 ] == {'$ref' : '#/components/schemas/RoleUserAssignment' }
173+
174+ # Verify user constraint: exactly one of 'user' or 'user_ansible_id'
175+ user_one_of = all_of [1 ]['oneOf' ]
176+ assert len (user_one_of ) == 2
177+ assert user_one_of [0 ] == {'required' : ['user' ], 'not' : {'required' : ['user_ansible_id' ]}}
178+ assert user_one_of [1 ] == {'required' : ['user_ansible_id' ], 'not' : {'required' : ['user' ]}}
179+
180+ # Verify object constraint: at most one of 'object_id' or 'object_ansible_id'
181+ object_one_of = all_of [2 ]['oneOf' ]
182+ assert len (object_one_of ) == 3
0 commit comments