Google App Engine set up a user when using testbed

后端 未结 2 1256
既然无缘
既然无缘 2020-12-17 16:20

I\'m using the GAE testbed service and when I run users.get_current_user() I get None i.e.

>>> import sys
>>> sys         


        
相关标签:
2条回答
  • 2020-12-17 16:59

    After some experimentation the following worked for me:

    >>> os.environ['USER_EMAIL'] = 'a@b.c'
    >>> os.environ['USER_ID'] = '123'
    >>> users.get_current_user()
    users.User(email='a@b.c',_user_id='123')
    

    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

    >>> os.environ['AUTH_DOMAIN'] = 'testbed'
    

    Per Elliot de Vries comment, for an administrative user:

    >>> os.environ['USER_IS_ADMIN'] = '1'
    
    0 讨论(0)
  • 2020-12-17 17:06

    To simulate a sign in of an admin user, you can call anywhere in your test function:

    self.testbed.setup_env(
        USER_EMAIL = 'test@example.com',
        USER_ID = '123',
        USER_IS_ADMIN = '1',
        overwrite = True)
    

    Note that you need to use the overwrite=True parameter!

    0 讨论(0)
提交回复
热议问题