Factory-boy

Latest version: v3.3.0

Safety actively analyzes 630094 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 4 of 8

2.6.0

------------------

*New:*

- Add :attr:`factory.FactoryOptions.rename` to help handle conflicting names (:issue:`206`)
- Add support for random-yet-realistic values through `fake-factory <https://pypi.org/project/fake-factory/>`_,
through the :class:`factory.Faker` class.
- :class:`factory.Iterator` no longer begins iteration of its argument at import time,
thus allowing to pass in a lazy iterator such as a Django queryset
(i.e ``factory.Iterator(models.MyThingy.objects.all())``).
- Simplify imports for ORM layers, now available through a simple ``factory`` import,
at ``factory.alchemy.SQLAlchemyModelFactory`` / ``factory.django.DjangoModelFactory`` / ``factory.mongoengine.MongoEngineFactory``.

*Bug fix:*

- :issue:`201`: Properly handle custom Django managers when dealing with abstract Django models.
- :issue:`212`: Fix :meth:`factory.django.mute_signals` to handle Django's signal caching
- :issue:`228`: Don't load :func:`django.apps.apps.get_model()` until required
- :pr:`219`: Stop using :meth:`mogo.model.Model.new()`, deprecated 4 years ago.

2.5.2

------------------

*Bug fix:*

- Add support for Django 1.7/1.8
- Add support for mongoengine>=0.9.0 / pymongo>=2.1

2.5.1

------------------

*Bug fix:*

- Respect custom managers in :class:`~factory.django.DjangoModelFactory` (see :issue:`192`)
- Allow passing declarations (e.g :class:`~factory.Sequence`) as parameters to :class:`~factory.django.FileField`
and :class:`~factory.django.ImageField`.

2.5.0

------------------

*New:*

- Add support for getting/setting :mod:`factory.fuzzy`'s random state (see :issue:`175`, :issue:`185`).
- Support lazy evaluation of iterables in :class:`factory.fuzzy.FuzzyChoice` (see :issue:`184`).
- Support non-default databases at the factory level (see :issue:`171`)
- Make :class:`factory.django.FileField` and :class:`factory.django.ImageField` non-post_generation, i.e normal fields also available in ``save()`` (see :issue:`141`).

*Bug fix:*

- Avoid issues when using :meth:`factory.django.mute_signals` on a base factory class (see :issue:`183`).
- Fix limitations of :class:`factory.StubFactory`, that can now use :class:`factory.SubFactory` and co (see :issue:`131`).


*Deprecation:*

- Remove deprecated features from :ref:`v2.4.0`
- Remove the auto-magical sequence setup (based on the latest primary key value in the database) for Django and SQLAlchemy;
this relates to issues :issue:`170`, :issue:`153`, :issue:`111`, :issue:`103`, :issue:`92`, :issue:`78`. See https://github.com/FactoryBoy/factory_boy/commit/13d310f for technical details.

.. warning:: Version 2.5.0 removes the 'auto-magical sequence setup' bug-and-feature.
This could trigger some bugs when tests expected a non-zero sequence reference.

Upgrading
"""""""""

.. warning:: Version 2.5.0 removes features that were marked as deprecated in :ref:`v2.4.0 <v2.4.0>`.

All ``FACTORY_*``-style attributes are now declared in a ``class Meta:`` section:

.. code-block:: python

Old-style, deprecated
class MyFactory(factory.Factory):
FACTORY_FOR = models.MyModel
FACTORY_HIDDEN_ARGS = ['a', 'b', 'c']

New-style
class MyFactory(factory.Factory):
class Meta:
model = models.MyModel
exclude = ['a', 'b', 'c']

A simple shell command to upgrade the code would be:

.. code-block:: sh

sed -i: inplace update
grep -l: only file names, not matching lines
sed -i 's/FACTORY_FOR =/class Meta:\n model =/' $(grep -l FACTORY_FOR $(find . -name '*.py'))

This takes care of all ``FACTORY_FOR`` occurrences; the files containing other attributes to rename can be found with ``grep -R FACTORY .``

2.4.1

------------------

*Bug fix:*

- Fix overriding deeply inherited attributes (set in one factory, overridden in a subclass, used in a sub-sub-class).

2.4.0

------------------

*New:*

- Add support for :attr:`factory.fuzzy.FuzzyInteger.step`, thanks to `ilya-pirogov <https://github.com/ilya-pirogov>`_ (:pr:`120`)
- Add :meth:`~factory.django.mute_signals` decorator to temporarily disable some signals, thanks to `ilya-pirogov <https://github.com/ilya-pirogov>`_ (:pr:`122`)
- Add :class:`~factory.fuzzy.FuzzyFloat` (:issue:`124`)
- Declare target model and other non-declaration fields in a ``class Meta`` section.

*Deprecation:*

- Use of ``FACTORY_FOR`` and other ``FACTORY`` class-level attributes is deprecated and will be removed in 2.5.
Those attributes should now declared within the :class:`class Meta <factory.FactoryOptions>` attribute:

For :class:`factory.Factory`:

* Rename :attr:`~factory.Factory.FACTORY_FOR` to :attr:`~factory.FactoryOptions.model`
* Rename :attr:`~factory.Factory.ABSTRACT_FACTORY` to :attr:`~factory.FactoryOptions.abstract`
* Rename :attr:`~factory.Factory.FACTORY_STRATEGY` to :attr:`~factory.FactoryOptions.strategy`
* Rename :attr:`~factory.Factory.FACTORY_ARG_PARAMETERS` to :attr:`~factory.FactoryOptions.inline_args`
* Rename :attr:`~factory.Factory.FACTORY_HIDDEN_ARGS` to :attr:`~factory.FactoryOptions.exclude`

For :class:`factory.django.DjangoModelFactory`:

* Rename :attr:`~factory.django.DjangoModelFactory.FACTORY_DJANGO_GET_OR_CREATE` to :attr:`~factory.django.DjangoOptions.django_get_or_create`

For :class:`factory.alchemy.SQLAlchemyModelFactory`:

* Rename :attr:`~factory.alchemy.SQLAlchemyModelFactory.FACTORY_SESSION` to :attr:`~factory.alchemy.SQLAlchemyOptions.sqlalchemy_session`

Page 4 of 8

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.