Skip to content

Commit 875fece

Browse files
committed
Fix SpeechToTextV1.add_corpus() to use POST instead of GET, closes #207
1 parent 13290dc commit 875fece

2 files changed

Lines changed: 23 additions & 24 deletions

File tree

test/test_speech_to_text_v1.py

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -106,49 +106,48 @@ def test_custom_model():
106106

107107
assert len(responses.calls) == 5
108108

109-
@responses.activate
110109
def test_custom_corpora():
111110

112111
corpora_url = 'https://stream.watsonplatform.net/speech-to-text/api/v1/customizations/{0}/corpora'
113112
get_corpora_url = '{0}/{1}'.format(corpora_url.format('customid'),'corpus')
114113

115-
responses.add(responses.GET, corpora_url.format('customid'),
116-
body='{"get response": "yep"}', status=200,
117-
content_type='application/json')
114+
with responses.RequestsMock(assert_all_requests_are_fired=True) as rsps:
115+
rsps.add(responses.GET, corpora_url.format('customid'),
116+
body='{"get response": "yep"}', status=200,
117+
content_type='application/json')
118118

119-
responses.add(responses.POST, get_corpora_url,
119+
rsps.add(responses.POST, get_corpora_url,
120120
body='{"get response": "yep"}',
121121
status=200,
122122
content_type='application/json')
123123

124-
responses.add(responses.GET, get_corpora_url,
124+
rsps.add(responses.GET, get_corpora_url,
125125
body='{"get response": "yep"}',
126126
status=200,
127127
content_type='application/json')
128128

129-
responses.add(responses.DELETE, get_corpora_url,
130-
body='{"get response": "yep"}',
131-
status=200,
132-
content_type='application/json')
129+
rsps.add(responses.DELETE, get_corpora_url,
130+
body='{"get response": "yep"}',
131+
status=200,
132+
content_type='application/json')
133133

134-
speech_to_text = watson_developer_cloud.SpeechToTextV1(
135-
username="username", password="password")
134+
speech_to_text = watson_developer_cloud.SpeechToTextV1(
135+
username="username", password="password")
136136

137-
speech_to_text.list_corpora(customization_id='customid')
137+
speech_to_text.list_corpora(customization_id='customid')
138138

139-
file_path = '../resources/speech_to_text/corpus-short-1.txt'
140-
full_path = os.path.join(os.path.dirname(__file__), file_path)
141-
with open(full_path) as corpus_file:
142-
speech_to_text.add_corpus(customization_id='customid',
143-
corpus_name="corpus", file_data=corpus_file)
139+
file_path = '../resources/speech_to_text/corpus-short-1.txt'
140+
full_path = os.path.join(os.path.dirname(__file__), file_path)
141+
with open(full_path) as corpus_file:
142+
speech_to_text.add_corpus(customization_id='customid',
143+
corpus_name="corpus", file_data=corpus_file)
144144

145-
speech_to_text.get_corpus(customization_id='customid',
146-
corpus_name='corpus')
145+
speech_to_text.get_corpus(customization_id='customid',
146+
corpus_name='corpus')
147147

148-
speech_to_text.delete_corpus(customization_id='customid',
149-
corpus_name='corpus')
148+
speech_to_text.delete_corpus(customization_id='customid',
149+
corpus_name='corpus')
150150

151-
assert len(responses.calls) == 4
152151

153152
@responses.activate
154153
def test_custom_words():

watson_developer_cloud/speech_to_text_v1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def add_corpus(self,
118118

119119
headers = {'Content-Type': 'application/octet-stream'}
120120

121-
return self.request(method='GET',
121+
return self.request(method='POST',
122122
url=url.format(customization_id,
123123
corpus_name),
124124
headers=headers,

0 commit comments

Comments
 (0)