You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It appears that mocking always returns an empty list with the session.execute(text(<sql>), params).mappings().all() call.
I have a multi-step mock where I am, in a large transaction, performing multiple lookups.
One of these example lookups is below, the one that doesn't work.
defget_pending_requests(credential_type_said, holder_id, issuer_id, session):
sql_query=pending_requests_query(latest_cred_req_state_subquery) # returns a valid SQL queryterminal_states=get_terminal_states() # tuple of stringscompleted_states_str=tuple(terminal_states) # Convert list to tuple for the SQL queryresult=session.execute(
text(sql_query),
{
'credential_type_said': credential_type_said,
'holder_id': holder_id,
'issuer_id': issuer_id,
'completed_states': completed_states_str
}
).mappings().all()
# Process the results: separate CredentialRequest fields and statusrequests_with_status= []
forrowinresult:
row_dict=dict(row) # Convert proxy row to dictstatus=row_dict.pop('status') # Extract status, removing it from the row_dictcred_request=CredentialRequest(**row_dict)
requests_with_status.append((cred_request, status))
returnrequests_with_status
And the test mock:
defmytest():
...
mock_session=UnifiedAlchemyMagicMock(data=[
...# other mocks
(
[mock.call.execute(
ANY, # This will match any query text
{
"credential_type_said": mock_credential_type.said,
"issuer_id": issuer_id,
"holder_id": holder_id,
"completed_states": credentials.terminal_states_tuple()
}
)],
[mocks.make_pending_request_list_mock()] # returns a list of CredentialRequest objects
),
# call test function with session, etc.
The result of the .mappings().all() mock is always an empty list rather than the specified data.
Like in the other issue, I end up having to use unittest.mock to work with my test, though that means I can't use alchemy-mock for this specific mock.
Thanks again for building this library.
The text was updated successfully, but these errors were encountered:
It appears that mocking always returns an empty list with the
session.execute(text(<sql>), params).mappings().all()
call.I have a multi-step mock where I am, in a large transaction, performing multiple lookups.
One of these example lookups is below, the one that doesn't work.
And the test mock:
The result of the
.mappings().all()
mock is always an empty list rather than the specified data.Like in the other issue, I end up having to use unittest.mock to work with my test, though that means I can't use alchemy-mock for this specific mock.
Thanks again for building this library.
The text was updated successfully, but these errors were encountered: