@@ -513,3 +513,55 @@ def test_delete_user_data():
513513 response = speech_to_text .delete_user_data ('id' ).get_result ()
514514 assert response is None
515515 assert len (responses .calls ) == 1
516+
517+ @responses .activate
518+ def test_custom_grammars ():
519+ url = 'https://stream.watsonplatform.net/speech-to-text/api/v1/customizations/{0}/grammars/{1}'
520+
521+ responses .add (
522+ responses .POST ,
523+ url .format ('customization_id' , 'grammar_name' ),
524+ body = '{}' ,
525+ status = 200 ,
526+ content_type = 'application/json' )
527+
528+ responses .add (
529+ responses .DELETE ,
530+ url .format ('customization_id' , 'grammar_name' ),
531+ status = 200 ,
532+ content_type = 'application/json' )
533+
534+ responses .add (
535+ responses .GET ,
536+ url .format ('customization_id' , 'grammar_name' ),
537+ body = '{"status": "analyzed", "name": "test-add-grammar-python", "out_of_vocabulary_words": 0}' ,
538+ status = 200 ,
539+ content_type = 'application/json' )
540+
541+ responses .add (
542+ responses .GET ,
543+ url = 'https://stream.watsonplatform.net/speech-to-text/api/v1/customizations/customization_id/grammars' ,
544+ body = '{"grammars":[{"status": "analyzed", "name": "test-add-grammar-python", "out_of_vocabulary_words": 0}]}' ,
545+ status = 200 ,
546+ content_type = 'application/json' )
547+
548+ speech_to_text = watson_developer_cloud .SpeechToTextV1 (
549+ username = "username" , password = "password" )
550+
551+ with open (os .path .join (os .path .dirname (__file__ ), '../../resources/confirm-grammar.xml' ), 'rb' ) as grammar_file :
552+ speech_to_text .add_grammar (
553+ "customization_id" ,
554+ grammar_name = 'grammar_name' ,
555+ grammar_file = grammar_file ,
556+ content_type = 'application/srgs+xml' ,
557+ allow_overwrite = True )
558+ assert responses .calls [0 ].response .json () == {}
559+
560+ speech_to_text .delete_grammar ('customization_id' , 'grammar_name' )
561+ assert responses .calls [1 ].response .status_code == 200
562+
563+ speech_to_text .get_grammar ('customization_id' , 'grammar_name' )
564+ assert responses .calls [2 ].response .json () == {"status" : "analyzed" , "name" : "test-add-grammar-python" , "out_of_vocabulary_words" : 0 }
565+
566+ speech_to_text .list_grammars ('customization_id' )
567+ assert responses .calls [3 ].response .json () == {"grammars" :[{"status" : "analyzed" , "name" : "test-add-grammar-python" , "out_of_vocabulary_words" : 0 }]}
0 commit comments