jeudi 4 juin 2015

UnitTesting SQLAlchemy Query issues - BooleanClauseList

I have the following SQLAlchemy query:

query = session.query(
    Template
).outerjoin(
    (
        GlobalTemplate,
        Template.id == GlobalTemplate.template_id
    )
)

if account_id == 0:
    q_filter = [
        Template.account_id == parent_account_id,
        GlobalTemplate.account_id == 0,
        GlobalTemplate.account_id == parent_account_id
    ]
else:
    q_filter = [
        Template.account_id == account_id,
        GlobalTemplate.account_id == 0,
        GlobalTemplate.account_id == account_id
    ]

query = query.filter(or_(*q_filter))

My unit test looks like this:

@patch('myapp.apps.campaigns.utilities.Session')
@patch('myapp.apps.campaigns.utilities.Template')
@patch('myapp.apps.campaigns.utilities.GlobalTemplate')
def test_templates_query(self, GlobalTemplate, Template, Session):
    utilities.templates_query(100, 0)

    self.assertListEqual(
        Session.mock_calls,
        [
            call(),
            call().query(Template),
            call().query().outerjoin((GlobalTemplate, False)),
            call().query().outerjoin().filter((True,))
        ]
    )

My test is failing on the last mock.call(). It looks like call().query().outerjoin().filter(<sqlalchemy.sql.expression.BooleanClauseList object at 0x4356d10>), but I've never seen that before. Anyone else run into this issue?

Aucun commentaire:

Enregistrer un commentaire