aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/tests/tools.py
diff options
context:
space:
mode:
authorJessica Tallon <tsyesika@tsyesika.se>2015-08-24 18:28:41 +0200
committerJessica Tallon <tsyesika@tsyesika.se>2015-08-24 21:07:06 +0200
commitb4997540dcc7b75441e9b10ee6dcac32cc2708be (patch)
treee543baf0acc77214c44bad9f826d9187459539a9 /mediagoblin/tests/tools.py
parente9bb5879f772e4d546aadb4bb6f935c7c55b8000 (diff)
downloadmediagoblin-b4997540dcc7b75441e9b10ee6dcac32cc2708be.tar.lz
mediagoblin-b4997540dcc7b75441e9b10ee6dcac32cc2708be.tar.xz
mediagoblin-b4997540dcc7b75441e9b10ee6dcac32cc2708be.zip
Fix some unit tests and bugs
This fixes a lot of the issues with the LocalUser changes that were merged recently. There was a problem where the attributes of LocalUser were not being eagerly loaded and because the Session was detached an exception was being raised when they were accessed. This also fixes some typo's which were introduced. Finally this adds a temporary fix for a potential SQLAlchemy bug, this is a bug where doing: User.query.filter(LocalUser.username == "some_username").first() does NOT yeild a user with the username "some_username" but all users on the site. The temp fix is to just query the LocalUser, this should be resolved when bug is confirmed and fixed upstream.
Diffstat (limited to 'mediagoblin/tests/tools.py')
-rw-r--r--mediagoblin/tests/tools.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/mediagoblin/tests/tools.py b/mediagoblin/tests/tools.py
index 76b7983a..6c974c39 100644
--- a/mediagoblin/tests/tools.py
+++ b/mediagoblin/tests/tools.py
@@ -176,7 +176,7 @@ def assert_db_meets_expected(db, expected):
def fixture_add_user(username=u'chris', password=u'toast',
privileges=[], wants_comment_notification=True):
# Reuse existing user or create a new one
- test_user = User.query.filter(LocalUser.username==username).first()
+ test_user = LocalUser.query.filter(LocalUser.username==username).first()
if test_user is None:
test_user = LocalUser()
test_user.username = username
@@ -190,8 +190,11 @@ def fixture_add_user(username=u'chris', password=u'toast',
test_user.all_privileges.append(query.one())
test_user.save()
- # Reload
- test_user = User.query.filter(LocalUser.username==username).first()
+
+ # Reload - The `with_polymorphic` needs to be there to eagerly load
+ # the attributes on the LocalUser as this can't be done post detachment.
+ user_query = LocalUser.query.with_polymorphic(LocalUser)
+ test_user = user_query.filter(LocalUser.username==username).first()
# ... and detach from session:
Session.expunge(test_user)
@@ -201,7 +204,7 @@ def fixture_add_user(username=u'chris', password=u'toast',
def fixture_comment_subscription(entry, notify=True, send_email=None):
if send_email is None:
- uploader = User.query.filter_by(id=entry.uploader).first()
+ uploader = LocalUser.query.filter_by(id=entry.uploader).first()
send_email = uploader.wants_comment_notification
cs = CommentSubscription(