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#
Factory for creating Django User instances. |
|
Factory for the fields common to every concrete contributor type. |
|
Factory for creating Person instances. |
|
Factory for creating Organization instances. |
|
Factory for creating ContributorIdentifier instances. |
|
Factory for creating Affiliation instances. |
|
Factory for creating Contribution instances. |
Data#
API#
- User#
‘get_user_model(…)’
- class UserFactory#
Bases:
factory.django.DjangoModelFactoryFactory 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.
- 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.DjangoModelFactoryFactory 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=Truegenerates a placeholder,image=<file>uses that file directly.- name#
‘Sequence(…)’
- profile#
‘Faker(…)’
- class PersonFactory#
Bases:
fairdm.factories.contributors.ContributorFactoryFactory 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 setis_claimed/is_activeexplicitly.The email is a sequence, so every call builds a new person, whatever the names. Pass an
emailthat is already in use to get that person back.- 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.ContributorFactoryFactory for creating Organization instances.
- class ContributorIdentifierFactory#
Bases:
fairdm.factories.utils.ConceptFieldFactoryFactory for creating ContributorIdentifier instances.
AbstractIdentifier.valuecarries 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).relatedhas no default: passContributorIdentifierFactory(related=person).- type#
None
- value#
‘Sequence(…)’
- class AffiliationFactory#
Bases:
factory.django.DjangoModelFactoryFactory 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.
- person#
‘SubFactory(…)’
- organization#
‘SubFactory(…)’
- type#
None
- start_date#
‘2020’
- class ContributionFactory#
Bases:
factory.django.DjangoModelFactoryFactory 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
- 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.