-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbtest.py
27 lines (22 loc) · 1.05 KB
/
dbtest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import asyncio, sys
from database.accesscontrol import User, Role, UserPrivilegeManager
from database.core import Database
async def main():
db = Database(r"""user=postgres dbname=telescope_staging host=35.192.191.179 password=e@'^A$#gJQZT~&t(""")
# await db.execute(Role.CREATE_TABLE)
# print(await db.execute("INSERT INTO roles (name) VALUES ('test1')"))
# print(await db.execute("INSERT INTO roles (name) VALUES ('test2')"))
# await db.execute(User.CREATE_TABLE)
# await db.execute("INSERT INTO users (email, roles) VALUES ('[email protected]', '{1, 2}')")
# print(await db.execute("SELECT roles FROM users WHERE email = %s", ("[email protected]",)))
rbac = UserPrivilegeManager(db, 300)
await rbac.init()
print(rbac.get_privileges_for_pair([1,2], [1,2]))
print(await rbac.get_or_create_user("[email protected]"))
await db.close_all()
#
if __name__ == "__main__":
# make aiopg work on windows
if sys.version_info >= (3, 8) and sys.platform.lower().startswith("win"):
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
asyncio.run(main())