I have a code which I am trying to test using Mock library/python-django. To give brief summary of my application is:
(PHASE I): Client use my app exposed API. The mapped API function make a HTTP Connection request to 3rd party API ( Tropo which are CaaS provider)
(PHASE II): Tropo server(3rd party) respond back with some url back to my server which I mapped to function which send another request to Tropo Server which on their side, make call() to phonenumbers.
I used Django test client by just using my API which does run but the problem is it also reply on Tropo to make real call to the numbers I give in. So I thought to use mock() library but I have very little knowledge of it.
What I did is, I see what response I get after first phase from Tropo hard coded it in variable input
and I also have expected_output
variable which is also hardcoded seeing the output after second phase.
But I want to architect my test framework properly in which I can mock the whole tropo library in my testing environment and all the request go to this fake library and not the real tropo. But not changing the code.
Any ideas or suggestion. Please bare me as I am developer and this is something I try to do for testing.
Since I am not getting any response I am trying to give more details of what exactly I am stuck in:
Let say there this snippet of my code in one function...
conn = httplib.HTTPConnection('Some_External_URI')
headers = {"accept": "application/json", "Content-type":"application/json"}
params = ''
conn.request('POST', data, params, headers)
response = conn.getresponse()
payload = response.read()
How I can mock this particular connection request?