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:
parent
e9bb5879f7
commit
b4997540dc
@ -45,7 +45,7 @@ def get_profile(request):
|
|||||||
can be found then this function returns a (None, None).
|
can be found then this function returns a (None, None).
|
||||||
"""
|
"""
|
||||||
username = request.matchdict["username"]
|
username = request.matchdict["username"]
|
||||||
user = User.query.filter(LocalUser.username==username).first()
|
user = LocalUser.query.filter(LocalUser.username==username).first()
|
||||||
|
|
||||||
if user is None:
|
if user is None:
|
||||||
return None, None
|
return None, None
|
||||||
@ -94,7 +94,7 @@ def user_endpoint(request):
|
|||||||
def uploads_endpoint(request):
|
def uploads_endpoint(request):
|
||||||
""" Endpoint for file uploads """
|
""" Endpoint for file uploads """
|
||||||
username = request.matchdict["username"]
|
username = request.matchdict["username"]
|
||||||
requested_user = User.query.filter(LocalUser.username==username).first()
|
requested_user = LocalUser.query.filter(LocalUser.username==username).first()
|
||||||
|
|
||||||
if requested_user is None:
|
if requested_user is None:
|
||||||
return json_error("No such 'user' with id '{0}'".format(username), 404)
|
return json_error("No such 'user' with id '{0}'".format(username), 404)
|
||||||
@ -142,7 +142,7 @@ def inbox_endpoint(request, inbox=None):
|
|||||||
inbox: allows you to pass a query in to limit inbox scope
|
inbox: allows you to pass a query in to limit inbox scope
|
||||||
"""
|
"""
|
||||||
username = request.matchdict["username"]
|
username = request.matchdict["username"]
|
||||||
user = User.query.filter(LocalUser.username==username).first()
|
user = LocalUser.query.filter(LocalUser.username==username).first()
|
||||||
|
|
||||||
if user is None:
|
if user is None:
|
||||||
return json_error("No such 'user' with id '{0}'".format(username), 404)
|
return json_error("No such 'user' with id '{0}'".format(username), 404)
|
||||||
@ -225,7 +225,7 @@ def inbox_major_endpoint(request):
|
|||||||
def feed_endpoint(request, outbox=None):
|
def feed_endpoint(request, outbox=None):
|
||||||
""" Handles the user's outbox - /api/user/<username>/feed """
|
""" Handles the user's outbox - /api/user/<username>/feed """
|
||||||
username = request.matchdict["username"]
|
username = request.matchdict["username"]
|
||||||
requested_user = User.query.filter(LocalUser.username==username).first()
|
requested_user = LocalUser.query.filter(LocalUser.username==username).first()
|
||||||
|
|
||||||
# check if the user exists
|
# check if the user exists
|
||||||
if requested_user is None:
|
if requested_user is None:
|
||||||
@ -747,7 +747,7 @@ def lrdd_lookup(request):
|
|||||||
username, host = resource.split("@", 1)
|
username, host = resource.split("@", 1)
|
||||||
|
|
||||||
# Now lookup the user
|
# Now lookup the user
|
||||||
user = User.query.filter(LocalUser.username==username).first()
|
user = LocalUser.query.filter(LocalUser.username==username).first()
|
||||||
|
|
||||||
if user is None:
|
if user is None:
|
||||||
return json_error(
|
return json_error(
|
||||||
|
@ -38,7 +38,8 @@ from mediagoblin.db.extratypes import JSONEncoded, MutationDict
|
|||||||
from mediagoblin.db.migration_tools import (
|
from mediagoblin.db.migration_tools import (
|
||||||
RegisterMigration, inspect_table, replace_table_hack)
|
RegisterMigration, inspect_table, replace_table_hack)
|
||||||
from mediagoblin.db.models import (MediaEntry, Collection, MediaComment, User,
|
from mediagoblin.db.models import (MediaEntry, Collection, MediaComment, User,
|
||||||
Privilege, Generator, LocalUser, Location)
|
Privilege, Generator, LocalUser, Location,
|
||||||
|
Client, RequestToken, AccessToken)
|
||||||
from mediagoblin.db.extratypes import JSONEncoded, MutationDict
|
from mediagoblin.db.extratypes import JSONEncoded, MutationDict
|
||||||
|
|
||||||
|
|
||||||
|
@ -451,8 +451,8 @@ class ActivityMixin(object):
|
|||||||
"audio": _("audio"),
|
"audio": _("audio"),
|
||||||
"person": _("a person"),
|
"person": _("a person"),
|
||||||
}
|
}
|
||||||
obj = self.object
|
obj = self.object()
|
||||||
target = None if self.target is None else self.target
|
target = None if self.target_id is None else self.target()
|
||||||
actor = self.get_actor
|
actor = self.get_actor
|
||||||
content = verb_to_content.get(self.verb, None)
|
content = verb_to_content.get(self.verb, None)
|
||||||
|
|
||||||
@ -470,7 +470,7 @@ class ActivityMixin(object):
|
|||||||
# Do we want to add a target (indirect object) to content?
|
# Do we want to add a target (indirect object) to content?
|
||||||
if target is not None and "targetted" in content:
|
if target is not None and "targetted" in content:
|
||||||
if hasattr(target, "title") and target.title.strip(" "):
|
if hasattr(target, "title") and target.title.strip(" "):
|
||||||
target_value = terget.title
|
target_value = target.title
|
||||||
elif target.object_type in object_map:
|
elif target.object_type in object_map:
|
||||||
target_value = object_map[target.object_type]
|
target_value = object_map[target.object_type]
|
||||||
else:
|
else:
|
||||||
|
@ -250,9 +250,29 @@ class User(Base, UserMixin):
|
|||||||
|
|
||||||
__mapper_args__ = {
|
__mapper_args__ = {
|
||||||
'polymorphic_identity': 'user',
|
'polymorphic_identity': 'user',
|
||||||
'polymorphic_on': type
|
'polymorphic_on': type,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def delete(self, **kwargs):
|
||||||
|
"""Deletes a User and all related entries/comments/files/..."""
|
||||||
|
# Collections get deleted by relationships.
|
||||||
|
|
||||||
|
media_entries = MediaEntry.query.filter(MediaEntry.uploader == self.id)
|
||||||
|
for media in media_entries:
|
||||||
|
# TODO: Make sure that "MediaEntry.delete()" also deletes
|
||||||
|
# all related files/Comments
|
||||||
|
media.delete(del_orphan_tags=False, commit=False)
|
||||||
|
|
||||||
|
# Delete now unused tags
|
||||||
|
# TODO: import here due to cyclic imports!!! This cries for refactoring
|
||||||
|
from mediagoblin.db.util import clean_orphan_tags
|
||||||
|
clean_orphan_tags(commit=False)
|
||||||
|
|
||||||
|
# Delete user, pass through commit=False/True in kwargs
|
||||||
|
username = self.username
|
||||||
|
super(User, self).delete(**kwargs)
|
||||||
|
_log.info('Deleted user "{0}" account'.format(username))
|
||||||
|
|
||||||
def has_privilege(self, privilege, allow_admin=True):
|
def has_privilege(self, privilege, allow_admin=True):
|
||||||
"""
|
"""
|
||||||
This method checks to make sure a user has all the correct privileges
|
This method checks to make sure a user has all the correct privileges
|
||||||
@ -335,7 +355,7 @@ class LocalUser(User):
|
|||||||
upload_limit = Column(Integer)
|
upload_limit = Column(Integer)
|
||||||
|
|
||||||
__mapper_args__ = {
|
__mapper_args__ = {
|
||||||
'polymorphic_identity': 'user_local'
|
"polymorphic_identity": "user_local",
|
||||||
}
|
}
|
||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
@ -349,25 +369,6 @@ class LocalUser(User):
|
|||||||
'admin' if self.has_privilege(u'admin') else 'user',
|
'admin' if self.has_privilege(u'admin') else 'user',
|
||||||
self.username)
|
self.username)
|
||||||
|
|
||||||
def delete(self, **kwargs):
|
|
||||||
"""Deletes a User and all related entries/comments/files/..."""
|
|
||||||
# Collections get deleted by relationships.
|
|
||||||
|
|
||||||
media_entries = MediaEntry.query.filter(MediaEntry.uploader == self.id)
|
|
||||||
for media in media_entries:
|
|
||||||
# TODO: Make sure that "MediaEntry.delete()" also deletes
|
|
||||||
# all related files/Comments
|
|
||||||
media.delete(del_orphan_tags=False, commit=False)
|
|
||||||
|
|
||||||
# Delete now unused tags
|
|
||||||
# TODO: import here due to cyclic imports!!! This cries for refactoring
|
|
||||||
from mediagoblin.db.util import clean_orphan_tags
|
|
||||||
clean_orphan_tags(commit=False)
|
|
||||||
|
|
||||||
# Delete user, pass through commit=False/True in kwargs
|
|
||||||
super(User, self).delete(**kwargs)
|
|
||||||
_log.info('Deleted user "{0}" account'.format(self.username))
|
|
||||||
|
|
||||||
def serialize(self, request):
|
def serialize(self, request):
|
||||||
user = {
|
user = {
|
||||||
"id": "acct:{0}@{1}".format(self.username, request.host),
|
"id": "acct:{0}@{1}".format(self.username, request.host),
|
||||||
|
@ -71,13 +71,13 @@ def addmedia(args):
|
|||||||
app = commands_util.setup_app(args)
|
app = commands_util.setup_app(args)
|
||||||
|
|
||||||
# get the user
|
# get the user
|
||||||
user = app.db.User.query.filter(
|
user = app.db.LocalUser.query.filter(
|
||||||
LocalUser.username==args.username.lower()
|
LocalUser.username==args.username.lower()
|
||||||
).first()
|
).first()
|
||||||
if user is None:
|
if user is None:
|
||||||
print("Sorry, no user by username '%s'" % args.username)
|
print("Sorry, no user by username '%s'" % args.username)
|
||||||
return
|
return
|
||||||
|
|
||||||
# check for the file, if it exists...
|
# check for the file, if it exists...
|
||||||
filename = os.path.split(args.filename)[-1]
|
filename = os.path.split(args.filename)[-1]
|
||||||
abs_filename = os.path.abspath(args.filename)
|
abs_filename = os.path.abspath(args.filename)
|
||||||
|
@ -65,7 +65,7 @@ def batchaddmedia(args):
|
|||||||
files_uploaded, files_attempted = 0, 0
|
files_uploaded, files_attempted = 0, 0
|
||||||
|
|
||||||
# get the user
|
# get the user
|
||||||
user = app.db.User.query.filter(
|
user = app.db.LocalUser.query.filter(
|
||||||
LocalUser.username==args.username.lower()
|
LocalUser.username==args.username.lower()
|
||||||
).first()
|
).first()
|
||||||
if user is None:
|
if user is None:
|
||||||
|
@ -47,7 +47,7 @@ def adduser(args):
|
|||||||
|
|
||||||
db = mg_globals.database
|
db = mg_globals.database
|
||||||
users_with_username = \
|
users_with_username = \
|
||||||
db.User.query.filter(
|
db.LocalUser.query.filter(
|
||||||
LocalUser.username==args.username.lower()
|
LocalUser.username==args.username.lower()
|
||||||
).count()
|
).count()
|
||||||
|
|
||||||
@ -88,7 +88,7 @@ def makeadmin(args):
|
|||||||
|
|
||||||
db = mg_globals.database
|
db = mg_globals.database
|
||||||
|
|
||||||
user = db.User.query.filter(
|
user = db.LocalUser.query.filter(
|
||||||
LocalUser.username==six.text_type(args.username.lower())
|
LocalUser.username==six.text_type(args.username.lower())
|
||||||
).one()
|
).one()
|
||||||
if user:
|
if user:
|
||||||
@ -117,7 +117,7 @@ def changepw(args):
|
|||||||
|
|
||||||
db = mg_globals.database
|
db = mg_globals.database
|
||||||
|
|
||||||
user = db.User.query.filter(
|
user = db.LocalUser.query.filter(
|
||||||
LocalUser.username==six.text_type(args.username.lower())
|
LocalUser.username==six.text_type(args.username.lower())
|
||||||
).one()
|
).one()
|
||||||
if user:
|
if user:
|
||||||
@ -141,7 +141,7 @@ def deleteuser(args):
|
|||||||
|
|
||||||
db = mg_globals.database
|
db = mg_globals.database
|
||||||
|
|
||||||
user = db.User.query.filter(
|
user = db.LocalUser.query.filter(
|
||||||
LocalUser.username==args.username.lower()
|
LocalUser.username==args.username.lower()
|
||||||
).first()
|
).first()
|
||||||
if user:
|
if user:
|
||||||
|
@ -298,15 +298,15 @@ def draft_view(request):
|
|||||||
{'blogpost':blogpost,
|
{'blogpost':blogpost,
|
||||||
'blog': blog
|
'blog': blog
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@require_active_login
|
@require_active_login
|
||||||
def blog_delete(request, **kwargs):
|
def blog_delete(request, **kwargs):
|
||||||
"""
|
"""
|
||||||
Deletes a blog and media entries, tags associated with it.
|
Deletes a blog and media entries, tags associated with it.
|
||||||
"""
|
"""
|
||||||
url_user = request.matchdict.get('user')
|
url_user = request.matchdict.get('user')
|
||||||
owner_user = request.db.User.query.filter(
|
owner_user = request.db.LocalUser.query.filter(
|
||||||
LocalUser.username==url_user
|
LocalUser.username==url_user
|
||||||
).first()
|
).first()
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ def take_away_privileges(user,*privileges):
|
|||||||
if len(privileges) == 1:
|
if len(privileges) == 1:
|
||||||
privilege = Privilege.query.filter(
|
privilege = Privilege.query.filter(
|
||||||
Privilege.privilege_name==privileges[0]).first()
|
Privilege.privilege_name==privileges[0]).first()
|
||||||
user = User.query.filter(
|
user = LocalUser.query.filter(
|
||||||
LocalUser.username==user
|
LocalUser.username==user
|
||||||
).first()
|
).first()
|
||||||
if privilege in user.all_privileges:
|
if privilege in user.all_privileges:
|
||||||
@ -155,8 +155,8 @@ def give_privileges(user,*privileges):
|
|||||||
if len(privileges) == 1:
|
if len(privileges) == 1:
|
||||||
privilege = Privilege.query.filter(
|
privilege = Privilege.query.filter(
|
||||||
Privilege.privilege_name==privileges[0]).first()
|
Privilege.privilege_name==privileges[0]).first()
|
||||||
user = User.query.filter(
|
user = LocalUser.query.filter(
|
||||||
LoclUser.username==user
|
LocalUser.username==user
|
||||||
).first()
|
).first()
|
||||||
if privilege not in user.all_privileges:
|
if privilege not in user.all_privileges:
|
||||||
user.all_privileges.append(privilege)
|
user.all_privileges.append(privilege)
|
||||||
|
@ -79,7 +79,7 @@ def moderation_users_detail(request):
|
|||||||
'''
|
'''
|
||||||
Shows details about a particular user.
|
Shows details about a particular user.
|
||||||
'''
|
'''
|
||||||
user = User.query.filter(
|
user = LocalUser.query.filter(
|
||||||
LocalUser.username==request.matchdict['user']
|
LocalUser.username==request.matchdict['user']
|
||||||
).first()
|
).first()
|
||||||
active_reports = user.reports_filed_on.filter(
|
active_reports = user.reports_filed_on.filter(
|
||||||
|
@ -34,7 +34,7 @@ def get_media_entry_from_uploader_slug(uploader_username, slug):
|
|||||||
:returns media A MediaEntry object or None if no entry
|
:returns media A MediaEntry object or None if no entry
|
||||||
matches the specifications.
|
matches the specifications.
|
||||||
"""
|
"""
|
||||||
uploader = User.query.filter(
|
uploader = LocalUser.query.filter(
|
||||||
LocalUser.username==uploader_username
|
LocalUser.username==uploader_username
|
||||||
).first()
|
).first()
|
||||||
media = MediaEntry.query.filter(
|
media = MediaEntry.query.filter(
|
||||||
|
@ -38,7 +38,7 @@ def login(request):
|
|||||||
login_form.password.data)
|
login_form.password.data)
|
||||||
|
|
||||||
if username:
|
if username:
|
||||||
user = User.query.filter(
|
user = LocalUser.query.filter(
|
||||||
LocalUser.username==username
|
LocalUser.username==username
|
||||||
).first()
|
).first()
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ class MGClientTestCase:
|
|||||||
fixture_add_user(username, **options)
|
fixture_add_user(username, **options)
|
||||||
|
|
||||||
def user(self, username):
|
def user(self, username):
|
||||||
return User.query.filter(LocalUser.username==username).first()
|
return LocalUser.query.filter(LocalUser.username==username).first()
|
||||||
|
|
||||||
def _do_request(self, url, *context_keys, **kwargs):
|
def _do_request(self, url, *context_keys, **kwargs):
|
||||||
template.clear_test_template_context()
|
template.clear_test_template_context()
|
||||||
|
@ -98,8 +98,8 @@ def test_register_views(test_app):
|
|||||||
assert 'mediagoblin/user_pages/user_nonactive.html' in template.TEMPLATE_TEST_CONTEXT
|
assert 'mediagoblin/user_pages/user_nonactive.html' in template.TEMPLATE_TEST_CONTEXT
|
||||||
|
|
||||||
## Make sure user is in place
|
## Make sure user is in place
|
||||||
new_user = mg_globals.database.User.query.filter(
|
new_user = mg_globals.database.LocalUser.query.filter(
|
||||||
LocalUser.usrname==u'angrygirl'
|
LocalUser.username==u'angrygirl'
|
||||||
).first()
|
).first()
|
||||||
assert new_user
|
assert new_user
|
||||||
|
|
||||||
@ -138,7 +138,7 @@ def test_register_views(test_app):
|
|||||||
|
|
||||||
# assert context['verification_successful'] == True
|
# assert context['verification_successful'] == True
|
||||||
# TODO: Would be good to test messages here when we can do so...
|
# TODO: Would be good to test messages here when we can do so...
|
||||||
new_user = mg_globals.database.User.query.filter(
|
new_user = mg_globals.database.LocalUser.query.filter(
|
||||||
LocalUser.username==u'angrygirl'
|
LocalUser.username==u'angrygirl'
|
||||||
).first()
|
).first()
|
||||||
assert new_user
|
assert new_user
|
||||||
@ -151,7 +151,7 @@ def test_register_views(test_app):
|
|||||||
'mediagoblin/user_pages/user.html']
|
'mediagoblin/user_pages/user.html']
|
||||||
# assert context['verification_successful'] == True
|
# assert context['verification_successful'] == True
|
||||||
# TODO: Would be good to test messages here when we can do so...
|
# TODO: Would be good to test messages here when we can do so...
|
||||||
new_user = mg_globals.database.User.query.filter(
|
new_user = mg_globals.database.LocalUser.query.filter(
|
||||||
LocalUser.username==u'angrygirl'
|
LocalUser.username==u'angrygirl'
|
||||||
).first()
|
).first()
|
||||||
assert new_user
|
assert new_user
|
||||||
|
@ -88,7 +88,7 @@ def test_change_password(test_app):
|
|||||||
assert urlparse.urlsplit(res.location)[2] == '/edit/account/'
|
assert urlparse.urlsplit(res.location)[2] == '/edit/account/'
|
||||||
|
|
||||||
# test_user has to be fetched again in order to have the current values
|
# test_user has to be fetched again in order to have the current values
|
||||||
test_user = User.query.filter(LocalUser.username==u'chris').first()
|
test_user = LocalUser.query.filter(LocalUser.username==u'chris').first()
|
||||||
assert auth_tools.bcrypt_check_password('123456', test_user.pw_hash)
|
assert auth_tools.bcrypt_check_password('123456', test_user.pw_hash)
|
||||||
|
|
||||||
# test that the password cannot be changed if the given
|
# test that the password cannot be changed if the given
|
||||||
@ -100,5 +100,5 @@ def test_change_password(test_app):
|
|||||||
'new_password': '098765',
|
'new_password': '098765',
|
||||||
})
|
})
|
||||||
|
|
||||||
test_user = User.query.filter(LocalUser.username==u'chris').first()
|
test_user = LocalUser.query.filter(LocalUser.username==u'chris').first()
|
||||||
assert not auth_tools.bcrypt_check_password('098765', test_user.pw_hash)
|
assert not auth_tools.bcrypt_check_password('098765', test_user.pw_hash)
|
||||||
|
@ -44,12 +44,12 @@ class TestUserEdit(object):
|
|||||||
self.login(test_app)
|
self.login(test_app)
|
||||||
|
|
||||||
# Make sure user exists
|
# Make sure user exists
|
||||||
assert User.query.filter(LocalUser.username=u'chris').first()
|
assert LocalUser.query.filter(LocalUser.username==u'chris').first()
|
||||||
|
|
||||||
res = test_app.post('/edit/account/delete/', {'confirmed': 'y'})
|
res = test_app.post('/edit/account/delete/', {'confirmed': 'y'})
|
||||||
|
|
||||||
# Make sure user has been deleted
|
# Make sure user has been deleted
|
||||||
assert User.query.filter(LocalUser.username==u'chris').first() == None
|
assert LocalUser.query.filter(LocalUser.username==u'chris').first() == None
|
||||||
|
|
||||||
#TODO: make sure all corresponding items comments etc have been
|
#TODO: make sure all corresponding items comments etc have been
|
||||||
# deleted too. Perhaps in submission test?
|
# deleted too. Perhaps in submission test?
|
||||||
@ -79,7 +79,7 @@ class TestUserEdit(object):
|
|||||||
'bio': u'I love toast!',
|
'bio': u'I love toast!',
|
||||||
'url': u'http://dustycloud.org/'})
|
'url': u'http://dustycloud.org/'})
|
||||||
|
|
||||||
test_user = User.query.filter(LocalUser.username==u'chris').first()
|
test_user = LocalUser.query.filter(LocalUser.username==u'chris').first()
|
||||||
assert test_user.bio == u'I love toast!'
|
assert test_user.bio == u'I love toast!'
|
||||||
assert test_user.url == u'http://dustycloud.org/'
|
assert test_user.url == u'http://dustycloud.org/'
|
||||||
|
|
||||||
@ -159,10 +159,10 @@ class TestUserEdit(object):
|
|||||||
assert urlparse.urlsplit(res.location)[2] == '/'
|
assert urlparse.urlsplit(res.location)[2] == '/'
|
||||||
|
|
||||||
# Email shouldn't be saved
|
# Email shouldn't be saved
|
||||||
email_in_db = mg_globals.database.User.query.filter(
|
email_in_db = mg_globals.database.LocalUser.query.filter(
|
||||||
LocalUser.email=='new@example.com'
|
LocalUser.email=='new@example.com'
|
||||||
).first()
|
).first()
|
||||||
email = User.query.filter(LocalUser.username=='chris').first().email
|
email = LocalUser.query.filter(LocalUser.username=='chris').first().email
|
||||||
assert email_in_db is None
|
assert email_in_db is None
|
||||||
assert email == 'chris@example.com'
|
assert email == 'chris@example.com'
|
||||||
|
|
||||||
@ -173,7 +173,7 @@ class TestUserEdit(object):
|
|||||||
res.follow()
|
res.follow()
|
||||||
|
|
||||||
# New email saved?
|
# New email saved?
|
||||||
email = User.query.filter(LocalUser.username=='chris').first().email
|
email = LocalUser.query.filter(LocalUser.username=='chris').first().email
|
||||||
assert email == 'new@example.com'
|
assert email == 'new@example.com'
|
||||||
# test changing the url inproperly
|
# test changing the url inproperly
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ def test_ldap_plugin(ldap_plugin_app):
|
|||||||
ldap_plugin_app.get('/auth/logout/')
|
ldap_plugin_app.get('/auth/logout/')
|
||||||
|
|
||||||
# Get user and detach from session
|
# Get user and detach from session
|
||||||
test_user = mg_globals.database.User.query.filter(
|
test_user = mg_globals.database.LocalUser.query.filter(
|
||||||
LocalUser.username==u'chris'
|
LocalUser.username==u'chris'
|
||||||
).first()
|
).first()
|
||||||
Session.expunge(test_user)
|
Session.expunge(test_user)
|
||||||
|
@ -168,9 +168,9 @@ class TestUserHasPrivilege:
|
|||||||
privileges=[u'admin',u'moderator',u'active'])
|
privileges=[u'admin',u'moderator',u'active'])
|
||||||
fixture_add_user(u'aeva',
|
fixture_add_user(u'aeva',
|
||||||
privileges=[u'moderator',u'active'])
|
privileges=[u'moderator',u'active'])
|
||||||
self.natalie_user = User.query.filter(
|
self.natalie_user = LocalUser.query.filter(
|
||||||
LocalUser.username==u'natalie').first()
|
LocalUser.username==u'natalie').first()
|
||||||
self.aeva_user = User.query.filter(
|
self.aeva_user = LocalUser.query.filter(
|
||||||
LocalUser.username==u'aeva').first()
|
LocalUser.username==u'aeva').first()
|
||||||
|
|
||||||
def test_privilege_added_correctly(self, test_app):
|
def test_privilege_added_correctly(self, test_app):
|
||||||
|
@ -47,9 +47,9 @@ class TestModerationViews:
|
|||||||
self.query_for_users()
|
self.query_for_users()
|
||||||
|
|
||||||
def query_for_users(self):
|
def query_for_users(self):
|
||||||
self.admin_user = User.query.filter(LocalUser.username==u'admin').first()
|
self.admin_user = LocalUser.query.filter(LocalUser.username==u'admin').first()
|
||||||
self.mod_user = User.query.filter(LocalUser.username==u'moderator').first()
|
self.mod_user = LocalUser.query.filter(LocalUser.username==u'moderator').first()
|
||||||
self.user = User.query.filter(LocalUser.username==u'regular').first()
|
self.user = LocalUser.query.filter(LocalUser.username==u'regular').first()
|
||||||
|
|
||||||
def do_post(self, data, *context_keys, **kwargs):
|
def do_post(self, data, *context_keys, **kwargs):
|
||||||
url = kwargs.pop('url', '/submit/')
|
url = kwargs.pop('url', '/submit/')
|
||||||
|
@ -192,7 +192,7 @@ class TestOpenIDPlugin(object):
|
|||||||
openid_plugin_app.get('/auth/logout')
|
openid_plugin_app.get('/auth/logout')
|
||||||
|
|
||||||
# Get user and detach from session
|
# Get user and detach from session
|
||||||
test_user = mg_globals.database.User.query.filter(
|
test_user = mg_globals.database.LocalUser.query.filter(
|
||||||
LocalUser.username==u'chris'
|
LocalUser.username==u'chris'
|
||||||
).first()
|
).first()
|
||||||
Session.expunge(test_user)
|
Session.expunge(test_user)
|
||||||
|
@ -27,8 +27,8 @@ import six.moves.urllib.parse as urlparse
|
|||||||
pytest.importorskip("requests")
|
pytest.importorskip("requests")
|
||||||
|
|
||||||
from mediagoblin import mg_globals
|
from mediagoblin import mg_globals
|
||||||
from mediagoblin.db.base import Session, LocalUser
|
from mediagoblin.db.base import Session
|
||||||
from mediagoblin.db.models import Privilege
|
from mediagoblin.db.models import Privilege, LocalUser
|
||||||
from mediagoblin.tests.tools import get_app
|
from mediagoblin.tests.tools import get_app
|
||||||
from mediagoblin.tools import template
|
from mediagoblin.tools import template
|
||||||
|
|
||||||
@ -117,14 +117,14 @@ class TestPersonaPlugin(object):
|
|||||||
persona_plugin_app.get('/auth/logout/')
|
persona_plugin_app.get('/auth/logout/')
|
||||||
|
|
||||||
# Get user and detach from session
|
# Get user and detach from session
|
||||||
test_user = mg_globals.database.User.query.filter(
|
test_user = mg_globals.database.LocalUser.query.filter(
|
||||||
LocalUser.username==u'chris'
|
LocalUser.username==u'chris'
|
||||||
).first()
|
).first()
|
||||||
active_privilege = Privilege.query.filter(
|
active_privilege = Privilege.query.filter(
|
||||||
Privilege.privilege_name==u'active').first()
|
Privilege.privilege_name==u'active').first()
|
||||||
test_user.all_privileges.append(active_privilege)
|
test_user.all_privileges.append(active_privilege)
|
||||||
test_user.save()
|
test_user.save()
|
||||||
test_user = mg_globals.database.User.query.filter(
|
test_user = mg_globals.database.LocalUser.query.filter(
|
||||||
LocalUser.username==u'chris'
|
LocalUser.username==u'chris'
|
||||||
).first()
|
).first()
|
||||||
Session.expunge(test_user)
|
Session.expunge(test_user)
|
||||||
|
@ -64,9 +64,9 @@ class TestPrivilegeFunctionality:
|
|||||||
return response, context_data
|
return response, context_data
|
||||||
|
|
||||||
def query_for_users(self):
|
def query_for_users(self):
|
||||||
self.admin_user = User.query.filter(LocalUser.username==u'alex').first()
|
self.admin_user = LocalUser.query.filter(LocalUser.username==u'alex').first()
|
||||||
self.mod_user = User.query.filter(LocalUser.username==u'meow').first()
|
self.mod_user = LocalUser.query.filter(LocalUser.username==u'meow').first()
|
||||||
self.user = User.query.filter(LocalUser.username==u'natalie').first()
|
self.user = LocalUser.query.filter(LocalUser.username==u'natalie').first()
|
||||||
|
|
||||||
def testUserBanned(self):
|
def testUserBanned(self):
|
||||||
self.login(u'natalie')
|
self.login(u'natalie')
|
||||||
|
@ -20,7 +20,7 @@ import six
|
|||||||
from mediagoblin.tools import template
|
from mediagoblin.tools import template
|
||||||
from mediagoblin.tests.tools import (fixture_add_user, fixture_media_entry,
|
from mediagoblin.tests.tools import (fixture_add_user, fixture_media_entry,
|
||||||
fixture_add_comment, fixture_add_comment_report)
|
fixture_add_comment, fixture_add_comment_report)
|
||||||
from mediagoblin.db.models import (MediaReport, CommentReport, User, LocalUser
|
from mediagoblin.db.models import (MediaReport, CommentReport, User, LocalUser,
|
||||||
MediaComment)
|
MediaComment)
|
||||||
|
|
||||||
|
|
||||||
@ -56,8 +56,8 @@ class TestReportFiling:
|
|||||||
return response, context_data
|
return response, context_data
|
||||||
|
|
||||||
def query_for_users(self):
|
def query_for_users(self):
|
||||||
return (User.query.filter(LocalUser.username==u'allie').first(),
|
return (LocalUser.query.filter(LocalUser.username==u'allie').first(),
|
||||||
User.query.filter(LocalUser.username==u'natalie').first())
|
LocalUser.query.filter(LocalUser.username==u'natalie').first())
|
||||||
|
|
||||||
def testMediaReports(self):
|
def testMediaReports(self):
|
||||||
self.login(u'allie')
|
self.login(u'allie')
|
||||||
|
@ -72,7 +72,7 @@ class TestSubmission:
|
|||||||
#### totally stupid.
|
#### totally stupid.
|
||||||
#### Also if we found a way to make this run it should be a
|
#### Also if we found a way to make this run it should be a
|
||||||
#### property.
|
#### property.
|
||||||
return User.query.filter(LocalUser.username==u'chris').first()
|
return LocalUser.query.filter(LocalUser.username==u'chris').first()
|
||||||
|
|
||||||
def login(self):
|
def login(self):
|
||||||
self.test_app.post(
|
self.test_app.post(
|
||||||
|
@ -176,7 +176,7 @@ 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',
|
||||||
privileges=[], wants_comment_notification=True):
|
privileges=[], wants_comment_notification=True):
|
||||||
# Reuse existing user or create a new one
|
# 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:
|
if test_user is None:
|
||||||
test_user = LocalUser()
|
test_user = LocalUser()
|
||||||
test_user.username = username
|
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.all_privileges.append(query.one())
|
||||||
|
|
||||||
test_user.save()
|
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:
|
# ... and detach from session:
|
||||||
Session.expunge(test_user)
|
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):
|
def fixture_comment_subscription(entry, notify=True, send_email=None):
|
||||||
if send_email is 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
|
send_email = uploader.wants_comment_notification
|
||||||
|
|
||||||
cs = CommentSubscription(
|
cs = CommentSubscription(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user