diff --git a/scipost_django/series/factories.py b/scipost_django/series/factories.py new file mode 100644 index 0000000000000000000000000000000000000000..c858b04d14c822f01f09720d3de43c23ffa8f449 --- /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 ddef03c4df91383dfce15a034976e3a469d77d70..0000000000000000000000000000000000000000 --- 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 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/scipost_django/series/tests/test_factories.py b/scipost_django/series/tests/test_factories.py new file mode 100644 index 0000000000000000000000000000000000000000..7afadbb7208325c8832a0b8be72c0f46b12f756d --- /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)