fairdm.factories.utils#

Faker provider and helpers used by the FairDM factories.

Module Contents#

Classes#

FairDMProvider

Faker provider with generators for FairDM’s geographic, text and date fields.

ConceptFieldFactory

A factory whose concept fields take the address of a concept as well as the concept.

Functions#

randint

Return a callable that yields a random integer in a range.

Data#

API#

logger#

‘getLogger(…)’

randint(min_value, max_value)#

Return a callable that yields a random integer in a range.

Args: min_value: The lowest value the callable can return. max_value: The highest value the callable can return.

Returns: A zero-argument callable returning an integer from min_value to max_value inclusive.

class FairDMProvider(generator: Any)#

Bases: faker.providers.BaseProvider

Faker provider with generators for FairDM’s geographic, text and date fields.

Initialization

Base class for fake data providers :param generator: Generator instance

geo_point(**kwargs)#

Generate a random point as a WKT string.

Args: **kwargs: Passed to Faker.latlng.

Returns: A string of the form POINT(<latitude> <longitude>).

html_paragraphs(nb=5, **kwargs)#

Generate paragraphs of text wrapped in <p> tags.

Args: nb: The number of paragraphs, or a callable returning it. **kwargs: Passed to Faker.paragraph.

Returns: The paragraphs as one HTML string.

multiline_text(nb=5, **kwargs)#

Generate paragraphs of plain text separated by blank lines.

Args: nb: The number of paragraphs, or a callable returning it. **kwargs: Passed to Faker.paragraph.

Returns: The paragraphs as one string.

partial_date(**kwargs)#

Generate a date at a random precision.

Args: **kwargs: Passed to Faker.date_object.

Returns: The date formatted as a year, a year and month, or a full date.

random_instance(model=None, queryset=None)#

Pick a random existing record.

Args: model: The model to pick from. All its records are candidates. queryset: The records to pick from. Takes precedence over model.

Returns: A random instance, or None when there are no records.

Raises: ValueError: Neither model nor queryset is given.

class ConceptFieldFactory#

Bases: factory.django.DjangoModelFactory

A factory whose concept fields take the address of a concept as well as the concept.

A concept field holds a concept’s address in its column, but assigning the address itself to the field is refused, so an address given for one is stored through the field’s column.

class Meta#
abstract#

True