Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#Issue filter_by does not affect the output of the query #41

Open
tweigel-dev opened this issue Aug 10, 2021 · 1 comment
Open

#Issue filter_by does not affect the output of the query #41

tweigel-dev opened this issue Aug 10, 2021 · 1 comment

Comments

@tweigel-dev
Copy link

Hay,
I found a bug.
The filter_by does not affect the output of the query. It is no issue if not using the mock. sqlalchemy/sqlalchemy#6873

from sqlalchemy.orm import registry, Session
from sqlalchemy import Column, Integer
Base = registry().generate_base()
class Hardware(Base):
    """
    parent Hardwaretable
    """
    __tablename__   = 'hardware'
    hardware_id     = Column(Integer, primary_key=True)
session = UnifiedAlchemyMagicMock()
session.add(Hardware(hardware_id=0))
session.add(Hardware(hardware_id=1))
session.add(Hardware(hardware_id=2))
hardware = session.query(Hardware).filter_by(hardware_id=1).all()
print(hardware)

prints all 3 hardware objects and behaves like

hardware = session.query(Hardware).all()
@miki725
Copy link
Owner

miki725 commented Aug 10, 2021

the library does not actually filter anything. as mentioned in the readme it does very limited logic to mimick actual database. it only does that for .get() which gets the model instance by its PK. for filter you would have to stub the data:

>>> session = UnifiedAlchemyMagicMock(data=[
...     (
...         [mock.call.query(Model),
...          mock.call.filter_by(foo='bar')],
...         [Model(foo=5, bar=11)]
...     ),
... ])
>>> session.query(Model).filter_by(foo='bar').all()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants