Use a mock on test_factory_from_data_objects
Bug #1165210 reported by
Leo Arias
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/
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:/
Related branches
lp:~elopio/payclient/fix1165210-mock_factory
- Ricardo Kirkner (community): Approve
-
Diff: 48 lines (+16/-15)1 file modifiedsrc/payclient/tests/test_client.py (+16/-15)
Changed in payclient: | |
status: | Triaged → In Progress |
Changed in payclient: | |
status: | In Progress → Fix Committed |
tags: | added: u1-notrack |
To post a comment you must log in.
<pindonga> elopio, on l. 162, instead of asserting on the attrs, why not mock CreditCardReque st.__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