diff --git a/scipost_django/organizations/factories.py b/scipost_django/organizations/factories.py index 1641007ca6bf9e4547fb30c4abc57cb2e8a82694..0849b3e98ec6c0f8f4b21ac0be9400329a5c6230 100644 --- a/scipost_django/organizations/factories.py +++ b/scipost_django/organizations/factories.py @@ -1,8 +1,22 @@ import factory -from common import faker -from common.faker import LazyRandEnum -from organizations.constants import ORGANIZATION_STATUSES, ORGANIZATION_TYPES -from organizations.models import Organization +import faker + +from common.faker import LazyAwareDate, LazyRandEnum, fake +from organizations.constants import ( + ORGANIZATION_EVENTS, + ORGANIZATION_STATUSES, + ORGANIZATION_TYPES, + ROLE_KINDS, +) +from organizations.models import ( + Contact, + ContactPerson, + ContactRole, + Organization, + OrganizationEvent, + OrganizationLogo, +) +from scipost.constants import TITLE_CHOICES class OrganizationFactory(factory.django.DjangoModelFactory): @@ -26,11 +40,65 @@ class OrganizationFactory(factory.django.DjangoModelFactory): address = factory.Faker("address") logo = factory.django.ImageField() css_class = "" - grid_json = {} + ror_json = {} crossref_json = {} parent = None superseded_by = None - cf_associated_publication_ids = {} - cf_nr_associated_publications = 0 - cf_balance_info = {} - cf_expenditure_for_publication = {} + + +class OrganizationLogoFactory(factory.django.DjangoModelFactory): + class Meta: + model = OrganizationLogo + + organization = factory.SubFactory(OrganizationFactory) + image = factory.django.ImageField() + mimetype = LazyRandEnum(OrganizationLogo.MIMETYPE_CHOICES) + width = factory.Faker("pyint") + height = factory.Faker("pyint") + order = factory.Sequence(lambda n: n) + + +class OrganizationEventFactory(factory.django.DjangoModelFactory): + class Meta: + model = OrganizationEvent + + organization = factory.SubFactory(OrganizationFactory) + event = LazyRandEnum(ORGANIZATION_EVENTS) + comments = factory.Faker("text") + noted_on = LazyAwareDate("date_this_year") + noted_by = factory.SubFactory("scipost.factories.UserFactory") + + +class ContactFactory(factory.django.DjangoModelFactory): + class Meta: + model = Contact + + user = factory.SubFactory("scipost.factories.UserFactory") + title = factory.SelfAttribute("user.contributor.profile.title") + activation_key = factory.SelfAttribute("user.contributor.activation_key") + key_expires = factory.SelfAttribute("user.contributor.key_expires") + + +class ContactRoleFactory(factory.django.DjangoModelFactory): + class Meta: + model = ContactRole + + contact = factory.SubFactory(ContactFactory) + organization = factory.SubFactory(OrganizationFactory) + kind = LazyRandEnum(ROLE_KINDS, repeat=2) + date_from = LazyAwareDate("date_this_year") + date_until = factory.LazyAttribute( + lambda self: fake.aware.date_between(start_date=self.date_from, end_date="+1y") + ) + + +class ContactPersonFactory(factory.django.DjangoModelFactory): + class Meta: + model = ContactPerson + + organization = factory.SubFactory(OrganizationFactory) + title = LazyRandEnum(TITLE_CHOICES) + first_name = factory.Faker("first_name") + last_name = factory.Faker("last_name") + email = factory.Faker("email") + role = factory.Faker("job") diff --git a/scipost_django/organizations/tests/__init__.py b/scipost_django/organizations/tests/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/scipost_django/organizations/tests/test_factories.py b/scipost_django/organizations/tests/test_factories.py index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..ecb19309d484399ea23ad0197afe77a7cc4ac81a 100644 --- a/scipost_django/organizations/tests/test_factories.py +++ b/scipost_django/organizations/tests/test_factories.py @@ -0,0 +1,49 @@ +__copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)" +__license__ = "AGPL v3" + +from django.test import TestCase + +from organizations.factories import ( + OrganizationLogoFactory, + OrganizationFactory, + OrganizationEventFactory, + ContactFactory, + ContactRoleFactory, + ContactPersonFactory, +) + + +class TestOrganizationLogoFactory(TestCase): + def test_can_create_organization_logos(self): + organization_logo = OrganizationLogoFactory() + self.assertIsNotNone(organization_logo) + + +class TestOrganizationFactory(TestCase): + def test_can_create_organizations(self): + organization = OrganizationFactory() + self.assertIsNotNone(organization) + + +class TestOrganizationEventFactory(TestCase): + def test_can_create_organization_events(self): + organization_event = OrganizationEventFactory() + self.assertIsNotNone(organization_event) + + +class TestContactFactory(TestCase): + def test_can_create_contacts(self): + contact = ContactFactory() + self.assertIsNotNone(contact) + + +class TestContactPersonFactory(TestCase): + def test_can_create_contact_persons(self): + contact_person = ContactPersonFactory() + self.assertIsNotNone(contact_person) + + +class TestContactRoleFactory(TestCase): + def test_can_create_contact_roles(self): + contact_role = ContactRoleFactory() + self.assertIsNotNone(contact_role)