def test_fail_on_request_exception(self, get): api = Api({}) get.side_effect = RequestException('I\'m just working here man') with self.assertRaises(SystemExit): api.request('/me', auth=True) api2 = api.clone(sysexit=False) with self.assertRaises(ApiException): api2.request('/me', auth=True, csrf=True)
def test_fail_on_ssl(self, get): api = Api({}) get.side_effect = SSLError('Hey hey') with self.assertRaises(SystemExit): api.request('/me', auth=True) api2 = api.clone(sysexit=False) with self.assertRaises(ApiException): api2.request('/me', auth=True)
def test_fail_on_errored_response(self, get): api = Api({}) get.return_value = {'error': 'SomethingError'} with self.assertRaises(SystemExit): api.request('/me', auth=True) api2 = api.clone(sysexit=False) with self.assertRaises(ApiException): api2.request('/me', auth=True, csrf=True)
def test_fail_on_json(self, get): api = Api({}) dummy = Mock() dummy.json.side_effect = Exception('JSON parsing failed') dummy.text.return_value = 'something' get.return_value = dummy with self.assertRaises(SystemExit): api.request('/me', auth=True) api2 = api.clone(sysexit=False) with self.assertRaises(ApiException): api2.request('/me', auth=True)
def test_text_response(self, get): api = Api({}) dummy = Mock(text='some text') dummy.json.side_effect = Exception('Should not call this') get.return_value = dummy res = api.request('/me', result='text') self.assertEqual(res, 'some text')
def test_basic_request(self, post): api = Api({}) api.request('/test', method='post', data={'tag': ['babuf']}) post.assert_called_once_with('https://point.im/api/test', data={'tag': ['babuf']})