Skip to content

Commit

Permalink
test(sqla_factory): refactored some tests after adding an async conte…
Browse files Browse the repository at this point in the history
…xt manager
  • Loading branch information
nisemenov authored and adhtruong committed Jan 15, 2025
1 parent 6b0d6f3 commit ff81dc1
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions tests/sqlalchemy_factory/test_sqlalchemy_factory_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
func,
inspect,
orm,
select,
text,
types,
)
Expand Down Expand Up @@ -343,13 +344,15 @@ class Factory(SQLAlchemyFactory[AsyncModel]):
__async_session__ = session_config(session)
__model__ = AsyncModel

result = await Factory.create_async()
assert inspect(result).persistent # type: ignore[union-attr]
instance = await Factory.create_async()
result = await session.scalar(select(AsyncModel).where(AsyncModel.id == instance.id))
assert result

batch_result = await Factory.create_batch_async(size=2)
assert len(batch_result) == 2
for batch_item in batch_result:
assert inspect(batch_item).persistent # type: ignore[union-attr]
result = await session.scalar(select(AsyncModel).where(AsyncModel.id == batch_item.id))
assert result


@pytest.mark.parametrize(
Expand Down Expand Up @@ -392,8 +395,9 @@ class Factory(SQLAlchemyFactory[AsyncRefreshModel]):
test_int = Ignore()
test_bool = Ignore()

result = await Factory.create_async()
assert inspect(result).persistent # type: ignore[union-attr]
instance = await Factory.create_async()
result = await session.scalar(select(AsyncRefreshModel).where(AsyncRefreshModel.id == instance.id))
assert result
assert result.test_datetime is not None
assert isinstance(result.test_datetime, datetime)
assert result.test_str == "test_str"
Expand Down

0 comments on commit ff81dc1

Please sign in to comment.