|
3 | 3 | from typing import Literal |
4 | 4 | from unittest.mock import patch |
5 | 5 |
|
| 6 | +from scim2_models import Email |
6 | 7 | from scim2_models import Group |
| 8 | +from scim2_models import PhoneNumber |
7 | 9 | from scim2_models import User |
8 | 10 | from scim2_models.resources.user import X509Certificate |
9 | 11 |
|
10 | 12 | from scim2_tester.filling import fill_with_random_values |
| 13 | +from scim2_tester.filling import fix_primary_attributes |
11 | 14 | from scim2_tester.filling import generate_random_value |
12 | 15 | from scim2_tester.filling import get_model_from_ref_type |
13 | 16 | from scim2_tester.filling import get_random_example_value |
@@ -123,8 +126,6 @@ def test_generate_random_value_with_examples(testing_context): |
123 | 126 |
|
124 | 127 | def test_generate_random_value_phone_number(testing_context): |
125 | 128 | """Generates phone numbers correctly.""" |
126 | | - from scim2_models import PhoneNumber |
127 | | - |
128 | 129 | value = generate_random_value(testing_context, "phoneNumbers.value", PhoneNumber) |
129 | 130 |
|
130 | 131 | assert isinstance(value, str) |
@@ -191,8 +192,33 @@ def test_generate_random_value_reference_external(testing_context): |
191 | 192 |
|
192 | 193 | def test_generate_random_value_default_string(testing_context): |
193 | 194 | """Generates default string values.""" |
194 | | - from scim2_models import User |
195 | | - |
196 | 195 | value = generate_random_value(testing_context, "title", User) |
197 | 196 |
|
198 | 197 | assert isinstance(value, str) |
| 198 | + |
| 199 | + |
| 200 | +def test_fix_primary_attributes_single_object(): |
| 201 | + """Ensures single email gets primary=True.""" |
| 202 | + user = User(user_name="test") |
| 203 | + user. emails = [ Email( value="[email protected]", type=Email. Type. work)] |
| 204 | + |
| 205 | + fix_primary_attributes(user) |
| 206 | + |
| 207 | + assert len(user.emails) == 1 |
| 208 | + assert user.emails[0].primary is True |
| 209 | + |
| 210 | + |
| 211 | +def test_fix_primary_attributes_multiple_objects(): |
| 212 | + """Ensures exactly one email has primary=True when multiple exist.""" |
| 213 | + user = User(user_name="test") |
| 214 | + user.emails = [ |
| 215 | + Email( value="[email protected]", type=Email. Type. work), |
| 216 | + Email( value="[email protected]", type=Email. Type. home), |
| 217 | + Email( value="[email protected]", type=Email. Type. other), |
| 218 | + ] |
| 219 | + |
| 220 | + fix_primary_attributes(user) |
| 221 | + |
| 222 | + assert len(user.emails) == 3 |
| 223 | + primary_count = sum(1 for email in user.emails if email.primary) |
| 224 | + assert primary_count == 1 |
0 commit comments