More explicit get_or_create pattern
Don't do "user = getUser() or newUser()" in one line. It is bound to confuse poor souls. Be more explicit here and even add a code comment. Thanks to Elrond for not liking the previous pattern. Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
This commit is contained in:
parent
947c08ae43
commit
4fc0a28994
@ -205,7 +205,10 @@ def assert_db_meets_expected(db, expected):
|
|||||||
|
|
||||||
def fixture_add_user(username=u'chris', password=u'toast',
|
def fixture_add_user(username=u'chris', password=u'toast',
|
||||||
active_user=True):
|
active_user=True):
|
||||||
test_user = User.query.filter_by(username=username).first() or User()
|
# Reuse existing user or create a new one
|
||||||
|
test_user = User.query.filter_by(username=username).first()
|
||||||
|
if test_user is None:
|
||||||
|
test_user = User()
|
||||||
test_user.username = username
|
test_user.username = username
|
||||||
test_user.email = username + u'@example.com'
|
test_user.email = username + u'@example.com'
|
||||||
if password is not None:
|
if password is not None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user