def test_translate_model_id(cls): service = ibm_watson.LanguageTranslatorV3(version='2018-05-01', iam_apikey='iam_apikey') endpoint = '/v3/translate' url = '{0}{1}'.format(base_url, endpoint) expected = { "character_count": 22, "translations": [{ "translation": "Messi es el mejor" }], "word_count": 5 } responses.add(responses.POST, url, body=json.dumps(expected), status=200, content_type='application/json') response = service.translate( 'Messi is the best ever', model_id='en-es-conversational').get_result() assert len(responses.calls) == 2 assert responses.calls[1].request.url.startswith(url) assert response == expected TranslationResult._from_dict(response)
def test_translate_source_target(cls): service = ibm_watson.LanguageTranslatorV3(version='2018-05-01', iam_apikey='iam_apikey') endpoint = '/v3/translate' url = '{0}{1}'.format(base_url, endpoint) expected = { "character_count": 19, "translations": [{ "translation": u"Hello, how are you ? \u20ac" }], "word_count": 4 } responses.add(responses.POST, url, body=json.dumps(expected), status=200, content_type='application/json') response = service.translate('Hola, cómo estás? €', source='es', target='en').get_result() assert len(responses.calls) == 2 assert responses.calls[1].request.url.startswith(url) assert response == expected TranslationResult._from_dict(response)