Python mox urllib2's Request and urllopen function

42 views Asked by At

I was trying to mox

req = urllib2.Request(
    rest_url, json.dumps(data), {'Content-Type': 'application/json'})
req = urllib2.urlopen(req)
chunk_size = 1024 * 1024
while True:
   chunk = req.read(chunk_size)
   if not chunk:
     break
   fd.write(chunk)

Can anyone help me with writing the mox tests for this? I was trying following piece

self.mox.StubOutWithMock(urllib2, "Request")
self.mox.StubOutWithMock(urllib2, "urlopen")
res = self.mox.CreateMockAnything(urllib2.Request)
urllib2.Request(IgnoreArg(), IgnoreArg(), IgnoreArg()).AndReturn(req).AndReturn(res)

But throws error

urllib2.Request(IgnoreArg(), IgnoreArg(), IgnoreArg()).AndReturn(req).AndReturn(res)
raise TypeError('Not callable')
TypeError: Not callable
0

There are 0 answers