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

UnifiedAlchemyMagicMock does not work with .label() #24

Closed
hozher opened this issue Sep 23, 2019 · 8 comments
Closed

UnifiedAlchemyMagicMock does not work with .label() #24

hozher opened this issue Sep 23, 2019 · 8 comments
Labels
enhancement New feature or request

Comments

@hozher
Copy link

hozher commented Sep 23, 2019

Hello,

I have this query in my function to be tested:

query = session.query(
            whitelist.whitelistEmailId,
            whitelist.areaId,
            whitelist.businessNameId,
            whitelist.email,
            whitelist.identificationNumber,
            whitelist.isRegistered,
            whitelist.serviceTypeId,
            area.name.label('area'),
            business.name.label('businessName'),
            service.name.label('serviceType')
            ).\
        join(area, whitelist.areaId == area.areaId).\
        join(business, whitelist.businessNameId == business.businessNameId).\
        join(service, whitelist.serviceTypeId == service.serviceTypeId)

I am trying to mock it out like this:

return UnifiedAlchemyMagicMock(data=[
        (
            [mock.call.query(
                WhitelistedEmail.whitelistEmailId,
                WhitelistedEmail.areaId,
                WhitelistedEmail.businessNameId,
                WhitelistedEmail.email,
                WhitelistedEmail.identificationNumber,
                WhitelistedEmail.isRegistered,
                WhitelistedEmail.serviceTypeId,
                Area.name.label('area'),
                BusinessName.name.label('businessName'),
                ServiceType.name.label('serviceType')
            )], Factory.get_list()
        )
    ])

After Ive added these three guys, that make use of .label() does not work anymore.

    Area.name.label('area'),
    BusinessName.name.label('businessName'),
    ServiceType.name.label('serviceType')

Is this a known issue? or might be am I doing something wrong. any clue is more than welcome.

@miki725
Copy link
Owner

miki725 commented Sep 23, 2019

dont think tested with labels. could be the comparison logic does not correctly compare labels. Can you try using

class ExpressionMatcher(PrettyExpression):
to manually compare labels?
so something like:

ExpressionMatcher(Area.name.label('area')) == Area.name.label('area')

@hozher
Copy link
Author

hozher commented Sep 23, 2019

@miki725 Thanks for answering.

The problem is that when query gets called is not returning any value (not getting mocked) I did the ExpressionMatcher whiteout success as follows:

return UnifiedAlchemyMagicMock(data=[
        (
            [mock.call.query(
                WhitelistedEmail.whitelistEmailId,
                WhitelistedEmail.areaId,
                WhitelistedEmail.businessNameId,
                WhitelistedEmail.email,
                WhitelistedEmail.identificationNumber,
                WhitelistedEmail.isRegistered,
                WhitelistedEmail.serviceTypeId,
                ExpressionMatcher(Area.name.label('area')) == Area.name.label('area'),
                ExpressionMatcher(BusinessName.name.label('businessName')) == BusinessName.name.label('businessName'),
                ExpressionMatcher(ServiceType.name.label('serviceType')) == ServiceType.name.label('serviceType'),
            )], Factory.get_list()
        )
    ])

@miki725
Copy link
Owner

miki725 commented Sep 23, 2019

I meant can you post results running ExpressionMatcher by itself. I dont know if its capable of comparing label objects

@hozher
Copy link
Author

hozher commented Sep 23, 2019

alright, i got this:

 print(ExpressionMatcher(Area.name.label('area')) == Area.name.label('area'))
    print(ExpressionMatcher(BusinessName.name.label('businessName')) == BusinessName.name.label('businessName'))
    print(ExpressionMatcher(ServiceType.name.label('serviceType')) == ServiceType.name.label('serviceType'))
"Area".name = "Area".name
"BusinessName".name = "BusinessName".name
"ServiceType".name = "ServiceType".name

@miki725
Copy link
Owner

miki725 commented Sep 24, 2019

yep thats not supported. should of gotten a boolean if it was. Ill try to add support at some point or feel free to submit a PR!

@miki725 miki725 added the enhancement New feature or request label Sep 24, 2019
@miki725
Copy link
Owner

miki725 commented Sep 25, 2019

#25 adds labels support. can you test that branch?

@hozher
Copy link
Author

hozher commented Sep 25, 2019

It works pretty well 😃

>>> from alchemy_mock.comparison import ExpressionMatcher
>>> from model import Area
>>> ExpressionMatcher(Area.name.label('area')) == Area.name.label('area')
True

Thanks a lot! merge, might be?

@miki725
Copy link
Owner

miki725 commented Sep 25, 2019

just released 0.4.2. should be able to install from pypi. let me know if any further issues

@miki725 miki725 closed this as completed Sep 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants