"""Test CreateIdentitySchema.""" from typing import Any import pytest from marshmallow import ValidationError from permissions.validations.schemas.identity import CreateIdentity VALID_DATA = { 'first_name': 'Foo', 'last_name': 'Bar', 'email': 'foo@bar.com', 'roles_to_attach': ['BANKING_TAX_BASE_ROLE'], 'tenant': {'tenant_type': 'account', 'tenant_uuid': 'dffedd4d-b88d-444d-a9eb-6ce89aa4d2f6'}, } @pytest.mark.parametrize( ('schema', 'expected_err'), [ pytest.param(VALID_DATA, None, id='valid-data'), pytest.param( {**VALID_DATA, 'roles_to_attach': ['WORKSTATION_ADMIN_ROLE']}, None, id='valid-workstation-admin-role-for-account', ), pytest.param( { **VALID_DATA, 'roles_to_attach': ['WORKSTATION_ADMIN_ROLE'], 'tenant': { 'tenant_type': 'subaccount', 'tenant_uuid': '1fab3fe8-c9a6-488a-9a96-959734a93997', }, }, None, id='valid-workstation-admin-role-for-subaccount', ), pytest.param( { **VALID_DATA, 'roles_to_attach': ['WORKSTATION_ADMIN_ROLE'], 'tenant': { 'tenant_type': 'label_participant', 'tenant_uuid': 'dffedd4d-b88d-444d-a9eb-6ce89aa4d2f6', }, }, { '_schema': [ 'Role WORKSTATION_ADMIN_ROLE is not supported' ' by the label_participant tenant type.' ] }, id='unsupported-workstation-admin-role-for-label-participant', ), pytest.param( { **VALID_DATA, 'tenant': { 'tenant_type': 'label_participant', 'tenant_uuid': 'dffedd4d-b88d-444d-a9eb-6ce89aa4d2f6', }, }, { '_schema': [ 'Role BANKING_TAX_BASE_ROLE is not supported' ' by the label_participant tenant type.' ] }, id='Unsupported role for tenant type', ), pytest.param( {**VALID_DATA, 'localization': 'en_US'}, { 'localization': [ 'Must be one of: en, de, es, fr, it, ja, ko, pt, ru, tr, zh-CN, zh-TW.' ] }, id='Unsupported localization', ), ], ) def test_validates_schema( schema: dict[str, Any], expected_err: dict[str, list[str]] | None ) -> None: """Test validates_schema for CreateIdentitySchema.""" try: CreateIdentity().load(schema) assert not expected_err except ValidationError as err: assert err.messages == expected_err