aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/tests/tools.py
diff options
context:
space:
mode:
authorSebastian Spaeth <Sebastian@SSpaeth.de>2013-01-08 10:22:13 +0100
committerSebastian Spaeth <Sebastian@SSpaeth.de>2013-01-08 11:54:44 +0100
commita5cf95c5ad5f898dede89075cbd61c52fb285e8e (patch)
treeb076cb29b95b5e7331e613e7cfef53edd6c784cd /mediagoblin/tests/tools.py
parent7f4e42b0b15aefcc885c9aacefac3a76f2f7b5ad (diff)
downloadmediagoblin-a5cf95c5ad5f898dede89075cbd61c52fb285e8e.tar.lz
mediagoblin-a5cf95c5ad5f898dede89075cbd61c52fb285e8e.tar.xz
mediagoblin-a5cf95c5ad5f898dede89075cbd61c52fb285e8e.zip
Do not fail is a user exists already
When the tests want to create a new user, don't fail if it already exists and just reuse the existing one. This allows us to run tests without dumping the whole database if that is not needed for the tests. The upcoming tests for test_edit will make use of this. Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
Diffstat (limited to 'mediagoblin/tests/tools.py')
-rw-r--r--mediagoblin/tests/tools.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/mediagoblin/tests/tools.py b/mediagoblin/tests/tools.py
index 31afb08b..11c0c510 100644
--- a/mediagoblin/tests/tools.py
+++ b/mediagoblin/tests/tools.py
@@ -25,6 +25,7 @@ from paste.deploy import loadapp
from webtest import TestApp
from mediagoblin import mg_globals
+from mediagoblin.db.models import User
from mediagoblin.tools import testing
from mediagoblin.init.config import read_mediagoblin_config
from mediagoblin.db.open import setup_connection_and_db_from_config
@@ -202,9 +203,9 @@ def assert_db_meets_expected(db, expected):
assert document == expected_document # make sure it matches
-def fixture_add_user(username=u'chris', password='toast',
+def fixture_add_user(username=u'chris', password=u'toast',
active_user=True):
- test_user = mg_globals.database.User()
+ test_user = User.query.filter_by(username=username).first() or User()
test_user.username = username
test_user.email = username + u'@example.com'
if password is not None:
@@ -216,7 +217,7 @@ def fixture_add_user(username=u'chris', password='toast',
test_user.save()
# Reload
- test_user = mg_globals.database.User.find_one({'username': username})
+ test_user = User.query.filter_by(username=username).first()
# ... and detach from session:
Session.expunge(test_user)