def test_google(self): cache.delete('%s-languages' % GoogleTranslation().mtid) httpretty.register_uri( httpretty.GET, 'https://www.googleapis.com/language/translate/v2/languages', body='{"data": {"languages": [ { "language": "cs" }]}}') httpretty.register_uri( httpretty.GET, 'https://www.googleapis.com/language/translate/v2/', body='{"data":{"translations":[{"translatedText":"svet"}]}}') machine = GoogleTranslation() self.assertTranslate(machine)
def test_google_invalid(self): """Test handling of server failure.""" cache.delete('%s-languages' % GoogleTranslation().mtid) httpretty.register_uri( httpretty.GET, 'https://www.googleapis.com/language/translate/v2/languages', body='', status=500, ) httpretty.register_uri( httpretty.GET, 'https://www.googleapis.com/language/translate/v2/', body='', status=500, ) machine = GoogleTranslation() self.assertEqual(machine.supported_languages, []) self.assertTranslate(machine, empty=True)
def test_google(self): cache.delete('%s-languages' % GoogleTranslation().mtid) httpretty.register_uri( httpretty.GET, 'https://www.googleapis.com/language/translate/v2/languages', body=json.dumps({ 'data': { 'languages': [{ 'language': 'en' }, { 'language': 'cs' }] } })) httpretty.register_uri( httpretty.GET, 'https://www.googleapis.com/language/translate/v2/', body=b'{"data":{"translations":[{"translatedText":"svet"}]}}') machine = GoogleTranslation() self.assertTranslate(machine)
def test_google(self): cache.delete('{0}-languages'.format(GoogleTranslation().mtid)) httpretty.register_uri(httpretty.GET, GOOGLE_API_ROOT + 'languages', body=json.dumps({ 'data': { 'languages': [{ 'language': 'en' }, { 'language': 'iw' }, { 'language': 'cs' }] } })) httpretty.register_uri( httpretty.GET, GOOGLE_API_ROOT, body=b'{"data":{"translations":[{"translatedText":"svet"}]}}') machine = GoogleTranslation() self.assert_translate(machine) self.assert_translate(machine, lang='he')