def setUp(self): #override the requests module self.requests = MagicMock(spec=requests) self.requests.get = MagicMock(spec=requests.get) self.requests.post = MagicMock(spec=requests.post) self.requests.put = MagicMock(spec=requests.put) resp = MagicMock(spec=requests.Response, spec_set=['cookies']) resp.cookies = {} self.requests.get.return_value = resp self.requests.post.return_value = resp self.requests.put.return_value = resp self.base_url = 'test_base_url' self.rw = APIRequestWrapper(base_url=self.base_url, user='******', password='******') self.rw._wrapped = self.requests
def setUp(self): #override the requests module self.requests = MagicMock(spec = requests) self.requests.get = MagicMock(spec=requests.get) self.requests.post = MagicMock(spec=requests.post) self.requests.put = MagicMock(spec=requests.put) resp = MagicMock(spec=requests.Response, spec_set=['cookies']) resp.cookies = {} self.requests.get.return_value = resp self.requests.post.return_value = resp self.requests.put.return_value = resp self.base_url = 'test_base_url' self.rw = APIRequestWrapper(base_url=self.base_url, user='******', password='******') self.rw._wrapped = self.requests
class TestAPIRequestWrapper(unittest.TestCase): def setUp(self): #override the requests module self.requests = MagicMock(spec = requests) self.requests.get = MagicMock(spec=requests.get) self.requests.post = MagicMock(spec=requests.post) self.requests.put = MagicMock(spec=requests.put) resp = MagicMock(spec=requests.Response, spec_set=['cookies']) resp.cookies = {} self.requests.get.return_value = resp self.requests.post.return_value = resp self.requests.put.return_value = resp self.base_url = 'test_base_url' self.rw = APIRequestWrapper(base_url=self.base_url, user='******', password='******') self.rw._wrapped = self.requests def test_get(self): url_params = '/plus_this_get' self.rw.get(url_params=url_params) #see what the mock object was called with call_args = self.requests.get.call_args #make sure headers get to it ok self.assertEquals(call_args[0][0], self.base_url + url_params) #self.assertEquals(call_args[1]['headers'], self.rw.headers) def test_post(self): url_params = '/plus_this_post' data = 'this is my data' self.rw.post(url_params=url_params, data = data) #see what the mock object was called with call_args = self.requests.post.call_args #make sure headers get to it ok self.assertEquals(call_args[0][0], self.base_url + url_params) #self.assertEquals(call_args[1]['headers'], self.rw.headers) self.assertEquals(call_args[1]['data'], data) def test_put(self): url_params = '/plus_this_post' data = 'this is my data' auth = 'This is auth' self.rw.put(url_params=url_params, data = data, auth = auth) #see what the mock object was called with call_args = self.requests.put.call_args #make sure headers get to it ok self.assertEquals(call_args[0][0], self.base_url + url_params) #self.assertEquals(call_args[1]['headers'], self.rw.headers) self.assertEquals(call_args[1]['auth'], auth) self.assertEquals(call_args[1]['data'], data)
class TestAPIRequestWrapper(unittest.TestCase): def setUp(self): #override the requests module self.requests = MagicMock(spec=requests) self.requests.get = MagicMock(spec=requests.get) self.requests.post = MagicMock(spec=requests.post) self.requests.put = MagicMock(spec=requests.put) resp = MagicMock(spec=requests.Response, spec_set=['cookies']) resp.cookies = {} self.requests.get.return_value = resp self.requests.post.return_value = resp self.requests.put.return_value = resp self.base_url = 'test_base_url' self.rw = APIRequestWrapper(base_url=self.base_url, user='******', password='******') self.rw._wrapped = self.requests def test_get(self): url_params = '/plus_this_get' self.rw.get(url_params=url_params) #see what the mock object was called with call_args = self.requests.get.call_args #make sure headers get to it ok self.assertEquals(call_args[0][0], self.base_url + url_params) #self.assertEquals(call_args[1]['headers'], self.rw.headers) def test_post(self): url_params = '/plus_this_post' data = 'this is my data' self.rw.post(url_params=url_params, data=data) #see what the mock object was called with call_args = self.requests.post.call_args #make sure headers get to it ok self.assertEquals(call_args[0][0], self.base_url + url_params) #self.assertEquals(call_args[1]['headers'], self.rw.headers) self.assertEquals(call_args[1]['data'], data) def test_put(self): url_params = '/plus_this_post' data = 'this is my data' auth = 'This is auth' self.rw.put(url_params=url_params, data=data, auth=auth) #see what the mock object was called with call_args = self.requests.put.call_args #make sure headers get to it ok self.assertEquals(call_args[0][0], self.base_url + url_params) #self.assertEquals(call_args[1]['headers'], self.rw.headers) self.assertEquals(call_args[1]['auth'], auth) self.assertEquals(call_args[1]['data'], data)