I'm using the GAE testbed service and when I run users.get_current_user()
I get None
i.e.
>>> import sys
>>> sys.path.append("/usr/local/google_appengine") # for Mac OS X
>>> from google.appengine.api import users
>>> from google.appengine.ext import testbed
>>> testbed = testbed.Testbed()
>>> testbed.activate()
>>> testbed.init_user_stub()
>>> users.get_current_user() == None
True
This is the expected result. However, I'd like to log in a fake user when running some of my unit tests.
If it's possible (and I expect it would be), how can one log a user in when running testbed
from the command line so that get_current_user()
returns an actual user?
Thanks for reading.
After some experimentation the following worked for me:
I hope this is a good solution, and this answer helps the next person to run into this issue.
EDIT: Related variables
To avoid
/google/appengine/api/users.py:115 - AssertionError: assert _auth_domain
Per Elliot de Vries comment, for an administrative user:
To simulate a sign in of an admin user, you can call anywhere in your test function:
Note that you need to use the
overwrite=True
parameter!