I am getting into testing in python and I asked myself how to test this method.
def get_response(self, url, params):
encoded_params = urllib.urlencode(params)
request = urllib2.Request(BASE_URL, headers=HEADERS)
response = urllib2.urlopen(request, encoded_params)
return response
Using doctest or unittest, how is this best achieved? I thought of passing get_response()
a test url and some test parameters, which exists in real world and to check if response.read()
returns the expected data. But somehow I feel, this is not the way it should be done. Any suggestions? I would appreciate suggestions how to handle such cases in context of texting.