I am trying to test the below function using unit test mocks but i am not able to do it since the return type from request get/post is of type <class 'requests.models.Response'>. please let me know how to mock this and unit test this below function:
def response_check(base_url, headers, schedule_name, response):
"""
Function to get response from dataform API and check the job status
"""
run_url = base_url + "/" + response.json()["id"]
query_response = requests.get(run_url, headers=headers)
while query_response.json()["status"] == "RUNNING":
time.sleep(10)
print("Dataform job running")
query_response = requests.get(run_url, headers=headers)
if query_response.json()["status"] in ["FAILED", "CANCELLED", "TIMED_OUT"]:
raise AirflowException(
f'Dataform task {schedule_name} has been {response.json()["status"]} for reason {response.json()["runLogUrl"]}'
)
print(query_response.json())
return "Dataform job finished"
I need to check for different response status but i am not able to mock the return type of it
@patch?side_effectto provide a list of canned responses; the calls torequests.getwill use them as they are made.