mock-alchemy
mock-alchemy copied to clipboard
Support for unified Core+ORM SQLAlchemy query style
Is your feature request related to a problem? Please describe.
With SQLAlchemy 1.4, but Core-style and ORM-style queries can be run the same way:
class MyModel(Base):
__tablename__ = "model"
id = Column(Integer, primary_key=True, index=True)
name = Column(String, nullable=False)
statement = select(MyModel)
result = session.execute(statement)
all_rows = result.all;()
Details in SQLAlchemy documentation
Describe the solution you'd like
statement = select(MyModel)
session = UnifiedAlchemyMagicMock(
data=[
(
[
mock.call.execute(statement),
],
[
MyModel(id=1234, name="foo"),
]
)
]
)
result = session.execute(stmt)
found = result.one_or_none()
assert found.name == "foo"
Describe alternatives you've considered
In the meantime, I'll be using a normal mock with return values.
Is there any chance of this (or something like it) happening?
With the session.execute(statement)
being the preferred ORM method going forward with SQLAlchemy 2.0 and session.query()
being marked as legacy it would be nice to convert queries over during SQLAlchemy 2.0 migration, however I am guessing that I won't be able to do this and continue using mock-alchemy unless this issue is addressed?