SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit de9392e0 authored by George Katsikas's avatar George Katsikas :goat:
Browse files

add factories for all series models

parent 74b2f2cd
No related branches found
No related tags found
No related merge requests found
__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()
__copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)"
__license__ = "AGPL v3"
from django.test import TestCase
# Create your tests here.
__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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment