from mock import patch Mock from grab import Grab import logging loggi

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from mock import patch, Mock
from grab import Grab
import logging
logging.basicConfig(leve=logging.DEBUG)
def request(self):
self.response.body = 'OK|captcha_id'
self.response.code = 200
with patch.object(Grab, 'request') as mock_method:
mock_method.side_effect = request
g = Grab()
g.request()
print g.response.code
print g.response.body
Traceback (most recent call last):
File "test.py", line 16, in <module>
g.request()
File "/home/kalombo/.virtualenvs/grab/local/lib/python2.7/site-packages/mock.py", line 955, in __call__
return _mock_self._mock_call(*args, **kwargs)
File "/home/kalombo/.virtualenvs/grab/local/lib/python2.7/site-packages/mock.py", line 1018, in _mock_call
ret_val = effect(*args, **kwargs)
TypeError: request() takes exactly 1 argument (0 given)