我正在发送记录simple-salesforce
后尝试模拟update
服务器响应。但是,当我运行当前的测试时,它通过了,但没有任何迹象表明我的日志有影响。
mymodule.py
def update_SF(result):
exceptions = {}
updated_cases = []
logger.debug(
f'The following result is being processed by the update_SF function: {result}')
for id, dispositions in result.items():
disp = 'As of ' + NOW + '\n' + str('\n\n'.join(dispositions))
try:
# The call below is what I need to mock, to test the exception handling.
SF.Legal_Case__c.update(id, {'Test_Disposition__c': disp})
except Exception as e:
logger.debug(f'There was an exception: {e}')
# raise
exceptions[id] = e
time.sleep(10)
continue
logger.debug(f'Updated {id} with a disposition:\n{disp}\n\n')
updated_cases.append(f'Updated {id} with a disposition: {disp}')
return updated_cases, exceptions
test_mymodule.py
def test_retry_after_sf_server_exceptions(self):
print(f'\ntest_retry_after_sf_server_exceptions running')
with patch("mymodule.Salesforce") as patched_update:
# mock a SalesforceError response
patched_update.update.side_effect = SalesforceError
# verify the function returns the exception
result = update_SF(test_result)
print(f'\n{result[1]}')