lundi 2 février 2015

How to pass/mock the admin_required decorator in gae?


class Generator(Resource):

@admin_required
def get(self):
pass


If I add the @admin_required decorator on my view, the unit test start failing, with the message:



RuntimeError: working outside of request context



Is there a way to mock it or bypass it for unit tests?


Here is the decorator:



def admin_required(func):
"""Requires App Engine admin credentials"""
@wraps(func)
def decorated_view(*args, **kwargs):
if users.get_current_user():
if not users.is_current_user_admin():
abort(401) # Unauthorized
return func(*args, **kwargs)
return redirect(users.create_login_url(request.url))
return decorated_view

Aucun commentaire:

Enregistrer un commentaire