From b9284b595dd74872afac85d68cc0d77a5cd6c90e Mon Sep 17 00:00:00 2001
From: George Katsikas <giorgakis.katsikas@gmail.com>
Date: Tue, 14 Nov 2023 13:24:07 +0100
Subject: [PATCH] add factories for all careers models

---
 scipost_django/careers/factories.py           | 37 +++++++++++++++++++
 .../careers/tests/test_factories.py           | 18 +++++++++
 2 files changed, 55 insertions(+)
 create mode 100644 scipost_django/careers/factories.py
 create mode 100644 scipost_django/careers/tests/test_factories.py

diff --git a/scipost_django/careers/factories.py b/scipost_django/careers/factories.py
new file mode 100644
index 000000000..2681f2111
--- /dev/null
+++ b/scipost_django/careers/factories.py
@@ -0,0 +1,37 @@
+from django.utils.text import slugify
+import factory
+
+from common.faker import LazyAwareDate, LazyRandEnum
+from scipost.constants import TITLE_CHOICES
+
+from .models import JobApplication, JobOpening
+
+
+class JobOpeningFactory(factory.django.DjangoModelFactory):
+    class Meta:
+        model = JobOpening
+
+    title = factory.Faker("job")
+    short_description = factory.Faker("sentence")
+    description = factory.Faker("paragraph")
+    application_deadline = LazyAwareDate("date_this_year")
+    status = LazyRandEnum(JobOpening.JOBOPENING_STATUSES)
+    announced = LazyAwareDate("date_this_year")
+    slug = factory.LazyAttribute(lambda self: slugify(self.title))
+
+
+class JobApplicationFactory(factory.django.DjangoModelFactory):
+    class Meta:
+        model = JobApplication
+
+    uuid = factory.Faker("uuid4")
+    status = LazyRandEnum(JobApplication.JOBAPP_STATUSES)
+    last_updated = LazyAwareDate("date_this_year")
+    job_opening = factory.SubFactory(JobOpeningFactory)
+    date_received = LazyAwareDate("date_this_year")
+    title = LazyRandEnum(TITLE_CHOICES)
+    first_name = factory.Faker("first_name")
+    last_name = factory.Faker("last_name")
+    email = factory.Faker("email")
+    motivation = factory.django.FileField()
+    cv = factory.django.FileField()
diff --git a/scipost_django/careers/tests/test_factories.py b/scipost_django/careers/tests/test_factories.py
new file mode 100644
index 000000000..0945dd491
--- /dev/null
+++ b/scipost_django/careers/tests/test_factories.py
@@ -0,0 +1,18 @@
+__copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)"
+__license__ = "AGPL v3"
+
+from django.test import TestCase
+
+from ..factories import JobApplicationFactory, JobOpeningFactory
+
+
+class TestJobOpeningFactory(TestCase):
+    def test_can_create_job_openings(self):
+        job_opening = JobOpeningFactory()
+        self.assertIsNotNone(job_opening)
+
+
+class TestJobApplicationFactory(TestCase):
+    def test_can_create_job_applications(self):
+        job_application = JobApplicationFactory()
+        self.assertIsNotNone(job_application)
-- 
GitLab