"""Tests for schema utils.""" from marshmallow import ValidationError import pytest from users import constants from users.validation.schemas import utils @pytest.mark.parametrize( ('accept_orchard_brand', 'value', 'expected'), [ (None, constants.AUTH0_ORCHARD_ORG_NAME, constants.AUTH0_ORCHARD_ORG_NAME), (None, constants.ORCHARD_BRAND, constants.AUTH0_ORCHARD_ORG_NAME), (True, constants.ORCHARD_BRAND, constants.AUTH0_ORCHARD_ORG_NAME), (None, constants.AWAL_BRAND.upper(), constants.AWAL_BRAND), (None, 'unexpected', ValidationError), (False, constants.ORCHARD_BRAND, ValidationError), ], ) def test_auth0_organization_field(accept_orchard_brand, value, expected): kwargs = {} if accept_orchard_brand is not None: kwargs['accept_orchard_brand'] = accept_orchard_brand field = utils.Auth0Organization(**kwargs) if isinstance(expected, str): result = field.deserialize(value) assert result == expected else: with pytest.raises(expected) as e: field.deserialize(value) assert e.type is expected