Skip to content

Commit

Permalink
fix(tts): remove extraneous filename param
Browse files Browse the repository at this point in the history
  • Loading branch information
apaparazzi0329 committed Jun 10, 2021
1 parent cd1dadf commit d6f9c5d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 58 deletions.
17 changes: 3 additions & 14 deletions ibm_watson/text_to_speech_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"""

from enum import Enum
from os.path import basename
from typing import BinaryIO, Dict, List
import json

Expand Down Expand Up @@ -1061,13 +1060,8 @@ def list_custom_prompts(self, customization_id: str,
response = self.send(request)
return response

def add_custom_prompt(self,
customization_id: str,
prompt_id: str,
metadata: 'PromptMetadata',
file: BinaryIO,
*,
filename: str = None,
def add_custom_prompt(self, customization_id: str, prompt_id: str,
metadata: 'PromptMetadata', file: BinaryIO,
**kwargs) -> DetailedResponse:
"""
Add a custom prompt.
Expand Down Expand Up @@ -1166,7 +1160,6 @@ def add_custom_prompt(self,
rate of 16 kHz. The service accepts audio with higher sampling rates. The
service transcodes all audio to 16 kHz before processing it.
* The length of the prompt audio is limited to 30 seconds.
:param str filename: (optional) The filename for file.
:param dict headers: A `dict` containing the request headers
:return: A `DetailedResponse` containing the result, headers and HTTP status code.
:rtype: DetailedResponse with `dict` result representing a `Prompt` object
Expand All @@ -1189,11 +1182,7 @@ def add_custom_prompt(self,
form_data = []
form_data.append(
('metadata', (None, json.dumps(metadata), 'application/json')))
if not filename and hasattr(file, 'name'):
filename = basename(file.name)
if not filename:
raise ValueError('filename must be provided')
form_data.append(('file', (filename, file, 'audio/wav')))
form_data.append(('file', (None, file, 'audio/wav')))

if 'headers' in kwargs:
headers.update(kwargs.get('headers'))
Expand Down
44 changes: 0 additions & 44 deletions test/unit/test_text_to_speech_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -1319,56 +1319,13 @@ def test_add_custom_prompt_all_params(self):
prompt_id = 'testString'
metadata = prompt_metadata_model
file = io.BytesIO(b'This is a mock file.').getvalue()
filename = 'testString'

# Invoke method
response = _service.add_custom_prompt(
customization_id,
prompt_id,
metadata,
file,
filename=filename,
headers={}
)

# Check for correct operation
assert len(responses.calls) == 1
assert response.status_code == 201


@responses.activate
def test_add_custom_prompt_required_params(self):
"""
test_add_custom_prompt_required_params()
"""
# Set up mock
url = self.preprocess_url(_base_url + '/v1/customizations/testString/prompts/testString')
mock_response = '{"prompt": "prompt", "prompt_id": "prompt_id", "status": "status", "error": "error", "speaker_id": "speaker_id"}'
responses.add(responses.POST,
url,
body=mock_response,
content_type='application/json',
status=201)

# Construct a dict representation of a PromptMetadata model
prompt_metadata_model = {}
prompt_metadata_model['prompt_text'] = 'testString'
prompt_metadata_model['speaker_id'] = 'testString'

# Set up parameter values
customization_id = 'testString'
prompt_id = 'testString'
metadata = prompt_metadata_model
file = io.BytesIO(b'This is a mock file.').getvalue()
filename = 'testString'

# Invoke method
response = _service.add_custom_prompt(
customization_id,
prompt_id,
metadata,
file,
filename=filename,
headers={}
)

Expand Down Expand Up @@ -1401,7 +1358,6 @@ def test_add_custom_prompt_value_error(self):
prompt_id = 'testString'
metadata = prompt_metadata_model
file = io.BytesIO(b'This is a mock file.').getvalue()
filename = 'testString'

# Pass in all but one required param and check for a ValueError
req_param_dict = {
Expand Down

0 comments on commit d6f9c5d

Please sign in to comment.