Update docs

This commit is contained in:
Roman Mogylatov 2021-08-25 09:47:50 -04:00
parent c15fc27f00
commit 2c8ac22c03

View File

@ -148,13 +148,11 @@ provider with two peculiarities:
Factory aggregate Factory aggregate
----------------- -----------------
:py:class:`FactoryAggregate` provider aggregates multiple factories. When you call the :py:class:`FactoryAggregate` provider aggregates multiple factories.
``FactoryAggregate`` it delegates the call to one of the factories.
The aggregated factories are associated with the string names. When you call the The aggregated factories are associated with the string keys. When you call the
``FactoryAggregate`` you have to provide one of the these names as a first argument. ``FactoryAggregate`` you have to provide one of the these keys as a first argument.
``FactoryAggregate`` looks for the factory with a matching name and delegates it the work. The ``FactoryAggregate`` looks for the factory with a matching key and calls it with the rest of the arguments.
rest of the arguments are passed to the delegated ``Factory``.
.. image:: images/factory_aggregate.png .. image:: images/factory_aggregate.png
:width: 100% :width: 100%
@ -165,12 +163,12 @@ rest of the arguments are passed to the delegated ``Factory``.
:lines: 3- :lines: 3-
:emphasize-lines: 33-37,47 :emphasize-lines: 33-37,47
You can get a dictionary of the aggregated factories using the ``.factories`` attribute of the You can get a dictionary of the aggregated factories using the ``.factories`` attribute.
``FactoryAggregate``. To get a game factories dictionary from the previous example you can use To get a game factories dictionary from the previous example you can use
``game_factory.factories`` attribute. ``game_factory.factories`` attribute.
You can also access an aggregated factory as an attribute. To create the ``Chess`` object from the You can also access an aggregated factory as an attribute. To create the ``Chess`` object from the
previous example you can do ``chess = game_factory.chess('John', 'Jane')``. previous example you can do ``chess = game_factory.chess("John", "Jane")``.
.. note:: .. note::
You can not override the ``FactoryAggregate`` provider. You can not override the ``FactoryAggregate`` provider.
@ -178,4 +176,22 @@ previous example you can do ``chess = game_factory.chess('John', 'Jane')``.
.. note:: .. note::
When you inject the ``FactoryAggregate`` provider it is passed "as is". When you inject the ``FactoryAggregate`` provider it is passed "as is".
To use non-string keys or keys with ``.`` and ``-`` you can provide a dictionary as a positional argument:
.. code-block:: python
providers.FactoryAggregate({
SomeClass: providers.Factory(...),
"key.with.periods": providers.Factory(...),
"key-with-dashes": providers.Factory(...),
})
Example:
.. literalinclude:: ../../examples/providers/factory_aggregate_non_string_keys.py
:language: python
:lines: 3-
:emphasize-lines: 30-33,39-40
.. disqus:: .. disqus::