feat(tests): add function to populate DIT with Users

This commit is contained in:
Julian Lobbes 2022-11-30 00:20:52 +01:00
parent c193f1faae
commit 0d307591ca

View File

@ -1,12 +1,14 @@
"""Generates fake user accounts."""
from io import BytesIO
from time import sleep
import requests
from PIL import Image
from faker import Faker
from lumi2.usermodel import User
import lumi2.ldap as ldap
def get_random_avatar() -> Image.Image:
@ -35,3 +37,18 @@ def generate_random_user() -> User:
faker.last_name(),
picture=get_random_avatar(),
)
def populate_users(num_of_users: int = 10) -> None:
"""Populates the DIT with the specified number of randomly generated users."""
conn = ldap.get_connection()
for i in range(num_of_users):
print(f"Creating a random user... ({i+1}/{num_of_users})")
user = generate_random_user()
ldap.create_user(conn, user)
user._generate_static_images()
# Delay to give 'thispersondoesnotexist.com' time to generate a new image
if i < num_of_users - 1:
sleep(1)
conn.unbind()