(e2e) add specific accounts for testing

This creates a bunch of accounts with various profiles
to allow testing in a specific "mode"
This commit is contained in:
Quentin BEY
2024-11-13 16:54:54 +01:00
committed by BEY Quentin
parent 6123e11dd4
commit 59f3499799
13 changed files with 394 additions and 48 deletions

View File

@@ -106,7 +106,7 @@ class Timeit:
return elapsed_time
def create_demo(stdout):
def create_demo(stdout): # pylint: disable=too-many-locals
"""
Create a database with demo data for developers to work in a realistic environment.
The code is engineered to create a huge number of objects fast.
@@ -190,7 +190,6 @@ def create_demo(stdout):
queue.push(
models.TeamAccess(team_id=team_id, user_id=user_id, role=role[0])
)
queue.flush()
with Timeit(stdout, "Creating domains"):
created = set()
@@ -224,6 +223,75 @@ def create_demo(stdout):
role=models.RoleChoices.OWNER,
)
)
queue.flush()
with Timeit(stdout, "Creating specific users"):
# ⚠️ Warning: this users also need to be created in the keycloak
# realm.json AND the OIDC setting to fallback on user email
# should be set to True, because we don't pilot the sub.
for role in models.RoleChoices.values:
team_user = models.User(
sub=uuid4(),
email=f"jean.team-{role}@example.com",
name=f"Jean Group {role.capitalize()}",
password="!",
is_superuser=False,
is_active=True,
is_staff=False,
language=random.choice(settings.LANGUAGES)[0],
)
queue.push(team_user)
queue.push(
models.TeamAccess(team_id=teams_ids[0], user_id=team_user.pk, role=role)
)
for role in models.RoleChoices.values:
user_with_mail = models.User(
sub=uuid4(),
email=f"jean.mail-{role}@example.com",
name=f"Jean Mail {role.capitalize()}",
password="!",
is_superuser=False,
is_active=True,
is_staff=False,
language=random.choice(settings.LANGUAGES)[0],
)
queue.push(user_with_mail)
queue.push(
mailbox_models.MailDomainAccess(
domain_id=domains_ids[0],
user_id=user_with_mail.pk,
role=role,
)
)
for team_role in models.RoleChoices.values:
for domain_role in models.RoleChoices.values:
team_mail_user = models.User(
sub=uuid4(),
email=f"jean.team-{team_role}-mail-{domain_role}@example.com",
name=f"Jean Group {team_role.capitalize()} Mail {domain_role.capitalize()}",
password="!",
is_superuser=False,
is_active=True,
is_staff=False,
language=random.choice(settings.LANGUAGES)[0],
)
queue.push(team_mail_user)
queue.push(
models.TeamAccess(
team_id=teams_ids[0], user_id=team_mail_user.pk, role=team_role
)
)
queue.push(
mailbox_models.MailDomainAccess(
domain_id=domains_ids[0],
user_id=team_mail_user.pk,
role=domain_role,
)
)
queue.flush()

View File

@@ -28,13 +28,22 @@ def test_commands_create_demo():
"""The create_demo management command should create objects as expected."""
call_command("create_demo")
assert (
models.User.objects.count() == TEST_NB_OBJECTS["users"] + 3
) # Monique Test, Jeanne Test and Jean Something (quick fix for e2e)
# Monique Test, Jeanne Test and Jean Something (quick fix for e2e)
# 3 user with team rights
# 3 user with domain rights
# 3 x 3 user with both rights
assert models.User.objects.count() == TEST_NB_OBJECTS["users"] + 3 + 3 + 3 + 9
assert models.Team.objects.count() == TEST_NB_OBJECTS["teams"]
assert models.TeamAccess.objects.count() >= TEST_NB_OBJECTS["teams"]
assert mailbox_models.MailDomain.objects.count() == TEST_NB_OBJECTS["domains"]
assert mailbox_models.MailDomainAccess.objects.count() == TEST_NB_OBJECTS["domains"]
# 3 domain access for each user with domain rights
# 3 x 3 domain access for each user with both rights
assert (
mailbox_models.MailDomainAccess.objects.count()
== TEST_NB_OBJECTS["domains"] + 3 + 9
)
def test_commands_createsuperuser():