def __init__(self, req): self.req = req self.grant = None access_token = self.extract_access_token(req) if access_token is not None: self._new = False self.grant = self.fetch_password_grant(req, access_token) else: self._new = True self.grant = Grant.new_password_grant( None, # user_id set by self.remember() req.user_agent, req.remote_addr)
def test_context(): with scoped_session(quick_sessionmaker()) as db_session: email = ''.join(choice(letters) for i in range(10)) + '@test.com' # use a fixed user id, since this would # otherwise change in each test function. user = User(email=email, password='******', is_verified=True) user.id = PUBLIC_ID.next_id() grant = Grant.new_password_grant(user, 'user-agent', '0.0.0.0') db_session.add(user) db_session.add(grant) return { 'user': user.__json__(), 'grant': grant.__json__(), }