def test_parseLegacyMultiFailure(self): response = {'body': 'ERR: 301, Some Failure\nOK:12345'} transport = Transport() result = transport.parseLegacy(response) self.assertTrue(len(result) == 2) self.assertTrue(result[0]['code'] == '301') self.assertTrue(result[1]['OK'] == '12345')
def __init__(self, token): """ Construct a new API instance with the auth token of the API :param str token: The auth token """ self.token = token Transport.__init__(self)
def __init__(self, apiKey): """ Construct a new API instance with the auth key of the API :param str apiKey: The auth key """ self.apiKey = apiKey Transport.__init__(self)
def test_request(self, mock_request): transport = Transport() transport.request('act') mock_request.assert_called_with( 'http://api.clickatell.com/act', params={}, data='{}', headers={'User-Agent': 'ClickatellPython/0.1.0 httplib2 Python/' + platform.python_version()} )
def test_merge(self): transport = Transport() dict1 = {'test': 1} dict2 = {'test': 2, 'test2': 3} dict3 = {'test1': 1, 'test2': 2} merge = transport.merge(dict1, dict2, dict3) self.assertTrue(merge['test'] == 2) self.assertTrue(merge['test2'] == 2) self.assertTrue(merge['test1'] == 1)
def test_parseRestFailure(self): response = json.dumps( {'error': { 'description': 'Error', 'code': '301' }}) transport = Transport() self.assertRaises(ClickatellError, lambda: transport.parseRest(response))
def test_request(self, mock_request): transport = Transport() transport.request('act') mock_request.assert_called_with('http://api.clickatell.com/act', params={}, data='{}', headers={ 'User-Agent': 'ClickatellPython/0.1.2 Python/' + platform.python_version() })
def __init__(self, username, password, apiId): """ Construct a new API instance with the authentication details and the API ID. :param str username: The API username :param str password: The API password :param int apiId: The API ID """ self.username = username self.password = password self.apiId = apiId Transport.__init__(self) pass
def request(self, action, data={}, headers={}, method='GET'): """ Append the user authentication details to every incoming request """ data = self.merge(data, { 'user': self.username, 'password': self.password, 'api_id': self.apiId }) return Transport.request(self, action, data, headers, method)
def request(self, action, data={}, headers={}, method='GET'): """ Append the REST headers to every request """ headers = { "Authorization": self.apiKey, "Content-Type": "application/json", "Accept": "application/json" } return Transport.request(self, action, data, headers, method)
def request(self, action, data={}, headers={}, method='GET'): """ Append the REST headers to every request """ headers = { "Authorization": "Bearer " + self.token, "Content-Type": "application/json", "X-Version": "1", "Accept": "application/json" } return Transport.request(self, action, data, headers, method)
def request(self, action, data={}, headers={}, method='GET'): """ Append the user authentication details to every incoming request """ data = self.merge(data, {'apiKey': self.apiKey}) return Transport.request(self, action, data, headers, method)
def request(self, action, data={}, headers={}, method='GET'): """ Append the user authentication details to every incoming request """ data = self.merge(data, {'user': self.username, 'password': self.password, 'api_id': self.apiId}) return Transport.request(self, action, data, headers, method)
def test_parseLegacyFailure(self): response = {'body': 'ERR: Some exception'} transport = Transport() self.assertRaises(ClickatellError, lambda: transport.parseLegacy(response))
def test_request_return(self): transport = Transport() text = transport.request('404') # content is expected to return as a string self.assertFalse(isinstance(text, bytes))
def test_parseRest(self): response = {'body': json.dumps({'data':True})} transport = Transport() self.assertTrue(transport.parseRest(response))
def test_parseRestFailure(self): response = {'body': json.dumps({'error':{'description':'Error','code':'301'}})} transport = Transport() self.assertRaises(ClickatellError, lambda: transport.parseRest(response))
def test_parseLegacy(self): response = {'body': 'OK: 1234 Test: 12345'} transport = Transport() result = transport.parseLegacy(response) self.assertTrue(result['OK'] == '1234') self.assertTrue(result['Test'] == '12345')
def test_parseRest(self): response = {'body': json.dumps({'data': True})} transport = Transport() self.assertTrue(transport.parseRest(response))