aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Spaeth <Sebastian@SSpaeth.de>2013-01-09 09:53:55 +0100
committerSebastian Spaeth <Sebastian@SSpaeth.de>2013-01-15 14:49:50 +0100
commit4fc0a289947c5e0ba68f612bc933f25b497f9fca (patch)
tree4b506e611056c535ffa7aa1a04f9d9d35793498a
parent947c08ae43914184116995b2d51f11778497a2be (diff)
downloadmediagoblin-4fc0a289947c5e0ba68f612bc933f25b497f9fca.tar.lz
mediagoblin-4fc0a289947c5e0ba68f612bc933f25b497f9fca.tar.xz
mediagoblin-4fc0a289947c5e0ba68f612bc933f25b497f9fca.zip
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>
-rw-r--r--mediagoblin/tests/tools.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/mediagoblin/tests/tools.py b/mediagoblin/tests/tools.py
index 11c0c510..3e78b2e3 100644
--- a/mediagoblin/tests/tools.py
+++ b/mediagoblin/tests/tools.py
@@ -205,7 +205,10 @@ def assert_db_meets_expected(db, expected):
def fixture_add_user(username=u'chris', password=u'toast',
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.email = username + u'@example.com'
if password is not None: