From ce3f6a8fc424511dc33d2673a8ab495ba3d92156 Mon Sep 17 00:00:00 2001 From: George Katsikas <giorgakis.katsikas@gmail.com> Date: Wed, 20 Mar 2024 12:18:03 +0100 Subject: [PATCH] add factories for all funders models --- scipost_django/funders/factories.py | 27 +++++++++++++++++++ .../funders/tests/test_factories.py | 19 +++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 scipost_django/funders/factories.py create mode 100644 scipost_django/funders/tests/test_factories.py diff --git a/scipost_django/funders/factories.py b/scipost_django/funders/factories.py new file mode 100644 index 000000000..eccd40eda --- /dev/null +++ b/scipost_django/funders/factories.py @@ -0,0 +1,27 @@ +__copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)" +__license__ = "AGPL v3" + +import random +from .models import * +import factory + + +class FunderFactory(factory.django.DjangoModelFactory): + class Meta: + model = Funder + + organization = factory.SubFactory("organizations.factories.OrganizationFactory") + name = factory.SelfAttribute("organization.name") + acronym = factory.SelfAttribute("organization.acronym") + identifier = factory.Faker("numerify", text="http://dx.doi.org/10.#####/#########") + + +class GrantFactory(factory.django.DjangoModelFactory): + class Meta: + model = Grant + + funder = factory.SubFactory(FunderFactory) + number = factory.Faker("isbn10") + recipient = factory.SubFactory("scipost.factories.ContributorFactory") + recipient_name = factory.SelfAttribute("recipient.profile.full_name") + further_details = factory.Faker("text") diff --git a/scipost_django/funders/tests/test_factories.py b/scipost_django/funders/tests/test_factories.py new file mode 100644 index 000000000..be9bac9f8 --- /dev/null +++ b/scipost_django/funders/tests/test_factories.py @@ -0,0 +1,19 @@ +__copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)" +__license__ = "AGPL v3" + + +from django.test import TestCase +from ..factories import * + + +# Create your tests here. +class TestFunderFactory(TestCase): + def test_can_create_funders(self): + funder = FunderFactory() + self.assertIsNotNone(funder) + + +class TestGrantFactory(TestCase): + def test_can_create_grants(self): + grant = GrantFactory() + self.assertIsNotNone(grant) -- GitLab