def test_post_ok(self, mock_post): """ Test ._post() handles a response """ mock_response = Mock( name='response', ok=True, status_code=200, ) mock_response.json.return_value = {"status": "ok", "tags": []} mock_post.return_value = mock_response resource = Resource(account_key='123') response = resource._post(request='list', uri='tags') self.assertDictEqual( response, {"status": "ok", "tags": []} ) mock_post.assert_called_once_with( url='https://api.logentries.com/v2/tags', headers={'Content-type': 'application/json'}, data=json.dumps({'acl': '123', 'account': '123', 'request': 'list'}) )
def test_post_not_ok(self, mock_post): """ Test ._post() handles a not ok response """ mock_response = Mock( name='response', ok=False, status_code=500, text='Server Error' ) mock_post.return_value = mock_response resource = Resource(account_key='123') with self.assertRaises(ServerException): resource._post(request='test1', uri='test_endpoint') mock_post.assert_called_once_with( url='https://api.logentries.com/v2/test_endpoint', headers={'Content-type': 'application/json'}, data=json.dumps({'acl': '123', 'account': '123', 'request': 'test1'}) )