SciPost Code Repository

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

add factories for all organization models

parent d0a6be98
No related branches found
No related tags found
No related merge requests found
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")
__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)
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