def test_is_current_user_admin_only_cookie_user(self): # Cookie only self.oauth_logout() dummy_mail = '*****@*****.**' # Not an admin self.cookie_login(dummy_mail, is_admin=False) self.assertFalse(auth_utils.is_current_user_admin()) # Is an admin self.cookie_login(dummy_mail, is_admin=True) self.assertTrue(auth_utils.is_current_user_admin()) self.cookie_logout()
def test_is_current_user_admin_oauth_only_is_admin(self): # Can't call is_current_user_admin twice in the same test because the OAuth # user gets set once and cached. oauth_mail = '*****@*****.**' # Is an admin self.oauth_login(oauth_mail, is_admin=True) self.assertTrue(auth_utils.is_current_user_admin())
def process_request(self, request): request.user = auth_utils.get_current_user() request.user_is_admin = auth_utils.is_current_user_admin() # Update the cached value of the current user's Account account = None if request.user is not None: account = models.Account.get_account_for_user(request.user) models.Account.current_user_account = account
def test_is_current_user_admin_both_cookie_and_oauth_user(self): self.cookie_login('*****@*****.**', is_admin=True) self.oauth_login('*****@*****.**', is_admin=True) self.assertTrue(auth_utils.is_current_user_admin())
def test_is_current_user_admin_no_users(self): self.cookie_logout() self.oauth_logout() self.assertFalse(auth_utils.is_current_user_admin())