idempotent fixtures

Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space>
This commit is contained in:
Marc 'risson' Schmitt
2024-04-15 16:18:31 +02:00
parent 2575b540fa
commit 877c264d59

View File

@ -52,8 +52,12 @@ def user_list():
parents_per_group = tenant[2] parents_per_group = tenant[2]
tenant_name = f"user-list-{user_count}-{groups_per_user}-{parents_per_group}" tenant_name = f"user-list-{user_count}-{groups_per_user}-{parents_per_group}"
t = Tenant.objects.create(schema_name=f"t_{tenant_name.replace('-', '_')}", name=uuid4()) t, created = Tenant.objects.get_or_create(
Domain.objects.create(tenant=t, domain=f"{tenant_name}.{host}") schema_name=f"t_{tenant_name.replace('-', '_')}", defaults={"name": uuid4()}
)
Domain.objects.get_or_create(tenant=t, domain=f"{tenant_name}.{host}")
if created:
continue
with t: with t:
Group.objects.bulk_create([Group(name=uuid4()) for _ in range(groups_per_user * 5)]) Group.objects.bulk_create([Group(name=uuid4()) for _ in range(groups_per_user * 5)])
@ -82,26 +86,26 @@ def user_list():
def login(): def login():
t = Tenant.objects.create(schema_name=f"t_login_no_mfa", name=uuid4()) t, created = Tenant.objects.create(schema_name=f"t_login_no_mfa", defaults={"name": uuid4()})
Domain.objects.create(tenant=t, domain=f"login-no-mfa.{host}") Domain.objects.get_or_create(tenant=t, domain=f"login-no-mfa.{host}")
if not created:
with t:
user = User(username="test", name=uuid4())
user.set_password("verySecurePassword")
user.save()
with t: t, created = Tenant.objects.create(schema_name=f"t_login_with_mfa", defaults={"name": uuid4()})
user = User(username="test", name=uuid4()) Domain.objects.get_or_create(tenant=t, domain=f"login-with-mfa.{host}")
user.set_password("verySecurePassword") if not created:
user.save() with t:
user = User(username="test", name=uuid4())
t = Tenant.objects.create(schema_name=f"t_login_with_mfa", name=uuid4()) user.set_password("verySecurePassword")
Domain.objects.create(tenant=t, domain=f"login-with-mfa.{host}") user.save()
device = user.staticdevice_set.create()
with t: # Multiple token with same token for all the iterations in the test
user = User(username="test", name=uuid4()) device.token_set.bulk_create(
user.set_password("verySecurePassword") [StaticToken(device=device, token=f"staticToken") for _ in range(1_000_000)]
user.save() )
device = user.staticdevice_set.create()
# Multiple token with same token for all the iterations in the test
device.token_set.bulk_create(
[StaticToken(device=device, token=f"staticToken") for _ in range(100000)]
)
def provider_oauth2(): def provider_oauth2():
@ -128,8 +132,12 @@ def provider_oauth2():
expression_policies_count = tenant[2] expression_policies_count = tenant[2]
tenant_name = f"provider-oauth2-{user_policies_count}-{group_policies_count}-{expression_policies_count}" tenant_name = f"provider-oauth2-{user_policies_count}-{group_policies_count}-{expression_policies_count}"
t = Tenant.objects.create(schema_name=f"t_{tenant_name.replace('-', '_')}", name=uuid4()) t, created = Tenant.objects.get_or_create(
Domain.objects.create(tenant=t, domain=f"{tenant_name}.{host}") schema_name=f"t_{tenant_name.replace('-', '_')}", defaults={"name": uuid4()}
)
Domain.objects.get_or_create(tenant=t, domain=f"{tenant_name}.{host}")
if created:
continue
with t: with t:
user = User(username="test", name=uuid4()) user = User(username="test", name=uuid4())