Skip to content

Commit

Permalink
add generate dummies to actions
Browse files Browse the repository at this point in the history
  • Loading branch information
tiptenbrink committed Dec 21, 2023
1 parent 17c1499 commit c11438e
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions backend/actions/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

from apiserver.data import Source, ops
from apiserver import data
from apiserver.data.api.ud.userdata import new_userdata
from apiserver.lib.model.entities import SignedUp
from auth.data.relational.opaque import get_setup
from faker import Faker

import opaquepy as opq

Expand Down Expand Up @@ -95,6 +99,59 @@ async def print_admin_token():
print(admin_token)


async def generate_dummies():
local_dsrc = await get_local_dsrc()
faker = Faker()
admin_password = "admin"
async with data.get_conn(local_dsrc) as conn:
setup = await get_setup(conn)

# setup = ""
faker_u = faker.unique

for i in range(99):
fname = faker_u.first_name()
lname = faker_u.last_name()
email = f"{fname}.{lname}@gmail.com"
su = SignedUp(
firstname=fname,
lastname=lname,
email=email,
phone=faker_u.phone_number(),
confirmed=True,
)
av40id = int.from_bytes(faker_u.binary(2), byteorder="big")
register_id = auth.core.util.random_time_hash_hex()
joined = faker.date()
async with data.get_conn(local_dsrc) as conn:
uid = await data.user.new_user(
conn,
su,
register_id=register_id,
av40id=av40id,
joined=joined,
)
userdata = new_userdata(su, uid, register_id, av40id, joined)

cl_req, cl_state = opq.register_client(admin_password)
serv_resp = opq.register(setup, cl_req, uid)
cl_fin = opq.register_client_finish(cl_state, admin_password, serv_resp)
pw_file = opq.register_finish(cl_fin)
birthdate = faker.date()
new_ud = data.ud.finished_userdata(
userdata,
callname=fname,
eduinstitution="TU Delft",
birthdate=birthdate,
show_age=True,
)

await data.user.UserOps.update_password_file(conn, uid, pw_file)
did_ups = await data.ud.upsert_userdata(conn, new_ud)
print(did_ups)
await data.signedup.delete_signedup(conn, email)


async def run_function(func_name):
module = sys.modules['__main__']
func = getattr(module, func_name)
Expand Down

0 comments on commit c11438e

Please sign in to comment.