|
| 1 | +import pytest |
| 2 | +from pydantic import ValidationError |
| 3 | + |
1 | 4 | from scim2_models.rfc7644.search_request import SearchRequest |
2 | 5 |
|
3 | 6 |
|
4 | 7 | def test_search_request(): |
5 | 8 | SearchRequest( |
6 | 9 | attributes=["userName", "displayName"], |
| 10 | + filter='userName Eq "john"', |
| 11 | + sort_by="userName", |
| 12 | + sort_order=SearchRequest.SortOrder.ascending, |
| 13 | + start_index=1, |
| 14 | + count=10, |
| 15 | + ) |
| 16 | + |
| 17 | + SearchRequest( |
7 | 18 | excluded_attributes=["timezone", "phoneNumbers"], |
8 | 19 | filter='userName Eq "john"', |
9 | 20 | sort_by="userName", |
@@ -42,3 +53,24 @@ def test_count_floor(): |
42 | 53 |
|
43 | 54 | sr = SearchRequest(count=-1) |
44 | 55 | assert sr.count == 1 |
| 56 | + |
| 57 | + |
| 58 | +def test_attributes_or_excluded_attributes(): |
| 59 | + """Test that a validation error is raised when both 'attributes' and 'excludedAttributes' are filled at the same time. |
| 60 | + https://datatracker.ietf.org/doc/html/rfc7644#section-3.9 |
| 61 | +
|
| 62 | + Clients MAY request a partial resource representation on any |
| 63 | + operation that returns a resource within the response by specifying |
| 64 | + either of the mutually exclusive URL query parameters "attributes" or |
| 65 | + "excludedAttributes"... |
| 66 | + """ |
| 67 | + |
| 68 | + payload = { |
| 69 | + "schemas": ["urn:ietf:params:scim:api:messages:2.0:SearchRequest"], |
| 70 | + "attributes": ["userName"], |
| 71 | + "excludedAttributes": [ |
| 72 | + "displayName", |
| 73 | + ], |
| 74 | + } |
| 75 | + with pytest.raises(ValidationError): |
| 76 | + SearchRequest.model_validate(payload) |
0 commit comments