def on_user_updated(sender, instance, **kwargs): """ Check for retired usernames. """ # Check only at User creation time and when not raw. if not instance.id and not kwargs['raw']: prefix_to_check = getattr(settings, 'RETIRED_USERNAME_PREFIX', None) if prefix_to_check: # Check for username that's too close to retired username format. if instance.username.startswith(prefix_to_check): raise AccountValidationError( USERNAME_EXISTS_MSG_FMT.format(username=instance.username), field="username") # Check for a retired username. if is_username_retired(instance.username): raise AccountValidationError( USERNAME_EXISTS_MSG_FMT.format(username=instance.username), field="username") # Check for a retired email. if is_email_retired(instance.email): raise AccountValidationError( EMAIL_EXISTS_MSG_FMT.format(email=instance.email), field="email")
def test_is_username_retired_is_retired(retirement_user): """ Check functionality of is_username_retired when username is retired """ original_username = retirement_user.username retired_username = get_retired_username_by_username( retirement_user.username) # Fake username retirement. retirement_user.username = retired_username retirement_user.save() assert is_username_retired(original_username)
def test_is_username_retired_is_retired(retirement_user): # lint-amnesty, pylint: disable=redefined-outer-name """ Check functionality of is_username_retired when username is retired """ original_username = retirement_user.username retired_username = get_retired_username_by_username( retirement_user.username) # Fake username retirement. retirement_user.username = retired_username retirement_user.save() assert is_username_retired(original_username)
def test_is_username_retired_not_retired(retirement_user): """ Check functionality of is_username_retired when username is not retired """ assert not is_username_retired(retirement_user.username)
def test_is_username_retired_not_retired(retirement_user): # lint-amnesty, pylint: disable=redefined-outer-name """ Check functionality of is_username_retired when username is not retired """ assert not is_username_retired(retirement_user.username)