"""Test Identity schema.""" import pytest from users.validation.schemas import identity @pytest.mark.parametrize( ('payload', 'expected_errors'), [ # no errors ( { 'email': 'test@theorchard.com', 'name': 'test', 'identity_id': '123456789123456789123456', }, {}, ), ( { 'email': 'test@theorchard.com', 'name': 'test', 'identity_id': '5c067bc05f37972e07cb605f', 'auth0_user_id': '5c067bc05f37972e07cb605f', }, {}, ), ( { 'email': 'test@theorchard.com', 'name': 'test', 'identity_id': '2c5ea4c0-4067-11e9-8b2d-1b9d6bcdbbfd', 'google_user_id': '104137916463319005366', }, {}, ), ( { 'email': 'test@theorchard.com', 'name': 'test', 'identity_id': '2c5ea4c0-4067-11e9-8b2d-1b9d6bcdbbfd', 'google_user_id': '104137916463319005366', 'active': 'Y', }, {}, ), ( { 'email': 'test@theorchard.com', 'name': 'test', 'identity_id': '2c5ea4c0-4067-11e9-8b2d-1b9d6bcdbbfd', 'google_user_id': '104137916463319005366', 'active': 'Y', 'user_types': ['artist'], }, {}, ), ( { 'localization': 'de', 'number_format': 'eu', }, {}, ), ( { 'email': 'test@theorchard.com', 'name': 'test', 'identity_id': '2c5ea4c0-4067-11e9-8b2d-1b9d6bcdbbfd', 'google_user_id': '104137916463319005366', 'active': 'Y', 'user_types': ['artist'], 'default_brand': 'overdrive', }, {}, ), # invalid types ( {'email': 'test@theorchard.com', 'name': 123, 'identity_id': 456}, {'name': ['Not a valid string.'], 'identity_id': ['Not a valid string.']}, ), ( { 'localization': 'English', }, { 'localization': [ 'Must be one of: en, de, es, fr, it, ja, ko, pt, ru, tr, zh-CN, zh-TW.' ] }, ), ( { 'number_format': 'none', }, {'number_format': ['Must be one of: us, eu.']}, ), ( { 'default_brand': 'somebrand', }, { 'default_brand': [ 'Must be one of: theorchard, sme, overdrive, ' 'awal, knr, orchard, helpcenter, ab, msk, altafonte.' ] }, ), # invalid length ( {'email': 'test@theorchard.com', 'name': 'test', 'identity_id': 'abc'}, {'identity_id': ['Length must be between 22 and 36.']}, ), ( { 'email': 'test@theorchard.com', 'name': 'test', 'identity_id': '8b272478-7964-11ea-94e2-0e8f0b0973f5-more', }, {'identity_id': ['Length must be between 22 and 36.']}, ), ( {'email': 'test@theorchard.com', 'name': 'test', 'identity_id': 'abc'}, {'identity_id': ['Length must be between 22 and 36.']}, ), ( { 'email': 'test@theorchard.com', 'name': 'test', 'identity_id': '2c5ea4c0-4067-11e9-8b2d-1b9d6bcdbbfd', 'google_user_id': '104137916463319005366', 'active': 'YESS', }, {'active': ['Invalid enum member YESS']}, ), ( { 'email': 'test@theorchard.com', 'name': 'test', 'identity_id': '2c5ea4c0-4067-11e9-8b2d-1b9d6bcdbbfd', 'google_user_id': '', 'active': 'YESS', }, { 'active': ['Invalid enum member YESS'], 'google_user_id': ['Shorter than minimum length 1.'], }, ), ], ) def test_validate_identity_schema(payload, expected_errors): """Test validate Identity schema.""" identity_schema = identity.Identity() errors = identity_schema.validate(payload, partial=True) assert errors == expected_errors