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

Querying specific columns #244

Open
aponbas opened this issue Jul 7, 2022 · 0 comments
Open

Querying specific columns #244

aponbas opened this issue Jul 7, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@aponbas
Copy link

aponbas commented Jul 7, 2022

Hi all,

When trying to query specific columns, mock-alchemy seems to return nothing at all.
I wrote this standalone script so you can see what I mean:

import uuid

from mock_alchemy.mocking import UnifiedAlchemyMagicMock
from sqlalchemy import Column, String, Integer
from sqlalchemy.orm import declarative_base

Base = declarative_base()


class Brand(Base):
    __tablename__ = "brand_table"

    id: str = Column("id", String, primary_key=True)
    brand_name: str = Column("brand_name", String)
    brand_id: int = Column("brand_id", Integer)


def test_read_brand_id():
    data = Brand(id=uuid.uuid4(),
                 brand_name="Github",
                 brand_id=1)

    session = UnifiedAlchemyMagicMock()
    session.add(data)

    without_specific_columns = session.query(Brand).all()

    print(f"Object without specific columns: {without_specific_columns}\n"
          f"Data: {without_specific_columns[0].__dict__}\n")

    with_specific_columns = session.query(Brand.brand_name).all()

    print(f"Object with specific columns: {with_specific_columns}")


if __name__ == "__main__":
    test_read_brand_id()

The output will be:
Screenshot 2022-07-07 at 11 38 50
Am I missing something or is mock-alchemy not set up for this?
Thanks in advance!

@aponbas aponbas added the bug Something isn't working label Jul 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant