Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadège Michel committed Jan 15, 2021
1 parent 0ee6557 commit 9d94c4f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
6 changes: 3 additions & 3 deletions factory/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,8 @@ def _create_async(cls, model_class, *args, **kwargs):

async def maker_coroutine():
for key, value in kwargs.items():
# when using SubFactory, you'll have a Task in the corresponding kwarg
# await tasks to pass model instances instead, not the Task
# When using SubFactory, you'll have a Task in the corresponding kwarg
# Await tasks to pass model instances instead, not the Task
if inspect.isawaitable(value):
kwargs[key] = await value

Expand Down Expand Up @@ -579,7 +579,7 @@ def create_batch(cls, size, **kwargs):
@classmethod
def create_async(cls, **kwargs):
"""Create a Task that will return an instance of the associated class,
with overridden attrs, when awaited."""
with overridden attrs, when awaited."""
return cls._generate(enums.ASYNC_CREATE_STRATEGY, kwargs)

@classmethod
Expand Down
6 changes: 3 additions & 3 deletions factory/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ def create_batch(klass, size, **kwargs):
return make_factory(klass, **kwargs).create_batch(size)


def create_async(klass, **kwargs):
"""Create a factory for the given class, and create a Task that can create an instance."""
return make_factory(klass, **kwargs).create_async()
async def create_async(klass, **kwargs):
"""Create a factory for the given class, and create a Task to create an instance."""
return await make_factory(klass, **kwargs).create_async()


async def create_async_batch(klass, size, **kwargs):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,10 @@ async def _create_model_async(cls, model_class, *args, **kwargs):
loop = asyncio.get_event_loop()
test_model = loop.run_until_complete(TestModelFactory())
self.assertEqual(test_model.one, 'one')
self.assertTrue(test_model.id)
self.assertEqual(test_model.id, 1)

def test_async_create_strategy_default(self):
# Async create is default strategy for AsyncFactory
# ASYNC_CREATE_STRATEGY is default strategy for AsyncFactory

class TestModelAsyncFactory(base.AsyncFactory):
class Meta:
Expand Down
4 changes: 3 additions & 1 deletion tests/test_using.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,11 @@ def test_create_batch_custom_base(self):
self.assertEqual(obj.id, 2)
self.assertEqual(obj.foo, 'bar')

def test_create_async(self):
def test_create_async_default_base(self):
# By default Factory class is used to create the factory
loop = asyncio.get_event_loop()
obj = loop.run_until_complete(factory.create_async(FakeAsyncModel, foo='bar'))
# FakeAsyncModel.create was not called
self.assertEqual(obj.id, None)
self.assertEqual(obj.foo, 'bar')

Expand Down

0 comments on commit 9d94c4f

Please sign in to comment.