Add duplicate username check

This commit is contained in:
Tim Van Baak 2021-05-06 00:09:00 -07:00
parent 6eadb5162a
commit 8a3893f33d
2 changed files with 7 additions and 0 deletions

View File

@ -33,6 +33,10 @@ def create_user(
if not display_name.strip(): if not display_name.strip():
display_name = username display_name = username
# Query the db to make sure the username isn't taken
if db.session.query(User.username == username).count() > 0:
raise ArgumentError('Username is already taken')
new_user = User( new_user = User(
username=username, username=username,
password=password, password=password,

View File

@ -46,3 +46,6 @@ def test_create_user(db):
assert new_user assert new_user
assert new_user.id is not None assert new_user.id is not None
assert new_user.created is not None assert new_user.created is not None
with pytest.raises(ArgumentError):
duplicate = userq.create_user(db, **kwargs)