mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-04 10:59:17 +02:00
Fixed #54: Now use pytest everywhere \o/
This commit is contained in:
parent
a7758395ee
commit
099cdfa99c
65 changed files with 1466 additions and 1467 deletions
35
api/tests/users/test_admin.py
Normal file
35
api/tests/users/test_admin.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
from funkwhale_api.users.admin import MyUserCreationForm
|
||||
|
||||
|
||||
def test_clean_username_success(db):
|
||||
# Instantiate the form with a new username
|
||||
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()
|
||||
assert 'alamode' == username
|
||||
|
||||
|
||||
def test_clean_username_false(factories):
|
||||
user = factories['users.User']()
|
||||
# Instantiate the form with the same username as self.user
|
||||
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
|
||||
assert 'username' in form.errors
|
Loading…
Add table
Add a link
Reference in a new issue