funkwhale/api/tests/users/test_admin.py

32 wiersze
1.0 KiB
Python
Czysty Zwykły widok Historia

from funkwhale_api.users.admin import MyUserCreationForm
def test_clean_username_success(db):
# Instantiate the form with a new username
2018-06-09 13:36:16 +00:00
form = MyUserCreationForm(
{"username": "alamode", "password1": "123456", "password2": "123456"}
)
# Run is_valid() to trigger the validation
valid = form.is_valid()
assert valid
# Run the actual clean_username method
username = form.clean_username()
2018-06-09 13:36:16 +00:00
assert "alamode" == username
def test_clean_username_false(factories):
2018-06-09 13:36:16 +00:00
user = factories["users.User"]()
# Instantiate the form with the same username as self.user
2018-06-09 13:36:16 +00:00
form = MyUserCreationForm(
{"username": user.username, "password1": "123456", "password2": "123456"}
)
# Run is_valid() to trigger the validation, which is going to fail
# because the username is already taken
valid = form.is_valid()
assert not valid
# The form.errors dict should contain a single error called 'username'
assert len(form.errors) == 1
2018-06-09 13:36:16 +00:00
assert "username" in form.errors