fairdm.factories.contributors#

Factories for the contributors app’s models.

These factory_boy factories create test instances of the contributors app’s models: the account (UserFactory), the two concrete contributor types (PersonFactory, OrganizationFactory) and the generic base (ContributorFactory), an organisation membership (AffiliationFactory), and a credit linking a contributor to a research object (ContributionFactory). Layout matches fairdm.factories.core: one class per model, defaults that satisfy full_clean() with no further arguments, and every factory re-exported from fairdm.factories.

Module Contents#

Classes#

UserFactory

Factory for creating Django User instances.

ContributorFactory

Factory for the fields common to every concrete contributor type.

PersonFactory

Factory for creating Person instances.

OrganizationFactory

Factory for creating Organization instances.

ContributorIdentifierFactory

Factory for creating ContributorIdentifier instances.

AffiliationFactory

Factory for creating Affiliation instances.

ContributionFactory

Factory for creating Contribution instances.

Data#

API#

User#

‘get_user_model(…)’

class UserFactory#

Bases: factory.django.DjangoModelFactory

Factory for creating Django User instances.

Note: Person model uses email as USERNAME_FIELD, not username. The username field is set to str property in Person model.

class Meta#
model#

None

email#

‘Sequence(…)’

first_name#

‘Test’

last_name#

‘User’

is_active#

True

is_staff#

False

is_superuser#

False

password(create, extracted, **kwargs)#

Set password after user creation.

class ContributorFactory#

Bases: factory.django.DjangoModelFactory

Factory for the fields common to every concrete contributor type.

PersonFactory and OrganizationFactory build on this rather than duplicating these declarations; the preferred name is a sequence, not a random Faker value, so that ordering by name is stable across a test run.

Image is opt-in (issue #323): omitted writes no file, with_image=True generates a placeholder, image=<file> uses that file directly.

class Meta#
model#

None

class Params#
with_image#

‘Trait(…)’

name#

‘Sequence(…)’

profile#

‘Faker(…)’

class PersonFactory#

Bases: fairdm.factories.contributors.ContributorFactory

Factory for creating Person instances.

Defaults to an unclaimed instance with an unusable password - a contributor added for attribution alone is the common case (Article I, issue #227). Pass password=... for a claimed-looking instance, or set is_claimed/is_active explicitly.

The email is a sequence, so every call builds a new person, whatever the names. Pass an email that is already in use to get that person back.

class Meta#
model#

None

django_get_or_create#

[‘email’]

email#

‘Sequence(…)’

first_name#

‘Faker(…)’

last_name#

‘Faker(…)’

is_active#

True

password(create, extracted, **kwargs)#

Set the given password, or leave the instance with an unusable one.

class OrganizationFactory#

Bases: fairdm.factories.contributors.ContributorFactory

Factory for creating Organization instances.

class Meta#
model#

None

class ContributorIdentifierFactory#

Bases: fairdm.factories.utils.ConceptFieldFactory

Factory for creating ContributorIdentifier instances.

AbstractIdentifier.value carries a database-level uniqueness constraint across every identifier-bearing record, not just other ContributorIdentifiers, so it is a sequence rather than a fixed or random value (Article I).

related has no default: pass ContributorIdentifierFactory(related=person).

class Meta#
model#

None

type#

None

value#

‘Sequence(…)’

class AffiliationFactory#

Bases: factory.django.DjangoModelFactory

Factory for creating Affiliation instances.

Defaults to a current, plain member membership: a start date is set and no end date, and the type is the plain member level rather than pending, admin or owner.

class Meta#
model#

None

person#

‘SubFactory(…)’

organization#

‘SubFactory(…)’

type#

None

start_date#

‘2020’

class ContributionFactory#

Bases: factory.django.DjangoModelFactory

Factory for creating Contribution instances.

The content_object can optionally be provided when creating a Contribution. If not provided, a default Project will be created.

Attributes: contributor: The contributor credited, a new Person by default.

Example: contribution = ContributionFactory() # Creates with default Project contribution = ContributionFactory(content_object=my_dataset) # Custom object

class Meta#
model#

None

exclude#

[‘content_object’]

contributor#

‘SubFactory(…)’

content_object()#

Create a default Project as the credited object.

content_type()#

Use the content type of content_object.

object_id()#

Use the id of content_object.