|
| 1 | +from label_studio.core.feature_flags.base import flag_set |
| 2 | +from label_studio.core.feature_flags.utils import get_user_repr_from_organization |
| 3 | + |
| 4 | + |
| 5 | +def test_get_user_repr_from_organization_owner_email_and_org_id(django_user_model): |
| 6 | + # Create a minimal organization-like object |
| 7 | + class Org: |
| 8 | + def __init__(self, id, email): |
| 9 | + self.id = id |
| 10 | + |
| 11 | + class CreatedBy: |
| 12 | + def __init__(self, email): |
| 13 | + self.email = email |
| 14 | + |
| 15 | + self.created_by = CreatedBy(email) |
| 16 | + |
| 17 | + org = Org(123, 'owner@example.com') |
| 18 | + |
| 19 | + ctx = get_user_repr_from_organization(org) |
| 20 | + |
| 21 | + assert ctx['key'] == 'owner@example.com' |
| 22 | + assert ctx['custom']['organization'] == 'owner@example.com' |
| 23 | + assert ctx['custom']['organization_id'] == 123 |
| 24 | + |
| 25 | + |
| 26 | +def test_flag_set_with_organization_context_env_override(monkeypatch, settings): |
| 27 | + # Ensure offline mode/env control for deterministic behavior |
| 28 | + settings.FEATURE_FLAGS_OFFLINE = True |
| 29 | + |
| 30 | + # Use env override path for flag resolution |
| 31 | + monkeypatch.setenv('fflag_feat_test_org_targeting', 'true') |
| 32 | + |
| 33 | + class Org: |
| 34 | + def __init__(self, id, email): |
| 35 | + self.id = id |
| 36 | + |
| 37 | + class CreatedBy: |
| 38 | + def __init__(self, email): |
| 39 | + self.email = email |
| 40 | + |
| 41 | + self.created_by = CreatedBy(email) |
| 42 | + |
| 43 | + org = Org(42, 'owner@example.com') |
| 44 | + |
| 45 | + assert flag_set('fflag_feat_test_org_targeting', organization=org, override_system_default=False) is True |
| 46 | + |
| 47 | + # Unset env should fall back to override_system_default=False |
| 48 | + monkeypatch.delenv('fflag_feat_test_org_targeting', raising=False) |
| 49 | + assert flag_set('fflag_feat_test_org_targeting', organization=org, override_system_default=False) is False |
0 commit comments