(tests) test dimail setup command

Test (and slightly improve) dimail setup command,
which populate database on local dimail container
This commit is contained in:
Marie PUPO JEAMMET
2024-09-30 19:44:45 +02:00
committed by Laurent Bossavit
parent 988a091e53
commit 989239082e
3 changed files with 88 additions and 12 deletions

View File

@@ -7,6 +7,9 @@ from django.core.management.base import BaseCommand, CommandError
import requests
from rest_framework import status
from mailbox_manager.enums import MailDomainStatusChoices
from mailbox_manager.models import MailDomain
User = get_user_model()
@@ -48,16 +51,21 @@ class Command(BaseCommand):
perms=["new_domain", "create_users", "manage_users"],
)
# we create a domain and add John Doe to it
domain_name = "test.domain.com"
if not MailDomain.objects.filter(name=domain_name).exists():
MailDomain.objects.create(
name=domain_name, status=MailDomainStatusChoices.ENABLED
)
self.create_domain(domain_name)
# we create a dimail user for keycloak+regie user John Doe
# This way, la Régie will be able to make request in the name of
# this user
people_base_user = User.objects.get(name="John Doe")
self.create_user(name=people_base_user.sub, password="whatever") # noqa S106
# we create a domain and add John Doe to it
domain_name = "test.domain.com"
self.create_domain(domain_name)
self.create_allows(people_base_user.sub, domain_name)
people_base_user = User.objects.filter(name="John Doe")
if people_base_user.exists():
self.create_user(name=people_base_user.sub, password="whatever") # noqa S106
self.create_allows(people_base_user.sub, domain_name)
self.stdout.write("DONE", ending="\n")