From de9392e051b8ad63148ce9c284f32a7517fbd3eb Mon Sep 17 00:00:00 2001
From: George Katsikas <giorgakis.katsikas@gmail.com>
Date: Mon, 20 Nov 2023 18:08:29 +0100
Subject: [PATCH] add factories for all series models

---
 scipost_django/series/factories.py            | 53 +++++++++++++++++++
 scipost_django/series/tests.py                |  7 ---
 scipost_django/series/tests/__init__.py       |  0
 scipost_django/series/tests/test_factories.py | 17 ++++++
 4 files changed, 70 insertions(+), 7 deletions(-)
 create mode 100644 scipost_django/series/factories.py
 delete mode 100644 scipost_django/series/tests.py
 create mode 100644 scipost_django/series/tests/__init__.py
 create mode 100644 scipost_django/series/tests/test_factories.py

diff --git a/scipost_django/series/factories.py b/scipost_django/series/factories.py
new file mode 100644
index 000000000..c858b04d1
--- /dev/null
+++ b/scipost_django/series/factories.py
@@ -0,0 +1,53 @@
+__copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)"
+__license__ = "AGPL v3"
+
+
+import factory
+from common.faker import fake
+from django.utils.text import slugify
+from journals.factories import JournalFactory
+
+from .models import *
+
+
+class SeriesFactory(factory.django.DjangoModelFactory):
+    class Meta:
+        model = Series
+
+    name = factory.Faker("sentence", nb_words=4)
+    slug = factory.LazyAttribute(lambda self: slugify(self.name))
+    description = factory.Faker("paragraph")
+    information = factory.Faker("paragraph")
+    image = factory.django.ImageField()
+
+    @factory.post_generation
+    def container_journals(self, create, extracted, **kwargs):
+        if not create:
+            return
+
+        if extracted:
+            for journal in extracted:
+                self.container_journals.add(journal)
+        else:
+            self.container_journals.add(JournalFactory())
+
+
+class CollectionFactory(factory.django.DjangoModelFactory):
+    class Meta:
+        model = Collection
+
+    series = factory.SubFactory(SeriesFactory)
+    name = factory.Faker("sentence", nb_words=4)
+    slug = factory.LazyAttribute(lambda self: slugify(self.name))
+
+    description = factory.Faker("paragraph")
+    event_details = factory.Faker("paragraph")
+
+    event_start_date = factory.Faker("date_this_decade")
+    event_end_date = factory.LazyAttribute(
+        lambda self: fake.aware.date_between(
+            start_date=self.event_start_date, end_date="+1y"
+        )
+    )
+
+    image = factory.django.ImageField()
diff --git a/scipost_django/series/tests.py b/scipost_django/series/tests.py
deleted file mode 100644
index ddef03c4d..000000000
--- a/scipost_django/series/tests.py
+++ /dev/null
@@ -1,7 +0,0 @@
-__copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)"
-__license__ = "AGPL v3"
-
-
-from django.test import TestCase
-
-# Create your tests here.
diff --git a/scipost_django/series/tests/__init__.py b/scipost_django/series/tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/scipost_django/series/tests/test_factories.py b/scipost_django/series/tests/test_factories.py
new file mode 100644
index 000000000..7afadbb72
--- /dev/null
+++ b/scipost_django/series/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 TestSeriesFactory(TestCase):
+    def test_can_create_series(self):
+        series = SeriesFactory()
+        self.assertIsNotNone(series)
+
+
+class TestCollectionFactory(TestCase):
+    def test_can_create_collections(self):
+        collection = CollectionFactory()
+        self.assertIsNotNone(collection)
-- 
GitLab