Commits

Branko Vukelic committed 8b9710a

Alias from as tfrom

Since the upstream API uses from, which is a reserved keyword, we need to
alias it, and normalize it later.

Comments (0)

Files changed (2)

mstranslator/client.py

     api_version = 'v2'
     api_endpoint_base = 'Http.svc'
     default_endpoint = 'Translate'
-    
+
     _valid_endpoints = {
         'AddTranslation': 'GET',
         'AddTranslationArray': 'POST',
         self.api_key = api_key
 
     def _get_quoted_data(self, **kwargs):
+        if 'tfrom' in kwargs:
+            kwargs['from'] = kwargs['tfrom']
+            del kwargs['tfrom']
         return urlencode(kwargs)
 
     def _get_endpoint_url(self, method=None):

tests/test_client.py

             'foo=bar&bar=1'
         )
 
+    def test_tfrom_is_alias_for_from(self):
+        self.assertEqual(
+            self.t._get_quoted_data(tfrom='test'),
+            'from=test'
+        )
+
     def test_get_full_url(self):
         self.assertEqual(
             self.t._get_full_url('Translate', text='foo'),
             dict(Authorization='Bearer %s' % api_key)
         )
 
-
-