unit testing - Python Mock not correctly setting return value -


i attempting build unit tests , have been using mock, upon using 2 patch statements, not able set proper return values.

@patch('pulleffect.lib.google.gcal_helper.validate_and_refresh_creds') @patch('pulleffect.lib.google.gcal_helper.get_google_creds') def test_get_calendar_list_for_gcalhelper_without_credentials(self,                                                                mock_get_google_creds,                                                                mock_validate_and_refresh_creds):     mock_validate_and_refresh_creds = "redirect"     mock_get_google_creds = "credentials"     credentials = pulleffect.lib.google.gcal_helper.get_calendar_list("name","widget")     assert b'redirect' in credentials 

however assert fails , instead of expected string redirect instead

<magicmock name = "validate_and_refresh_creds() id = 14054613955344> 

i wondering necessary have redirect returned instead. have not encountered issue when patching single method.

i able fix issue of

<magicmock name = "foo()" id = number> 

incorrectly appearing replacing earlier code with:

from mock import magicmock  def test_get_calendar_list_for_gcalhelper_without_credentials(self):      rtn = { "redirect": "/gcal/authenticate"}            pulleffect.lib.google.gcal_helper.validate_and_refresh_creds = magicmock(name = "sup", return_value  = rtn)     pulleffect.lib.google.gcal_helper.get_google_creds = magicmock(name = "sup2", return_value  = "redirect")     credentials = pulleffect.lib.google.gcal_helper.get_calendar_list("name","widget")         assert b'redirect' in credentials 

this allowed return values set.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -