forked from openlabs/Microsoft-Translator-Python-API
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
43 lines (32 loc) · 1.23 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# -*- coding: utf-8 -*-
"""
test
Test the translator
:copyright: (c) 2012 by Openlabs Technologies & Consulting (P) Limited
:license: BSD, see LICENSE for more details.
"""
import unittest
import time
from microsofttranslator import Translator, TranslateApiException
client_id = "translaterpythonapi"
client_secret = "FLghnwW4LJmNgEG+EZkL8uE+wb7+6tkOS8eejHg3AaI="
class TestTranslator(unittest.TestCase):
def test_translate(self):
client = Translator(client_id, client_secret, debug=True)
self.assertEqual(client.translate("hello", "pt"), u'Ol\xe1')
def test_invalid_client_id(self):
client = Translator("foo", "bar")
with self.assertRaises(TranslateApiException):
client.translate("hello", "pt")
# def test_token_timeout(self):
# client = Translator(client_id, client_secret, debug=True)
# self.assertEqual(client.translate("hello", "pt"), u'Ol\xe1')
# time.sleep(610)
# self.assertEqual(client.translate("hello", "pt"), u'Ol\xe1')
def test_all():
loader = unittest.TestLoader()
suite = unittest.TestSuite()
suite.addTests(loader.loadTestsFromTestCase(TestTranslator))
return suite
if __name__ == '__main__':
unittest.main()