def test_profiles(app): """Test the user profile.""" user = User(email="*****@*****.**") profile = { "full_name": "Invenio Admin", } with pytest.raises(ValueError): # the profile doesn't expect an 'email' value user.user_profile = { **profile, "email": "*****@*****.**", } assert user.user_profile == {} # a valid profile should be accepted user.user_profile = profile assert dict(user.user_profile) == profile # setting expected properties should work assert len(user.user_profile) == 1 assert user.user_profile["full_name"] == "Invenio Admin" # but setting unexpected properties should not work with pytest.raises(ValueError): user.user_profile["invalid"] = "value" # similar with wrong types for expected fields with pytest.raises(ValueError): user.user_profile["email"] = 1 assert len(user.user_profile) == 1 assert user.user_profile["full_name"] == "Invenio Admin"
def test_custom_profiles(app): """Test if the customization mechanism for user profiles works.""" app.config["ACCOUNTS_USER_PROFILE_SCHEMA"] = CustomProfile() user = User(email="*****@*****.**") # the default fields aren't allowed in the custom schema with pytest.raises(ValueError): user.user_profile = { "full_name": "Invenio Admin", } # the expected properties should work... user.user_profile = {"file_descriptor": 1} assert dict(user.user_profile) == {"file_descriptor": 1} # ... but not with unexpected types! with pytest.raises(ValueError): user.user_profile["file_descriptor"] = "1" assert dict(user.user_profile) == {"file_descriptor": 1}