コード例 #1
0
 def test_get_messages(self):
     """
     list_messages() should return messages
     """
     estimated_json = """
     [{
         "id": "messageId"
     }]
     """
     estimated_request = {
         'from': None,
         'to': None,
         'fromDateTime': None,
         'toDateTime': None,
         'direction': None,
         'state': None,
         'deliveryState': None,
         'sortOrder': None,
         'size': None
     }
     with patch('requests.request',
                return_value=create_response(200, estimated_json)) as p:
         client = get_client()
         data = list(client.list_messages())
         p.assert_called_with(
             'get',
             'https://api.catapult.inetwork.com/v1/users/userId/messages',
             auth=AUTH,
             headers=headers,
             params=estimated_request)
         self.assertEqual('messageId', data[0]['id'])
コード例 #2
0
 def test_list_recordings(self):
     """
     list_recordings() should return recordings
     """
     estimated_json = """
     [{
         "endTime": "2013-02-08T13:17:12.181Z",
         "id": "{recordingId1}",
         "media": "https://.../v1/users/.../media/{callId1}-1.wav",
         "call": "https://.../v1/users/.../calls/{callId1}",
         "startTime": "2013-02-08T13:15:47.587Z",
         "state": "complete"
     }]
     """
     with patch('requests.request',
                return_value=create_response(200, estimated_json)) as p:
         client = get_client()
         data = list(client.list_recordings())
         p.assert_called_with(
             'get',
             'https://api.catapult.inetwork.com/v1/users/userId/recordings',
             auth=AUTH,
             headers=headers,
             params={'size': None})
         self.assertEqual('{recordingId1}', data[0]['id'])
         self.assertEqual('{callId1}-1.wav', data[0]['media_name'])
コード例 #3
0
 def test_search_and_order_local_numbers(self):
     """
     search_and_order_available_numbers() should search, order and return available numbers
     """
     estimated_json_request = {
         'city': None,
         'state': None,
         'zip': '27606',
         'areaCode': None,
         'localNumber': None,
         'inLocalCallingArea': None,
         'quantity': 1
     }
     estimated_json = """
     [{
     "number": "{number1}",
     "nationalNumber": "{national_number1}",
     "price": "0.60",
     "location": "https://.../v1/users/.../phoneNumbers/{numberId1}"
     }]
     """
     with patch('requests.request',
                return_value=create_response(200, estimated_json)) as p:
         client = get_client()
         data = client.search_and_order_local_numbers(zip_code='27606',
                                                      quantity=1)
         p.assert_called_with(
             'post',
             'https://api.catapult.inetwork.com/v1/availableNumbers/local',
             auth=AUTH,
             headers=headers,
             params=estimated_json_request)
         self.assertEqual('{national_number1}', data[0]['national_number'])
         self.assertEqual('{numberId1}', data[0]['id'])
コード例 #4
0
 def test_send_message(self):
     """
     send_message() should create an message and return id
     """
     estimated_response = create_response(201)
     estimated_response.headers['Location'] = 'http://localhost/messageId'
     estimated_request = {
         'from': 'num1',
         'to': 'num2',
         'text': 'text',
         'media': None,
         'receiptRequested': None,
         'callbackUrl': None,
         'callbackHttpMethod': None,
         'callbackTimeout': None,
         'fallbackUrl': None,
         'tag': None
     }
     with patch('requests.request', return_value=estimated_response) as p:
         client = get_client()
         messageID = client.send_message(from_='num1',
                                         to='num2',
                                         text='text')
         p.assert_called_with(
             'post',
             'https://api.catapult.inetwork.com/v1/users/userId/messages',
             auth=AUTH,
             headers=headers,
             json=estimated_request)
         self.assertEqual('messageId', messageID)
コード例 #5
0
 def test_create_call(self):
     """
     create_call() should create a call and return id
     """
     estimated_resquest = {
         'from': '+1234567890',
         'to': '+1234567891',
         'callTimeout': None,
         'callbackUrl': None,
         'callbackTimeout': None,
         'callbackHttpMethod': None,
         'fallbackUrl': None,
         'bridgeId': None,
         'conferenceId': None,
         'recordingEnabled': False,
         'recordingFileFormat': None,
         'recordingMaxDuration': None,
         'transcriptionEnabled': False,
         'tag': None,
         'sipHeaders': None
     }
     estimated_response = create_response(201)
     estimated_response.headers['Location'] = 'http://localhost/callId'
     with patch('requests.request', return_value=estimated_response) as p:
         client = get_client()
         from_ = '+1234567890'
         to = '+1234567891'
         id = client.create_call(from_, to)
         p.assert_called_with(
             'post',
             'https://api.catapult.inetwork.com/v1/users/userId/calls',
             auth=AUTH,
             headers=headers,
             json=estimated_resquest)
         self.assertEqual('callId', id)
コード例 #6
0
 def test_search_available_toll_free_numbers(self):
     """
     search_available_numbers() should return available numbers
     """
     estimated_json_request = {'quantity': 1, 'pattern': '*456'}
     estimated_json = """
     [{
     "nationalNumber": "(844) 489-0456",
     "number": "+18444890456",
     "patternMatch": "           456",
     "price": "0.75"
     }]
     """
     with patch('requests.request',
                return_value=create_response(200, estimated_json)) as p:
         client = get_client()
         data = client.search_available_toll_free_numbers(quantity=1,
                                                          pattern='*456')
         p.assert_called_with(
             'get',
             'https://api.catapult.inetwork.com/v1/availableNumbers/tollFree',
             auth=AUTH,
             headers=headers,
             params=estimated_json_request)
         self.assertEqual('+18444890456', data[0]['number'])
コード例 #7
0
 def test_get_phone_number(self):
     """
     get_phone_number() should return a phone number
     """
     estimated_json = """
     {
     "id": "{numberId1}",
     "application": "https://catapult.inetwork.com/v1/users/users/u-ly123/applications/a-j321",
     "number":"{number1}",
     "nationalNumber":"{national_number1}",
     "name": "home phone",
     "createdTime": "2013-02-13T17:46:08.374Z",
     "state": "NC",
     "price": "0.60",
     "numberState": "enabled"
     }
     """
     with patch('requests.request',
                return_value=create_response(200, estimated_json)) as p:
         client = get_client()
         data = client.get_phone_number('numberId')
         p.assert_called_with(
             'get',
             'https://api.catapult.inetwork.com/v1/users/userId/phoneNumbers/numberId',
             headers=headers,
             auth=AUTH)
         self.assertEqual('{numberId1}', data['id'])
コード例 #8
0
 def test_update_application(self):
     """
     update_application() should update an application
     """
     estimated_json_request = {
         'name': 'MyUpdatedApplication',
         'incomingCallUrl': None,
         'incomingCallUrlCallbackTimeout': None,
         'incomingCallFallbackUrl': None,
         'incomingMessageUrl': None,
         'incomingMessageUrlCallbackTimeout': None,
         'incomingMessageFallbackUrl': None,
         'callbackHttpMethod': None,
         'autoAnswer': None
     }
     estimated_response = create_response(201)
     estimated_response.headers[
         'Location'] = 'http://localhost/applicationId'
     with patch('requests.request', return_value=estimated_response) as p:
         client = get_client()
         id = client.update_application(app_id='a-123',
                                        name='MyUpdatedApplication')
         p.assert_called_with(
             'post',
             'https://api.catapult.inetwork.com/v1/users/userId/applications/a-123',
             auth=AUTH,
             headers=headers,
             json=estimated_json_request)
コード例 #9
0
 def test_get_transcription(self):
     """
     get_transcription() should return a transcription
     """
     estimated_json = """
     {
         "chargeableDuration": 60,
         "id": "{transcription-id}",
         "state": "completed",
         "time": "2014-10-09T12:09:16Z",
         "text": "{transcription-text}",
         "textSize": 3627,
         "textUrl": "{url-to-full-text}"
     }
     """
     with patch('requests.request',
                return_value=create_response(200, estimated_json)) as p:
         client = get_client()
         data = client.get_transcription('recId', 'transcriptionId')
         p.assert_called_with(
             'get',
             'https://api.catapult.inetwork.com/v1/users/userId/recordings/recId/transcriptions/transcriptionId',
             headers=headers,
             auth=AUTH)
         self.assertEqual('{transcription-id}', data['id'])
コード例 #10
0
 def test_list_applications(self):
     """
     get_applications() should return applications
     """
     estimated_json = """
     [{
         "id": "a-111",
         "name": "MyFirstApp",
         "incomingCallUrl": "http://example.com/calls.php",
         "incomingMessageUrl": "http://example.com/messages.php",
         "incomingMessageUrlCallbackTimeout": 1000,
         "incomingCallUrlCallbackTimeout": 1000,
         "incomingCallFallbackUrl" : "http://fallback.com/",
         "incomingMessageFallbackUrl": "http://fallback.com/",
         "callbackHttpMethod": "GET",
         "autoAnswer": true
     }]
     """
     with patch('requests.request',
                return_value=create_response(200, estimated_json)) as p:
         client = get_client()
         data = list(client.list_applications())
         p.assert_called_with(
             'get',
             'https://api.catapult.inetwork.com/v1/users/userId/applications',
             auth=AUTH,
             headers=headers,
             params={"size": None})
         self.assertEqual(
             json.loads(estimated_json)[0]['id'], data[0]['id'])
コード例 #11
0
 def test_list_bridge_calls(self):
     """
     list_bridge_calls() should return calls of a bridge
     """
     estimated_json = """
     [{
         "activeTime": "2013-05-22T19:49:39Z",
         "direction": "out",
         "from": "{fromNumber}",
         "id": "{callId1}",
         "bridgeId": "{bridgeId}",
         "startTime": "2013-05-22T19:49:35Z",
         "state": "active",
         "to": "{toNumber1}",
         "recordingEnabled": false,
         "events": "https://api.catapult.inetwork.com/v1/users/{userId}/calls/{callId1}/events",
         "bridge": "https://api.catapult.inetwork.com/v1/users/{userId}/bridges/{bridgeId}"
     }]
     """
     with patch('requests.request', return_value=create_response(200, estimated_json)) as p:
         client = get_client()
         calls = list(client.list_bridge_calls('bridgeId'))
         p.assert_called_with(
             'get',
             'https://api.catapult.inetwork.com/v1/users/userId/bridges/bridgeId/calls',
             headers=headers,
             auth=AUTH)
         self.assertEqual('{callId1}', calls[0]['id'])
コード例 #12
0
 def test_list_transcriptions(self):
     """
     list_transcriptions() should return transcriptions
     """
     estimated_json = """
     [{
         "chargeableDuration": 60,
         "id": "{transcription-id}",
         "state": "completed",
         "time": "2014-10-09T12:09:16Z",
         "text": "{transcription-text}",
         "textSize": 3627,
         "textUrl": "{url-to-full-text}"
     }]
     """
     with patch('requests.request',
                return_value=create_response(200, estimated_json)) as p:
         client = get_client()
         data = list(client.list_transcriptions('recordingId'))
         p.assert_called_with(
             'get',
             'https://api.catapult.inetwork.com/v1/users/userId/recordings/recordingId/transcriptions',
             auth=AUTH,
             headers=headers,
             params={'size': None})
         self.assertEqual('{transcription-id}', data[0]['id'])
コード例 #13
0
 def test_list_calls(self):
     """
     list_calls() should return calls
     """
     estimated_resquest = {
         'bridgeId': None,
         'conferenceId': None,
         'from': None,
         'to': None,
         'size': None,
         'sortOrder': None
     }
     estimated_json = """
     [{
         "id": "callId"
     }]
     """
     with patch('requests.request',
                return_value=create_response(200, estimated_json)) as p:
         client = get_client()
         data = list(client.list_calls())
         p.assert_called_with(
             'get',
             'https://api.catapult.inetwork.com/v1/users/userId/calls',
             auth=AUTH,
             headers=headers,
             params=estimated_resquest)
         self.assertEqual('callId', data[0]['id'])
コード例 #14
0
 def test_create_domain_endpoint(self):
     """
     create_domain_endpoint() should create an endpoint and return id
     """
     estimated_response = create_response(201)
     estimated_response.headers['Location'] = 'http://localhost/endpointId'
     estimated_request = {
         'name': 'mysip',
         'description': None,
         'applicationId': None,
         'enabled': True,
         'credentials': {
             'password': '******'
         }
     }
     with patch('requests.request', return_value=estimated_response) as p:
         client = get_client()
         data = {'name': 'mysip', 'password': '******'}
         id = client.create_domain_endpoint('domainId', **data)
         p.assert_called_with(
             'post',
             'https://api.catapult.inetwork.com/v1/users/userId/domains/domainId/endpoints',
             auth=AUTH,
             headers=headers,
             json=estimated_request)
         self.assertEqual('endpointId', id)
コード例 #15
0
    def test_create_conference(self):
        """
        create_conference() should create a conference and return id
        """

        estimated_request = {
            'callbackUrl': None,
            'from': '+1234567980',
            'callbackTimeout': None,
            'callbackHttpMethod': 'GET',
            'fallbackUrl': None,
            'tag': 'my_tag'
        }

        estimated_response = create_response(201)
        estimated_response.headers[
            'Location'] = 'http://localhost/conferenceId'
        with patch('requests.request', return_value=estimated_response) as p:
            client = get_client()
            id = client.create_conference(from_='+1234567980',
                                          callbackUrl='http://abc.com',
                                          tag='my_tag',
                                          callback_http_method='GET')
            p.assert_called_with(
                'post',
                'https://api.catapult.inetwork.com/v1/users/userId/conferences',
                auth=AUTH,
                headers=headers,
                json=estimated_request)
            self.assertEqual('conferenceId', id)
コード例 #16
0
 def test_list_bridges(self):
     """
     list_bridges() should return bridges
     """
     estimated_json = """
     [{
         "id": "bridgeId",
         "state": "completed",
         "bridgeAudio": "true",
         "calls":"https://.../v1/users/{userId}/bridges/{bridgeId}/calls",
         "createdTime": "2013-04-22T13:55:30.279Z",
         "activatedTime": "2013-04-22T13:55:30.280Z",
         "completedTime": "2013-04-22T13:59:30.122Z"
     }]
     """
     with patch('requests.request', return_value=create_response(200, estimated_json)) as p:
         client = get_client()
         data = list(client.list_bridges())
         p.assert_called_with(
             'get',
             'https://api.catapult.inetwork.com/v1/users/userId/bridges',
             auth=AUTH,
             headers=headers,
             params={
                 'size': None})
         self.assertEqual('bridgeId', data[0]['id'])
コード例 #17
0
 def test_mute_conference(self):
     """
     mute_conference() should call update_conference() with right params
     """
     client = get_client()
     with patch.object(client, 'update_conference') as p:
         client.mute_conference('conferenceId', True)
         p.assert_called_with('conferenceId', mute=True)
コード例 #18
0
 def test_reject_call(self):
     """
     reject_call() should call update_call with right data
     """
     client = get_client()
     with patch.object(client, 'update_call') as p:
         client.reject_call('callId')
         p.assert_called_with('callId', state='rejected')
コード例 #19
0
 def test_disable_call_recording(self):
     """
     disable_call_recording() should call update_call with recording_enabled=False
     """
     client = get_client()
     with patch.object(client, 'update_call') as p:
         client.disable_call_recording('callId')
         p.assert_called_with('callId', recording_enabled=False)
コード例 #20
0
 def test_hold_conference_member(self):
     """
     hold_conference_member() should call update_conference_member() with right params
     """
     client = get_client()
     with patch.object(client, 'update_conference_member') as p:
         client.hold_conference_member('conferenceId', 'memberId', True)
         p.assert_called_with('conferenceId', 'memberId', hold=True)
コード例 #21
0
 def test_remove_conference_member(self):
     """
     delete_conference_member() should call update_conference_member() with right params
     """
     client = get_client()
     with patch.object(client, 'update_conference_member') as p:
         client.remove_conference_member('conferenceId', 'memberId')
         p.assert_called_with('conferenceId', 'memberId', state='completed')
コード例 #22
0
 def test_request_with_absolute_url(self):
     """
     _request() should make authorized request to absolute url
     """
     with patch('requests.request', return_value=create_response()) as p:
         client = get_client()
         response = client._request('get', 'http://localhost')
         p.assert_called_with('get', 'http://localhost', headers=headers, auth=('apiToken', 'apiSecret'))
コード例 #23
0
 def test_terminate_conference(self):
     """
     terminate_conference() should call update_conference() with right params
     """
     client = get_client()
     with patch.object(client, 'update_conference') as p:
         client.terminate_conference('conferenceId')
         p.assert_called_with('conferenceId', state='completed')
コード例 #24
0
 def test_hangup_call(self):
     """
     hangup_call() should call update_call with right data
     """
     client = get_client()
     with patch.object(client, 'update_call') as p:
         client.hangup_call('callId')
         p.assert_called_with('callId', state='completed')
コード例 #25
0
 def test_answer_call(self):
     """
     answer_call() should call update_call with right data
     """
     client = get_client()
     with patch.object(client, 'update_call') as p:
         client.answer_call('callId')
         p.assert_called_with('callId', state='active')
コード例 #26
0
 def test_request_with_relative_url(self):
     """
     _request() should make authorized request to relative url
     """
     with patch('requests.request', return_value=create_response()) as p:
         client = get_client()
         response = client._request('get', '/path')
         p.assert_called_with('get', 'https://api.catapult.inetwork.com/v1/path',
                              headers=headers, auth=('apiToken', 'apiSecret'))
コード例 #27
0
 def test_build_audio_playback(self):
     """
     Should return dict of values
     """
     estimated_json = {
         'fileUrl': 'http://sound.com/test.mp3',
         'loopEnabled': True,
     }
     client = get_client()
     my_audio = client.build_audio_playback(
         file_url="http://sound.com/test.mp3", loop_enabled=True)
     self.assertEqual(estimated_json, my_audio)
コード例 #28
0
 def test_delete_media_file(self):
     """
     delete_media_file() should remove a media file
     """
     with patch('requests.request', return_value=create_response(200)) as p:
         client = get_client()
         client.delete_media_file('file1')
         p.assert_called_with(
             'delete',
             'https://api.catapult.inetwork.com/v1/users/userId/media/file1',
             headers=headers,
             auth=AUTH)
コード例 #29
0
 def test_play_audio_file_to_conference_member(self):
     """
     play_audio_file_to_conference_member() should call play_audio_to_conference_member() with right params
     """
     client = get_client()
     with patch.object(client, 'play_audio_to_conference_member') as p:
         client.play_audio_file_to_conference_member(
             'conferenceId', 'memberId', 'url')
         p.assert_called_with('conferenceId',
                              'memberId',
                              file_url='url',
                              tag=None)
コード例 #30
0
 def test_delete_domain(self):
     """
     delete_domain() should remove an domain
     """
     with patch('requests.request', return_value=create_response(200)) as p:
         client = get_client()
         client.delete_domain('domainId')
         p.assert_called_with(
             'delete',
             'https://api.catapult.inetwork.com/v1/users/userId/domains/domainId',
             headers=headers,
             auth=AUTH)