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.
This commit is contained in:
Jessica Tallon
2015-08-24 18:28:41 +02:00
parent e9bb5879f7
commit b4997540dc
25 changed files with 87 additions and 82 deletions

View File

@@ -71,13 +71,13 @@ def addmedia(args):
app = commands_util.setup_app(args)
# get the user
user = app.db.User.query.filter(
user = app.db.LocalUser.query.filter(
LocalUser.username==args.username.lower()
).first()
if user is None:
print("Sorry, no user by username '%s'" % args.username)
return
# check for the file, if it exists...
filename = os.path.split(args.filename)[-1]
abs_filename = os.path.abspath(args.filename)

View File

@@ -65,7 +65,7 @@ def batchaddmedia(args):
files_uploaded, files_attempted = 0, 0
# get the user
user = app.db.User.query.filter(
user = app.db.LocalUser.query.filter(
LocalUser.username==args.username.lower()
).first()
if user is None:

View File

@@ -47,7 +47,7 @@ def adduser(args):
db = mg_globals.database
users_with_username = \
db.User.query.filter(
db.LocalUser.query.filter(
LocalUser.username==args.username.lower()
).count()
@@ -88,7 +88,7 @@ def makeadmin(args):
db = mg_globals.database
user = db.User.query.filter(
user = db.LocalUser.query.filter(
LocalUser.username==six.text_type(args.username.lower())
).one()
if user:
@@ -117,7 +117,7 @@ def changepw(args):
db = mg_globals.database
user = db.User.query.filter(
user = db.LocalUser.query.filter(
LocalUser.username==six.text_type(args.username.lower())
).one()
if user:
@@ -141,7 +141,7 @@ def deleteuser(args):
db = mg_globals.database
user = db.User.query.filter(
user = db.LocalUser.query.filter(
LocalUser.username==args.username.lower()
).first()
if user: