🔨(demo) add domains creation to demo
Add domains creation to "make demo" rule. Update related test.
This commit is contained in:
committed by
Marie
parent
05c8f636dd
commit
55dc342a8b
@@ -4,4 +4,5 @@ NB_OBJECTS = {
|
|||||||
"users": 1000,
|
"users": 1000,
|
||||||
"teams": 100,
|
"teams": 100,
|
||||||
"max_users_per_team": 100,
|
"max_users_per_team": 100,
|
||||||
|
"domains": 20,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,12 +10,15 @@ from uuid import uuid4
|
|||||||
from django import db
|
from django import db
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.management.base import BaseCommand, CommandError
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
|
from django.utils.text import slugify
|
||||||
|
|
||||||
from faker import Faker
|
from faker import Faker
|
||||||
|
|
||||||
from core import models
|
from core import models
|
||||||
|
|
||||||
from demo import defaults
|
from demo import defaults
|
||||||
|
from mailbox_manager import models as mailbox_models
|
||||||
|
from mailbox_manager.enums import MailDomainStatusChoices
|
||||||
|
|
||||||
fake = Faker()
|
fake = Faker()
|
||||||
|
|
||||||
@@ -152,6 +155,35 @@ def create_demo(stdout):
|
|||||||
)
|
)
|
||||||
queue.flush()
|
queue.flush()
|
||||||
|
|
||||||
|
with Timeit(stdout, "Creating domains"):
|
||||||
|
for _i in range(defaults.NB_OBJECTS["domains"]):
|
||||||
|
name = fake.domain_name()
|
||||||
|
slug = slugify(name)
|
||||||
|
|
||||||
|
queue.push(
|
||||||
|
mailbox_models.MailDomain(
|
||||||
|
name=name,
|
||||||
|
# slug should be automatic but bulk_create doesn't use save
|
||||||
|
slug=slug,
|
||||||
|
status=random.choice(MailDomainStatusChoices.choices)[0],
|
||||||
|
)
|
||||||
|
)
|
||||||
|
queue.flush()
|
||||||
|
|
||||||
|
with Timeit(stdout, "Creating accesses to domains"):
|
||||||
|
domains_ids = list(
|
||||||
|
mailbox_models.MailDomain.objects.values_list("id", flat=True)
|
||||||
|
)
|
||||||
|
for domain_id in domains_ids:
|
||||||
|
queue.push(
|
||||||
|
mailbox_models.MailDomainAccess(
|
||||||
|
domain_id=domain_id,
|
||||||
|
user_id=random.choice(users_ids),
|
||||||
|
role=models.RoleChoices.OWNER,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
queue.flush()
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
"""A management command to create a demo database."""
|
"""A management command to create a demo database."""
|
||||||
|
|||||||
@@ -10,12 +10,13 @@ import pytest
|
|||||||
from core import models
|
from core import models
|
||||||
|
|
||||||
from demo import defaults
|
from demo import defaults
|
||||||
|
from mailbox_manager import models as mailbox_models
|
||||||
|
|
||||||
TEST_NB_OBJECTS = {
|
TEST_NB_OBJECTS = {
|
||||||
"users": 5,
|
"users": 5,
|
||||||
"teams": 3,
|
"teams": 3,
|
||||||
"max_identities_per_user": 3,
|
|
||||||
"max_users_per_team": 5,
|
"max_users_per_team": 5,
|
||||||
|
"domains": 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
pytestmark = pytest.mark.django_db
|
pytestmark = pytest.mark.django_db
|
||||||
@@ -27,9 +28,11 @@ def test_commands_create_demo():
|
|||||||
"""The create_demo management command should create objects as expected."""
|
"""The create_demo management command should create objects as expected."""
|
||||||
call_command("create_demo")
|
call_command("create_demo")
|
||||||
|
|
||||||
assert models.User.objects.count() == 5
|
assert models.User.objects.count() == TEST_NB_OBJECTS["users"]
|
||||||
assert models.Team.objects.count() == 3
|
assert models.Team.objects.count() == TEST_NB_OBJECTS["teams"]
|
||||||
assert models.TeamAccess.objects.count() >= 3
|
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"]
|
||||||
|
|
||||||
|
|
||||||
def test_commands_createsuperuser():
|
def test_commands_createsuperuser():
|
||||||
|
|||||||
Reference in New Issue
Block a user