def create_user_and_session(self): user = BaseUser(**self.credentials, active=True, admin=True, superuser=True) user.save().run_sync() SessionsBase.create_session_sync(user_id=user.id)
def test_clean_sessions(self): SessionsBase.create_session_sync( user_id=1, expiry_date=datetime.datetime.now(), ) run_sync(clean()) session = SessionsBase.select().run_sync() self.assertEqual(session, [])
def test_create_session(self): """ Make sure sessions can be stored in the database. """ SessionsBase.create_session_sync(user_id=1) self.assertEqual( SessionsBase.select("user_id").run_sync(), [{"user_id": 1}] )
def get(self, request): data = (SessionsBase.select(SessionsBase.user_id).where( SessionsBase.token == request.cookies.get( "id")).first().run_sync()) if data: session_user = (BaseUser.select( BaseUser.username).where(BaseUser._meta.primary_key == data["user_id"]).first().run_sync()) return PlainTextResponse(f"hello {session_user['username']}") else: return PlainTextResponse("hello world")
def tearDown(self): SessionsBase.alter().drop_table().run_sync() BaseUser.alter().drop_table().run_sync()
def setUp(self): SessionsBase.create_table().run_sync() BaseUser.create_table().run_sync()
def setUp(self): SessionsBase.create_table(if_not_exists=True).run_sync() BaseUser.create_table(if_not_exists=True).run_sync() BaseUser( **self.credentials, active=True, admin=True, superuser=True ).save().run_sync()