Skip to content

Commit

Permalink
Rebased and adresses simple comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nadege committed Jan 13, 2024
1 parent 705b6ff commit 5f2582d
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion docs/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ All factories support two built-in strategies:

* ``build`` provides a local object
* ``create`` instantiates a local object, and saves it to the database.
* ``create async`` similar to ``create`` but can run asynchronous code.
* ``create_async`` similar to ``create`` but can run asynchronous code.

.. note:: For 1.X versions, the ``create`` will actually call ``AssociatedClass.objects.create``,
as for a Django model.
Expand Down
18 changes: 9 additions & 9 deletions docs/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ Attributes and methods

.. classmethod:: build_batch(cls, size, **kwargs)

Provides a list of :obj:`size` instances from the :class:`Factory`,
Provides a list of ``size`` instances from the :class:`Factory`,
through the 'build' strategy.


Expand All @@ -213,18 +213,18 @@ Attributes and methods

.. classmethod:: create_batch(cls, size, **kwargs)

Provides a list of :obj:`size` instances from the :class:`Factory`,
Provides a list of ``size`` instances from the :class:`Factory`,
through the 'create' strategy.


.. classmethod:: create_async(cls, **kwargs)

Provides a new object, using the `create_async` strategy.
Provides a new object, using the ``create_async`` strategy.

.. classmethod:: create_async_batch(cls, size, **kwargs)

Provides a list of :obj:`size` instances from the :class:`Factory`,
through the `create_async` strategy.
Asynchronously provides a list of ``size`` instances from the :class:`Factory`,
through the ``create_async`` strategy.


.. classmethod:: stub(cls, **kwargs)
Expand Down Expand Up @@ -415,7 +415,7 @@ Attributes and methods

.. class:: AsyncFactory

Similar to the :class:`Factory` class but with `create_async` as default strategy.
Similar to the :class:`Factory` class but with ``create_async`` as default strategy.


.. _parameters:
Expand Down Expand Up @@ -629,13 +629,13 @@ factory_boy supports two main strategies for generating instances, plus stubs.
:class:`Factory` wasn't overridden.


.. data:: CREATE_ASYNC_STRATEGY
.. data:: ASYNC_CREATE_STRATEGY

The `create_async` strategy is similar to the `create` strategy but asynchronous.
The ``create_async`` strategy is similar to the ``create`` strategy but asynchronous.

This is the default strategy for subclasses of :class:`AsyncFactory`.

Default behavior is to call :meth:`~Factory._create`, this can be overridden in :meth:`_create_model_async`.
Default behavior is to call :meth:`~Factory._create`, this can be overridden in :meth:`Factory._create_model_async`.

.. function:: use_strategy(strategy)

Expand Down
2 changes: 1 addition & 1 deletion factory/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def instantiate(self, step, args, kwargs):
def use_postgeneration_results(self, step, instance, results):
self.factory._after_postgeneration(
instance,
create=step.builder.strategy != enums.BUILD_STRATEGY,
create=step.builder.strategy in (enums.CREATE_STRATEGY, enums.ASYNC_CREATE_STRATEGY),
results=results,
)

Expand Down
2 changes: 1 addition & 1 deletion factory/declarations.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ def call(self, instance, step, context):
context._asdict(),
),
)
create = step.builder.strategy != enums.BUILD_STRATEGY
create = step.builder.strategy in (enums.CREATE_STRATEGY, enums.ASYNC_CREATE_STRATEGY)

return self.function(
instance, create, context.value, **context.extra)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_alchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ async def test():

statement = sqlalchemy.select(
sqlalchemy.func.count(models.NoteModel.id)
).where(models.NoteModel.text == "Text 0")
)
count = await models.async_session.scalar(statement)
assert count == 1
self.assertEqual(count, 1)

asyncio.run(test())
6 changes: 3 additions & 3 deletions tests/test_using.py
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ class Meta:
async def test():
test_model = await TestModelFactory.create_async()
self.assertEqual(test_model.one, 'one')
self.assertTrue(create_marker, test_model.id)
self.assertEqual(create_marker, test_model.id)

asyncio.run(test())

Expand All @@ -866,7 +866,7 @@ async def test():
for i, obj in enumerate(objs):
self.assertEqual('one', obj.one)
self.assertEqual(i, obj.two)
self.assertTrue(obj.id)
self.assertEqual(obj.id, create_marker)
asyncio.run(test())

def test_generate_build(self):
Expand Down Expand Up @@ -966,7 +966,7 @@ async def test():
for i, obj in enumerate(objs):
self.assertEqual('one', obj.one)
self.assertEqual('two', obj.two)
self.assertTrue(obj.id)
self.assertEqual(obj.id, create_marker)

asyncio.run(test())

Expand Down

0 comments on commit 5f2582d

Please sign in to comment.