Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_conversation_webhook_read(self):
http_client = Mock()
http_client.request.return_value = '{"id":"5031e2da142d401c93fbc38518ebb604","url":"https://example.com","channelId":"c0dae31e440145e094c4708b7d908842","events":["conversation.created","conversation.updated"],"status":"enabled","createdDatetime":"2019-04-03T08:41:37Z","updatedDatetime":null}'
web_hook = Client('', http_client).conversation_read_webhook('webhook-id')
http_client.request.assert_called_once_with('webhooks/webhook-id', 'GET', None)
self.assertEqual(datetime(2019, 4, 3, 8, 41, 37, tzinfo=tzutc()), web_hook.createdDatetime)
self.assertEqual(None, web_hook.updatedDatetime)
self.assertEqual(['conversation.created', 'conversation.updated'], web_hook.events)
def test_verify_delete_invalid(self):
http_client = Mock()
http_client.request.return_value = '{"errors": [{"code": 20,"description": "verification id not found","parameter": null}]}'
with self.assertRaises(ErrorException):
Client('', http_client).verify_delete('non-existent-verify-id')
http_client.request.assert_called_once_with('verify/non-existent-verify-id', 'DELETE', None)
def test_purchased_numbers_list(self):
http_client = Mock()
http_client.request.return_value = '{"items":[{"number":"3197010260188","country":"NL","region":"","locality":"","features":["sms","voice"],"type":"mobile"}],"limit":20,"count":1}'
numbers = Client('', http_client).purchased_numbers_list({'number': 319}, 40, 2)
http_client.request.assert_called_once_with('phone-numbers', 'GET', {'number': 319, 'limit': 40, 'offset': 2})
self.assertEqual(1, numbers.count)
self.assertEqual(1, len(numbers.items))
self.assertEqual('3197010260188', numbers.items[0].number)
def test_verify_create(self):
http_client = Mock()
http_client.request.return_value = '{}'
Client('', http_client).verify_create('31612345678', {})
http_client.request.assert_called_once_with('verify', 'POST', {'recipient': '31612345678'})
def test_message_delete_invalid(self):
http_client = Mock()
http_client.request.return_value = '{"errors": [{"code": 20, "description": "message not found", "parameter": null}]}'
with self.assertRaises(ErrorException):
Client('', http_client).message_delete('non-existent-message-id')
http_client.request.assert_called_once_with('messages/non-existent-message-id', 'DELETE', None)
def test_voice_recording_download(self):
http_client = Mock()
http_client.request.return_value = '{"data":null,"errors":[{"message":"No recording found for ID `00000000-0000-0000-0000-000000000000`.","code":13}],"pagination":{"totalCount":0,"pageCount":0,"currentPage":0,"perPage":0}}'
with self.assertRaises(ErrorException):
voice_recording = Client('', http_client).voice_recording_download('12348765-4321-0987-6543-210987654321',
'87654321-0987-6543-2109-876543210987',
'12345678-9012-3456-7890-123456789012')
http_client.request.return_value = '{"data":[{"id":"12345678-9012-3456-7890-123456789012","format":"wav","legId":"87654321-0987-6543-2109-876543210987","status":"done","duration":32,"type":"transfer","createdAt":"2018-01-01T00:00:01Z","updatedAt":"2018-01-01T00:00:05Z","deletedAt":null}],"pagination":{"totalCount":0,"pageCount":0,"currentPage":0,"perPage":0}}'
with self.assertRaises(ErrorException):
voice_recording = Client('', http_client).voice_recording_download('12348765-4321-0987-6543-210987654321',
'87654321-0987-6543-2109-876543210987',
'12345678-9012-3456-7890-123456789012')
def test_delete_number_invalid(self):
http_client = Mock()
http_client.request.return_value = '{"errors": [{"code": 20, "description": "number not found", "parameter": null}]}'
with self.assertRaises(ErrorException):
Client('', http_client).delete_number('non-existent-number')
http_client.request.assert_called_once_with('phone-numbers/non-existent-number', 'DELETE', None)
def test_contact_delete_invalid(self):
http_client = Mock()
http_client.request.return_value = '{"errors": [{"code": 20,"description": "contact not found","parameter": null}]}'
with self.assertRaises(ErrorException):
Client('', http_client).contact_delete('non-existent-contact-id')
http_client.request.assert_called_once_with('contacts/non-existent-contact-id', 'DELETE', None)
def test_verify_delete_invalid(self):
http_client = Mock()
http_client.request.return_value = '{"errors": [{"code": 20,"description": "verification id not found","parameter": null}]}'
with self.assertRaises(ErrorException):
Client('', http_client).verify_delete('non-existent-verify-id')
http_client.request.assert_called_once_with('verify/non-existent-verify-id', 'DELETE', None)
def test_voice_recording_download(self):
http_client = Mock()
http_client.request.return_value = '{"data":null,"errors":[{"message":"No recording found for ID `00000000-0000-0000-0000-000000000000`.","code":13}],"pagination":{"totalCount":0,"pageCount":0,"currentPage":0,"perPage":0}}'
with self.assertRaises(ErrorException):
voice_recording = Client('', http_client).voice_recording_download('12348765-4321-0987-6543-210987654321',
'87654321-0987-6543-2109-876543210987',
'12345678-9012-3456-7890-123456789012')
http_client.request.return_value = '{"data":[{"id":"12345678-9012-3456-7890-123456789012","format":"wav","legId":"87654321-0987-6543-2109-876543210987","status":"done","duration":32,"type":"transfer","createdAt":"2018-01-01T00:00:01Z","updatedAt":"2018-01-01T00:00:05Z","deletedAt":null}],"pagination":{"totalCount":0,"pageCount":0,"currentPage":0,"perPage":0}}'
with self.assertRaises(ErrorException):
voice_recording = Client('', http_client).voice_recording_download('12348765-4321-0987-6543-210987654321',
'87654321-0987-6543-2109-876543210987',
'12345678-9012-3456-7890-123456789012')