Esempio n. 1
0
    def test_translate_found(self, mock_api_call):
        res = {
            "tuc": [{
                "phrase": {
                    "text": "anglais",
                    "language": "fr"
                }
            }, {
                "phrase": {
                    "text": "germanique",
                    "language": "fr"
                },
            }]
        }

        mock_api_call.return_value = mock.Mock()
        mock_api_call.return_value.status_code = 200
        mock_api_call.return_value.json.return_value = res

        expected_result = '[{"text": "anglais", "seq": 0}, {"text": "germanique", "seq": 1}]'
        expected_result = json.dumps(json.loads(expected_result))
        result = vb.translate("english", "en", "fr")

        if sys.version_info[:2] <= (2, 7):
            self.assertItemsEqual(expected_result, result)
        else:
            self.assertCountEqual(expected_result, result)
Esempio n. 2
0
    def test_translate_empty_list(self, mock_api_call):
        res = {"result": "ok", "tuc": [], "phrase": "english"}

        mock_api_call.return_value = mock.Mock()
        mock_api_call.return_value.status_code = 200
        mock_api_call.return_value.json.return_value = res

        self.assertFalse(vb.translate("english", "en", "fr"))
Esempio n. 3
0
async def translate(bot,msg):
	try:
		print('GET /translate')
		with msg['text'].split() as text:
			source = text[1]
			dest = text[2]
			word = text[3]
			await bot.sendMessage(msg['chat']['id'],eval(vb.translate(word,source_lang=source,dest_lang=dest))[0]['text'])
	except:
		await bot.sendMessage(msg['chat']['id'],"Syntax: /translate sourceLang destLang words. Eg: /translate en zh car")
Esempio n. 4
0
    def test_translate_not_found(self, mock_api_call):
        mock_api_call.return_value = mock.Mock()
        mock_api_call.return_value.status_code = 404

        self.assertFalse(vb.translate("english", "en", "fr"))