feat(tests): add function to populate DIT with Users
This commit is contained in:
parent
c193f1faae
commit
0d307591ca
@ -1,12 +1,14 @@
|
|||||||
"""Generates fake user accounts."""
|
"""Generates fake user accounts."""
|
||||||
|
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from faker import Faker
|
from faker import Faker
|
||||||
|
|
||||||
from lumi2.usermodel import User
|
from lumi2.usermodel import User
|
||||||
|
import lumi2.ldap as ldap
|
||||||
|
|
||||||
|
|
||||||
def get_random_avatar() -> Image.Image:
|
def get_random_avatar() -> Image.Image:
|
||||||
@ -35,3 +37,18 @@ def generate_random_user() -> User:
|
|||||||
faker.last_name(),
|
faker.last_name(),
|
||||||
picture=get_random_avatar(),
|
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()
|
||||||
|
Loading…
Reference in New Issue
Block a user