[gedit-plugins/translate] get_remote_language_pairs UT



commit 8f804870a228ec878fc86701d3adb77160ee11bc
Author: Jordi Mas <jmas softcatala org>
Date:   Wed Jul 26 21:51:15 2017 +0200

    get_remote_language_pairs UT

 plugins/translate/tests/testapertium.py          |   18 ++++++++++++++++++
 plugins/translate/translate/services/apertium.py |    2 +-
 2 files changed, 19 insertions(+), 1 deletions(-)
---
diff --git a/plugins/translate/tests/testapertium.py b/plugins/translate/tests/testapertium.py
index 3433741..d6da6b6 100644
--- a/plugins/translate/tests/testapertium.py
+++ b/plugins/translate/tests/testapertium.py
@@ -65,5 +65,23 @@ class TestApertium(unittest.TestCase):
         self.assertEqual(['CatalĂ  -> English'], Apertium.g_language_names)
         self.assertEqual(['ca|en'], Apertium.g_language_codes)
 
+    @patch('urllib.request.urlopen')
+    def test_get_remote_language_pairs(self, mock_urlopen):
+        cm = MagicMock()
+        cm.getcode.return_value = 200
+        cm.read.return_value = bytes('{"responseStatus": 200, "responseData": [{"targetLanguage": "cat", 
"sourceLanguage": "oci_aran"}]}', 'utf-8')
+        cm.__enter__.return_value = cm
+        mock_urlopen.return_value = cm
+
+        apertium = Apertium(False)
+        language_pair_source, language_pair_target, locales, language_codes = 
apertium._get_remote_language_pairs()
+        self.assertEqual(['oci_aran'], language_pair_source)
+        self.assertEqual(['cat'], language_pair_target)
+        self.assertEqual({'oci_aran', 'cat'}, locales)
+        self.assertEqual(['oci_aran|cat'], language_codes)
+        mock_urlopen.assert_called_with("https://www.apertium.org/apy/listPairs";)
+
+
+
 if __name__ == '__main__':
     unittest.main()
diff --git a/plugins/translate/translate/services/apertium.py 
b/plugins/translate/translate/services/apertium.py
index 50b6be7..4f933a8 100644
--- a/plugins/translate/translate/services/apertium.py
+++ b/plugins/translate/translate/services/apertium.py
@@ -151,7 +151,7 @@ class Apertium(Service):
             Apertium.g_language_codes = language_codes
 
         except Exception as e:
-            print("_get_remote_language_pairs exception {0}".format(e))
+            print("_get_remote_language_names_and_pairs exception {0}".format(e))
 
 
     def _get_remote_language_pairs(self):


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]