beanie_odm_factory#

class polyfactory.factories.beanie_odm_factory.BeaniePersistenceHandler#

Bases: Generic[T], AsyncPersistenceProtocol[T]

Persistence Handler using beanie logic

async save(data: T) T#

Persist a single instance in mongoDB.

async save_many(data: list[T]) list[T]#

Persist multiple instances in mongoDB.

Note

we cannot use the .insert_many method from Beanie here because it doesn’t return the created instances

class polyfactory.factories.beanie_odm_factory.BeanieDocumentFactory#

Bases: Generic[T], ModelFactory[T]

Base factory for Beanie Documents

__async_persistence__#

alias of BeaniePersistenceHandler

__is_base_factory__: bool = True#

Flag dictating whether the factory is a ‘base’ factory. Base factories are registered globally as handlers for types. For example, the ‘DataclassFactory’, ‘TypedDictFactory’ and ‘ModelFactory’ are all base factories.

classmethod is_supported_type(value: Any) TypeGuard[type[T]]#

Determine whether the given value is supported by the factory.

Parameters:

value – An arbitrary value.

Returns:

A typeguard

classmethod get_field_value(field_meta: FieldMeta, field_build_parameters: Any | None = None, build_context: BuildContext | None = None) Any#

Return a field value on the subclass if existing, otherwise returns a mock value.

Parameters:
  • field_meta – FieldMeta instance.

  • field_build_parameters – Any build parameters passed to the factory as kwarg values.

Returns:

An arbitrary value.