Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7756115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:44:13+00:00 2026-06-01T12:44:13+00:00

When using Google App Engine 1.6.4 testbed with Flask 0.8, and in particular the

  • 0

When using Google App Engine 1.6.4 testbed with Flask 0.8, and in particular the Flask-Login 0.1 package (source), I encounter a strange problem with command-line unit testing.

Below is an example that demonstrates the problem. Note the commented line (from google.appengine.ext import testbed). When this line is commented, the tests work as expected.

When this line is uncommented, the @login_required decorator for Flask-Login stops recognizing the logged-in user i.e. current_user.is_authenticated() returns False. It would seem the culprit is importing testbed.

#!/usr/bin/env python2.7
import unittest
import sys
from flask import Flask, current_app, url_for
from flaskext import login

sys.path.append('/usr/local/google_appengine')

# Go ahead and uncomment this:
# from google.appengine.ext import testbed

app = Flask('test')
app.secret_key = 'abc'

login_manager = login.LoginManager()
login_manager.setup_app(app)
login_manager.login_view = 'index'

class User(login.UserMixin):
    def get_id(self):
        return "1"

@login_manager.user_loader
def load_user(user_id):
    return User()

@app.route('/')
@login.login_required
def index():
    pass

@login_manager.unauthorized_handler
def unauthorized():
    raise Exception("Unauthorized.")

class MyTest(unittest.TestCase):
    def setUp(self):
        self.app = app
        self.client = app.test_client()

    def test_user(self):
        with self.app.test_request_context():
            logged_in = login.login_user(User())
            r = self.client.get('/')

if __name__ == '__main__':
    unittest.main()

The specific exception is:

ERROR:test:Exception on / [GET]
Traceback (most recent call last):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Flask-0.8-py2.7.egg/flask/app.py", line 1504, in wsgi_app
    response = self.full_dispatch_request()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Flask-0.8-py2.7.egg/flask/app.py", line 1264, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Flask-0.8-py2.7.egg/flask/app.py", line 1262, in full_dispatch_request
    rv = self.dispatch_request()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Flask-0.8-py2.7.egg/flask/app.py", line 1248, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Flask_Login-0.1-py2.7.egg/flaskext/login.py", line 479, in decorated_view
    return current_app.login_manager.unauthorized()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Flask_Login-0.1-py2.7.egg/flaskext/login.py", line 250, in unauthorized
    return self.unauthorized_callback()
  File "./test.py", line 34, in unauthorized
    raise Exception("Unauthorized.")
Exception: Unauthorized.

The behaviour I would expect is that importing (and using) testbed would have no effect on the Flask context stack and, by extension, Flask-Login would continue to work in the unit testing environment even though testbed has been imported.

I have stared at this for a bit, to no avail, and would be grateful for any insight and suggestions for potential solutions to this problem.

Thank you for reading.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:44:14+00:00Added an answer on June 1, 2026 at 12:44 pm

    The testbed uses separate stubs for many of the GAE services, including the datastore and user service.

    I’m not familiar with flask, but if the login requires a user to exist in the database, it’ll fail since the testbed uses a separate database. You’ll have to load user data into the testbed database first.

    Also if you include the testbed, there’s some initialization calls you have to make to set up the stubs before you can use it. https://developers.google.com/appengine/docs/python/tools/localunittesting

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using testbed to unit test my google app engine app, and my app
I'm using Google App Engine (Python), and using OpenID for login. Specifically, I'm playing
I am using the Google App Engine testbed framework to write test cases with
I using google app engine, in 0.96 I have no problem to include a
When using Google app engine is there any benefit to use a CDN if
I am using Google App Engine with Google's JDO implementation to save an entity
I'm using Google App Engine python. I want to know what browser the user
I'm using Google App Engine (Python) and Chanel api. Is it possible to show
I've been developing a Facebook app using Google App Engine in Python and the
I am developing a website using Google App Engine and Django 1.0 (app-engine-patch) A

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.