예제 #1
0
 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)
예제 #2
0
 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, [])
예제 #3
0
 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}]
     )
예제 #4
0
 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")
예제 #5
0
 def tearDown(self):
     SessionsBase.alter().drop_table().run_sync()
     BaseUser.alter().drop_table().run_sync()
예제 #6
0
 def setUp(self):
     SessionsBase.create_table().run_sync()
     BaseUser.create_table().run_sync()
예제 #7
0
 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()