diff --git a/scipost_django/helpdesk/factories.py b/scipost_django/helpdesk/factories.py new file mode 100644 index 0000000000000000000000000000000000000000..74f51b5e34d21d87bab5ef98203d34d807474c74 --- /dev/null +++ b/scipost_django/helpdesk/factories.py @@ -0,0 +1,49 @@ +__copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)" +__license__ = "AGPL v3" + +import factory +from django.utils.text import slugify +from django.utils.timezone import timedelta + +from common.faker import LazyAwareDate, LazyRandEnum, fake + +from .models import * + + +class QueueFactory(factory.django.DjangoModelFactory): + class Meta: + model = Queue + + name = factory.Faker("word") + slug = factory.LazyAttribute(lambda self: slugify(self.name.lower())) + description = factory.Faker("text") + managing_group = factory.SubFactory("scipost.factories.GroupFactory") + parent_queue = None + + @factory.post_generation + def response_groups(self, create, extracted, **kwargs): + if not create: + return + if extracted: + for group in extracted: + self.response_groups.add(group) + + +class TicketFactory(factory.django.DjangoModelFactory): + class Meta: + model = Ticket + + queue = factory.SubFactory(QueueFactory) + title = factory.Faker("sentence") + description = factory.Faker("text") + publicly_visible = False + defined_on = LazyAwareDate("date_time_this_decade") + defined_by = factory.SubFactory("scipost.factories.UserFactory") + deadline = factory.LazyAttribute( + lambda self: fake.aware.date_time_between( + start_date=self.defined_on, end_date="+1y" + ) + ) + priority = LazyRandEnum(TICKET_PRIORITIES) + status = LazyRandEnum(TICKET_STATUSES) + assigned_to = factory.SubFactory("scipost.factories.UserFactory") diff --git a/scipost_django/helpdesk/tests/__init__.py b/scipost_django/helpdesk/tests/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/scipost_django/helpdesk/tests/test_factories.py b/scipost_django/helpdesk/tests/test_factories.py new file mode 100644 index 0000000000000000000000000000000000000000..83c1f94e81c09bdce1f49f0ef35fdaf618b5e49a --- /dev/null +++ b/scipost_django/helpdesk/tests/test_factories.py @@ -0,0 +1,17 @@ +__copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)" +__license__ = "AGPL v3" + +from django.test import TestCase +from ..factories import * + + +class TestQueueFactory(TestCase): + def test_can_create_queues(self): + queue = QueueFactory() + self.assertIsNotNone(queue) + + +class TestTicketFactory(TestCase): + def test_can_create_tickets(self): + ticket = TicketFactory() + self.assertIsNotNone(ticket)