Repository: watson-developer-cloud/python-sdk

Issue:
SpeechToTextV1.add_corpus() uses wrong http method (GET, should use POST)
Currently, using `add_corpus` will break with a `WatsonException: Unknown error` error. This is due to the method using the wrong HTTP method (GET, instead of POST). The tests don't catch this because the assertion in `test_custom_corpora` only checks the number of requests made and not the details of those requests.

I have a patch that should be ready soon.

Discussion:

Patch:
diff --git a/watson_developer_cloud/speech_to_text_v1.py b/watson_developer_cloud/speech_to_text_v1.py
index e849ad67..c2f717a6 100644
--- a/watson_developer_cloud/speech_to_text_v1.py
+++ b/watson_developer_cloud/speech_to_text_v1.py
@@ -118,7 +118,7 @@ class SpeechToTextV1(WatsonDeveloperCloudService):
 
         headers = {'Content-Type': 'application/octet-stream'}
 
-        return self.request(method='GET',
+        return self.request(method='POST',
                             url=url.format(customization_id,
                                            corpus_name),
                             headers=headers,


Test patch:
diff --git a/test/test_speech_to_text_v1.py b/test/test_speech_to_text_v1.py
index 2334f4b5..3153dcdf 100755
--- a/test/test_speech_to_text_v1.py
+++ b/test/test_speech_to_text_v1.py
@@ -106,49 +106,48 @@ def test_custom_model():
 
     assert len(responses.calls) == 5
 
-@responses.activate
 def test_custom_corpora():
 
     corpora_url = 'https://stream.watsonplatform.net/speech-to-text/api/v1/customizations/{0}/corpora'
     get_corpora_url = '{0}/{1}'.format(corpora_url.format('customid'),'corpus')
 
-    responses.add(responses.GET, corpora_url.format('customid'),
-                  body='{"get response": "yep"}', status=200,
-                  content_type='application/json')
+    with responses.RequestsMock(assert_all_requests_are_fired=True) as rsps:
+        rsps.add(responses.GET, corpora_url.format('customid'),
+                 body='{"get response": "yep"}', status=200,
+                 content_type='application/json')
 
-    responses.add(responses.POST, get_corpora_url,
+        rsps.add(responses.POST, get_corpora_url,
                  body='{"get response": "yep"}',
                  status=200,
                  content_type='application/json')
 
-    responses.add(responses.GET, get_corpora_url,
+        rsps.add(responses.GET, get_corpora_url,
                  body='{"get response": "yep"}',
                  status=200,
                  content_type='application/json')
 
-    responses.add(responses.DELETE, get_corpora_url,
-                  body='{"get response": "yep"}',
-                  status=200,
-                  content_type='application/json')
+        rsps.add(responses.DELETE, get_corpora_url,
+                 body='{"get response": "yep"}',
+                 status=200,
+                 content_type='application/json')
 
-    speech_to_text = watson_developer_cloud.SpeechToTextV1(
-        username="username", password="password")
+        speech_to_text = watson_developer_cloud.SpeechToTextV1(
+            username="username", password="password")
 
-    speech_to_text.list_corpora(customization_id='customid')
+        speech_to_text.list_corpora(customization_id='customid')
 
-    file_path = '../resources/speech_to_text/corpus-short-1.txt'
-    full_path = os.path.join(os.path.dirname(__file__), file_path)
-    with open(full_path) as corpus_file:
-        speech_to_text.add_corpus(customization_id='customid',
-                                  corpus_name="corpus", file_data=corpus_file)
+        file_path = '../resources/speech_to_text/corpus-short-1.txt'
+        full_path = os.path.join(os.path.dirname(__file__), file_path)
+        with open(full_path) as corpus_file:
+            speech_to_text.add_corpus(customization_id='customid',
+                                      corpus_name="corpus", file_data=corpus_file)
 
-    speech_to_text.get_corpus(customization_id='customid',
-                              corpus_name='corpus')
+        speech_to_text.get_corpus(customization_id='customid',
+                                  corpus_name='corpus')
 
-    speech_to_text.delete_corpus(customization_id='customid',
-                                 corpus_name='corpus')
+        speech_to_text.delete_corpus(customization_id='customid',
+                                     corpus_name='corpus')
 
-    assert len(responses.calls) == 4
 
 @responses.activate
 def test_custom_words():