Skip to content

Commit

Permalink
finalize transcriptions tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ckoegel committed Jun 18, 2024
1 parent c525ce3 commit 70b4dd4
Showing 1 changed file with 66 additions and 27 deletions.
93 changes: 66 additions & 27 deletions test/smoke/test_transcriptions_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from bandwidth.rest import RESTClientObject, RESTResponse
from bandwidth.api.transcriptions_api import TranscriptionsApi
from bandwidth.api.calls_api import CallsApi
from bandwidth.models import CreateCall
from bandwidth.models import CreateCall, CallTranscriptionMetadata, CallTranscriptionResponse, CallTranscription
from test.utils.env_variables import *


Expand All @@ -31,8 +31,12 @@ def setUp(self) -> None:

# Call ID Array
self.callIdArray = []
self.SLEEP_TIME_SEC = 3

def test_create_call(self) -> None:
# Transcription ID
self.transcription_id: str

def create_call_transcription(self) -> None:

# Initialize the call with Manteca
response = self.rest_client.request(
Expand All @@ -47,14 +51,10 @@ def test_create_call(self) -> None:
'Content-Type': 'application/json'
}
)
print(response.response.data)
print(MANTECA_BASE_URL + '/tests')

# Get the test id from the response
test_id = response.response.data.decode("utf-8")
answer_url = MANTECA_BASE_URL + '/bxml/idle'
print(answer_url)
print(test_id)

# Make a CreateCall body and assign the appropriate params
call_body = CreateCall(to=MANTECA_IDLE_NUMBER, var_from=MANTECA_ACTIVE_NUMBER,
Expand All @@ -72,44 +72,83 @@ def test_create_call(self) -> None:
self.callIdArray.append(create_call_response.call_id)


time.sleep(3)
print("Call ID: " + self.call_id)
time.sleep(self.SLEEP_TIME_SEC)
start_transcription_bxml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response><StartTranscription name=\"#{$manteca_call_id}\" tracks=\"inbound\"></StartTranscription><Pause duration=\"6\"/></Response>"
start_response = self.calls_api_instance.update_call_bxml_with_http_info(
BW_ACCOUNT_ID, self.call_id, start_transcription_bxml)
assert_that(start_response.status_code, equal_to(204))

# stop_transcription_bxml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response><StopTranscription name=\"#{$manteca_call_id}\"></StopTranscription></Response>"
# stop_response = self.calls_api_instance.update_call_bxml_with_http_info(
# BW_ACCOUNT_ID, self.call_id, stop_transcription_bxml)
# assert_that(response.stop_response, equal_to(204))

# end_response = self.calls_api_instance.update_call_with_http_info(
# BW_ACCOUNT_ID, self.call_id, {"state": "completed"})
# assert_that(end_response.status_code, equal_to(200))
stop_transcription_bxml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response><StopTranscription name=\"#{$manteca_call_id}\"></StopTranscription></Response>"
stop_response = self.calls_api_instance.update_call_bxml_with_http_info(
BW_ACCOUNT_ID, self.call_id, stop_transcription_bxml)
assert_that(stop_response.status_code, equal_to(204))
time.sleep(self.SLEEP_TIME_SEC)

end_response = self.calls_api_instance.update_call_with_http_info(
BW_ACCOUNT_ID, self.call_id, {"state": "completed"})
assert_that(end_response.status_code, equal_to(200))

def test_delete_real_time_transcription(self) -> None:
"""Test case for delete_real_time_transcription
def list_real_time_transcriptions(self) -> None:
"""Test case for list_real_time_transcriptions
Delete a specific transcription
Enumerate transcriptions made with StartTranscription
"""
pass
time.sleep(self.SLEEP_TIME_SEC * 20)
response = self.transcriptions_api_instance.list_real_time_transcriptions_with_http_info(
BW_ACCOUNT_ID, self.call_id)

assert_that(response.status_code, equal_to(200))
assert_that(response.data, instance_of(list))
assert_that(response.data[0], instance_of(CallTranscriptionMetadata))
assert_that(response.data[0].transcription_id, instance_of(str))
assert_that(response.data[0].transcription_url, instance_of(str))

def test_get_real_time_transcription(self) -> None:
self.transcription_id = response.data[0].transcription_id

def get_real_time_transcription(self) -> None:
"""Test case for get_real_time_transcription
Retrieve a specific transcription
"""
pass

def test_list_real_time_transcriptions(self) -> None:
"""Test case for list_real_time_transcriptions
response = self.transcriptions_api_instance.get_real_time_transcription_with_http_info(
BW_ACCOUNT_ID, self.call_id, self.transcription_id)

assert_that(response.status_code, equal_to(200))
assert_that(response.data, instance_of(CallTranscriptionResponse))
assert_that(response.data.account_id, equal_to(BW_ACCOUNT_ID))
assert_that(response.data.call_id, equal_to(self.call_id))
assert_that(response.data.transcription_id, equal_to(self.transcription_id))
assert_that(response.data.tracks, instance_of(list))
assert_that(response.data.tracks[0], instance_of(CallTranscription))
assert_that(response.data.tracks[0].track, equal_to('inbound'))
assert_that(response.data.tracks[0].confidence, instance_of(float))

def delete_real_time_transcription(self) -> None:
"""Test case for delete_real_time_transcription
Enumerate transcriptions made with StartTranscription
Delete a specific transcription
"""
response = self.transcriptions_api_instance.delete_real_time_transcription_with_http_info(
BW_ACCOUNT_ID, self.call_id, self.transcription_id)

assert_that(response.status_code, equal_to(200))

def _steps(self):
call_order = [
'create_call_transcription',
'list_real_time_transcriptions',
'get_real_time_transcription',
'delete_real_time_transcription'
]
for name in call_order:
yield name, getattr(self, name)

def test_steps(self) -> None:
"""Test each function from _steps.call_order in specified order
"""
pass

for name, step in self._steps():
step()

if __name__ == '__main__':
unittest.main()

0 comments on commit 70b4dd4

Please sign in to comment.