Use a mock on test_factory_from_data_objects

Bug #1165210 reported by Leo Arias
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Canonical Payment Service Client
Fix Committed
Low
Leo Arias

Bug Description

On src/payclient/tests/test_client.py, test_factory_from_data_objects, it would be better to use a mock to check that the right parameters where sent to the constructor.

This wasn't implemented as part of the original MP [1] because we don't know how to mock a constructor. Assigning the bug to myself to ask Michael Foord and investigate further.

[1] https://code.launchpad.net/~elopio/payclient/data_objects/+merge/157434

Tags: u1-notrack

Related branches

Revision history for this message
Leo Arias (elopio) wrote :

<pindonga> elopio, on l. 162, instead of asserting on the attrs, why not mock CreditCardRequest.__new__ and assert it was called with the right kwargs?
<pindonga> you probably need a MagicMock instance for that, but imo it'd be testing what you actually want (which is unwrapping the args before calling __new_ ,right?)
<elopio> pindonga: +1
<elopio> pindonga: magicmock doesn't support __new__. Do you know any alternative?
<pindonga> :( no
<pindonga> plain mock maybe?
<pindonga> never really grokked magicmock
<elopio> pindonga: it says "are not supported as they are either in use by mock, can’t be set dynamically, or can cause problems", so I think it's not really possible to mock __init__ or __new__
<pindonga> elopio, ah
<pindonga> but you don't need to :)
<pindonga> you can mock CreditCardRequest (the class)
<pindonga> and the call assert_called_with
<pindonga> since it's a callable
<pindonga> right?
<pindonga> if not , I'd ask mfoord on monday
<elopio> I think so. I'm trying small changes to see if one works.
<elopio> the things is that if I mock CreditCardRequest, then .from_data_objects will be mocked too.
<elopio> yeah, I can't seem to make it work. I'll better ask mfoord.
<elopio> pindonga: is it ok if I land it with the assertion, and update with the mock later, if possible?
<pindonga> yes, I guess so, if nessita and matiasb agree
<nessita> sounds good
<matiasb> ok for me

Leo Arias (elopio)
Changed in payclient:
status: Triaged → In Progress
Changed in payclient:
status: In Progress → Fix Committed
Julien Funk (jaboing)
tags: added: u1-notrack
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.