Skip to content

Commit

Permalink
SWI-5462 Add Real Time Transcriptions Tests (#207)
Browse files Browse the repository at this point in the history
* add privacy field to calls api test

* remove unused env var

* update recordings smoke tests to use new method names

* add files for stats and transcriptions apis

* update smoke test header blocks

* add statistics smoke tests

* fill in skeleton of transcriptions test

* transcriptions

* 403 from manteca :(

* finalize transcriptions tests

* update smoke test wf

* only main
  • Loading branch information
ckoegel authored Jun 18, 2024
1 parent a684bf3 commit cf4a633
Show file tree
Hide file tree
Showing 9 changed files with 219 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Nightly Smoke Tests
name: Smoke Tests

on:
schedule:
Expand All @@ -13,6 +13,11 @@ on:
options:
- WARNING
- DEBUG
pull_request:
branches:
- main
paths:
- 'test/smoke/**'

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}
Expand All @@ -39,7 +44,7 @@ env:

jobs:
test:
name: Nightly Smoke Test
name: Smoke Test
runs-on: ubuntu-latest
env:
PYTHON_VERSION: '3.12'
Expand Down
3 changes: 2 additions & 1 deletion test/smoke/test_calls_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Integration test for Bandwidth's Voice Voice Calls API
Integration test for Bandwidth's Voice Calls API
"""
from bandwidth import ApiResponse
from test.utils.env_variables import *
Expand Down Expand Up @@ -57,6 +57,7 @@ def setUp(self):
self.createCallBody = CreateCall(
to=USER_NUMBER,
var_from=BW_NUMBER,
privacy=True,
application_id=BW_VOICE_APPLICATION_ID,
answer_url=BASE_CALLBACK_URL,
answer_method=CallbackMethodEnum("POST"),
Expand Down
2 changes: 1 addition & 1 deletion test/smoke/test_conferences_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Integration tests for Bandwidth's Voice Voice Conferences API
Integration tests for Bandwidth's Voice Conferences API
"""

from cgi import test
Expand Down
2 changes: 1 addition & 1 deletion test/smoke/test_media_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Integration test for Bandwidth's Media API
Integration test for Bandwidth's Messaging Media API
"""

import uuid
Expand Down
10 changes: 1 addition & 9 deletions test/smoke/test_messages_api.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
"""
Bandwidth
Bandwidth's Communication APIs # noqa: E501
The version of the OpenAPI document: 1.0.0
Contact: [email protected]
Generated by: https://openapi-generator.tech
Integration test for Bandwidth's Messaging API
"""

import os
Expand Down
32 changes: 12 additions & 20 deletions test/smoke/test_recordings_api.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
"""
Bandwidth
Bandwidth's Communication APIs # noqa: E501
The version of the OpenAPI document: 1.0.0
Contact: [email protected]
Generated by: https://openapi-generator.tech
Integration test for Bandwidth's Voice Recordings API
"""


import os
from typing import Dict, List, Tuple
import unittest
Expand Down Expand Up @@ -219,8 +211,8 @@ def test_successful_call_recording(self) -> None:
- get_call_recording
- download_call_recording
- transcribe_call_recording
- get_call_transcription
- delete_call_transcription
- get_recording_transcription
- delete_recording_transcription
- delete_recording_media
- delete_recording
"""
Expand Down Expand Up @@ -288,7 +280,7 @@ def test_successful_call_recording(self) -> None:
assert_that(call_status['callTranscribed'], equal_to(True))

# Get the transcription
transcription_response = self.recordings_api_instance.get_call_transcription_with_http_info(
transcription_response = self.recordings_api_instance.get_recording_transcription_with_http_info(
BW_ACCOUNT_ID, call_id, recording_id)
assert_that(transcription_response.status_code, equal_to(200)) # Check response code

Expand All @@ -302,11 +294,11 @@ def test_successful_call_recording(self) -> None:
))

# Delete the transcription
delete_transcription_response = self.recordings_api_instance.delete_call_transcription_with_http_info(
delete_transcription_response = self.recordings_api_instance.get_recording_transcription_with_http_info(
BW_ACCOUNT_ID, call_id, recording_id)
assert_that(delete_transcription_response.status_code, equal_to(204)) # Check response code

assert_that(calling(self.recordings_api_instance.get_call_transcription).with_args(
assert_that(calling(self.recordings_api_instance.get_recording_transcription).with_args(
BW_ACCOUNT_ID, call_id, recording_id), raises(NotFoundException))

# Delete Recording media
Expand Down Expand Up @@ -454,28 +446,28 @@ def test_4xx_errors(self) -> None:
assert_that(call_status['callTranscribed'], equal_to(True))

# Use the unauthorized client to get transcripion (401)
assert_that(calling(self.unauthorized_recordings_api_instance.get_call_transcription).with_args(
assert_that(calling(self.unauthorized_recordings_api_instance.get_recording_transcription).with_args(
BW_ACCOUNT_ID, call_id, recording_id), raises(UnauthorizedException))

# Non-existent account id (403)
assert_that(calling(self.recordings_api_instance.get_call_transcription).with_args(
assert_that(calling(self.recordings_api_instance.get_recording_transcription).with_args(
"not an account id", call_id, recording_id), raises(ForbiddenException))

# Non-existent recording id (404)
assert_that(calling(self.recordings_api_instance.get_call_transcription).with_args(
assert_that(calling(self.recordings_api_instance.get_recording_transcription).with_args(
BW_ACCOUNT_ID, call_id, "not a recording id"), raises(NotFoundException))

# Delete Transcription
# Use the unauthorized client to delete transcripion (401)
assert_that(calling(self.unauthorized_recordings_api_instance.delete_call_transcription).with_args(
assert_that(calling(self.unauthorized_recordings_api_instance.delete_recording_transcription).with_args(
BW_ACCOUNT_ID, call_id, recording_id), raises(UnauthorizedException))

# Non-existent account id (403)
assert_that(calling(self.recordings_api_instance.delete_call_transcription).with_args(
assert_that(calling(self.recordings_api_instance.delete_recording_transcription).with_args(
"not an account id", call_id, recording_id), raises(ForbiddenException))

# Non-existent recording id (404)
assert_that(calling(self.recordings_api_instance.delete_call_transcription).with_args(
assert_that(calling(self.recordings_api_instance.delete_recording_transcription).with_args(
BW_ACCOUNT_ID, call_id, "not a recording id"), raises(NotFoundException))

# Delete Recording Media
Expand Down
41 changes: 41 additions & 0 deletions test/smoke/test_statistics_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
Integration test for Bandwidth's Statistics API
"""
import unittest
import logging

from hamcrest import *
from bandwidth import ApiClient, Configuration
from bandwidth.api.statistics_api import StatisticsApi
from bandwidth.models import AccountStatistics
from test.utils.env_variables import *


class TestStatisticsApi(unittest.TestCase):
"""StatisticsApi integration Test
"""

def setUp(self):
configuration = Configuration(
username=BW_USERNAME,
password=BW_PASSWORD
)
self.api_client = ApiClient(configuration)
self.api_instance = StatisticsApi(self.api_client)
self.account_id = BW_ACCOUNT_ID

def test_get_statistics(self):
api_response_with_http_info = self.api_instance.get_statistics_with_http_info(self.account_id)

logging.debug(api_response_with_http_info)
assert_that(api_response_with_http_info.status_code, equal_to(200))

api_response = self.api_instance.get_statistics(self.account_id)
assert_that(api_response, instance_of(AccountStatistics))
assert_that(api_response, has_properties(
'current_call_queue_size', instance_of(int),
'max_call_queue_size', instance_of(int)
))

if __name__ == '__main__':
unittest.main()
154 changes: 154 additions & 0 deletions test/smoke/test_transcriptions_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
"""
Integration test for Bandwidth's Voice Transcriptions API
"""
import unittest
import time

from hamcrest import *
from bandwidth import ApiClient, Configuration
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, CallTranscriptionMetadata, CallTranscriptionResponse, CallTranscription
from test.utils.env_variables import *


class TestTranscriptionsApi(unittest.TestCase):
"""TranscriptionsApi integration Test"""

def setUp(self) -> None:
configuration = Configuration(
username=BW_USERNAME,
password=BW_PASSWORD
)
api_client = ApiClient(configuration)

self.calls_api_instance = CallsApi(api_client)
self.transcriptions_api_instance = TranscriptionsApi(api_client)

# Rest client for interacting with Manteca
self.rest_client = RESTClientObject(Configuration.get_default_copy())

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

# Transcription ID
self.transcription_id: str

def create_call_transcription(self) -> None:

# Initialize the call with Manteca
response = self.rest_client.request(
method='POST',
url=MANTECA_BASE_URL + '/tests',
body={
'os': OPERATING_SYSTEM,
'language': 'python' + PYTHON_VERSION,
'type': 'CALL'
},
headers={
'Content-Type': 'application/json'
}
)

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

# Make a CreateCall body and assign the appropriate params
call_body = CreateCall(to=MANTECA_IDLE_NUMBER, var_from=MANTECA_ACTIVE_NUMBER,
application_id=MANTECA_APPLICATION_ID, answer_url=answer_url, tag=test_id)

# Make the call
create_call_response: CreateCallResponse = self.calls_api_instance.create_call(
BW_ACCOUNT_ID, call_body)
# assert_that(create_call_response.status_code, equal_to(201))

# Get the call id from the response
self.call_id = create_call_response.call_id

# Adding the call to the callIdArray
self.callIdArray.append(create_call_response.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(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 list_real_time_transcriptions(self) -> None:
"""Test case for list_real_time_transcriptions
Enumerate transcriptions made with StartTranscription
"""
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))

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
"""
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
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
"""

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

if __name__ == '__main__':
unittest.main()
1 change: 0 additions & 1 deletion test/utils/env_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
BW_MESSAGING_APPLICATION_ID = os.environ['BW_MESSAGING_APPLICATION_ID']
BW_VOICE_APPLICATION_ID = os.environ['BW_VOICE_APPLICATION_ID']
BASE_CALLBACK_URL = os.environ['BASE_CALLBACK_URL']
BW_NUMBER_PROVIDER = os.environ['BW_NUMBER_PROVIDER']
BW_NUMBER = os.environ['BW_NUMBER']
VZW_NUMBER = os.environ['VZW_NUMBER']
ATT_NUMBER = os.environ['ATT_NUMBER']
Expand Down

0 comments on commit cf4a633

Please sign in to comment.