diff --git a/CHANGES b/CHANGES index 1a24437..b3aad96 100644 --- a/CHANGES +++ b/CHANGES @@ -1,8 +1,8 @@ Version History =============== -Version 0.8.3 (Not yet released) --------------------------------- +Version 0.8.3 +------------- * Replace the (no longer working) Microsoft translation API with the new Azure Translator API (Fixes #200 and #201, thank you @svdvonde) diff --git a/rosetta/tests/tests.py b/rosetta/tests/tests.py index 358045d..a9b4488 100644 --- a/rosetta/tests/tests.py +++ b/rosetta/tests/tests.py @@ -3,6 +3,7 @@ import filecmp import hashlib import os import shutil +import vcr try: # Python 3 from urllib.parse import urlencode @@ -983,6 +984,11 @@ class RosettaTestCase(TestCase): r = self.client.get(url) self.assertEqual(r.status_code, 200) + @vcr.use_cassette('fixtures/vcr_cassettes/test_47_azure_ajax_translation.yaml', match_on=['method', 'scheme', 'host', 'port', 'path', 'query', 'raw_body'], record_mode='new_episodes') + def test_47_azure_ajax_translation(self): + r = self.client.get(reverse('rosetta.translate_text') + '?from=en&to=fr&text=hello%20world') + self.assertContains(r, '"Salut tout le monde"') + # Stubbed access control function def no_access(user): diff --git a/setup.py b/setup.py index ba8bf32..e04ef53 100644 --- a/setup.py +++ b/setup.py @@ -61,6 +61,6 @@ setup( 'requests >= 2.1.0', 'polib >= 1.1.0' ], - tests_require=['tox'], + tests_require=['tox', 'vcrpy'], cmdclass={'test': Tox}, ) diff --git a/testproject/fixtures/vcr_cassettes/test_33_pr_116_google_translate.yaml b/testproject/fixtures/vcr_cassettes/test_33_pr_116_google_translate.yaml deleted file mode 100644 index 42b2748..0000000 --- a/testproject/fixtures/vcr_cassettes/test_33_pr_116_google_translate.yaml +++ /dev/null @@ -1,27 +0,0 @@ -interactions: -- request: - body: null - headers: - Connection: [close] - Host: [!!python/unicode translate.google.com] - !!python/unicode User-Agent: [!!python/unicode Mozilla/4.0] - method: GET - uri: http://translate.google.com/translate_a/single?tl=fr&client=a&q=Hello%2C+world%21&dt=t&sl=en&oe=UTF-8&ie=UTF-8 - response: - body: {string: !!python/unicode '[[["Bonjour le monde!","Hello, world!",,,1]],,"en"]'} - headers: - accept-ranges: [none] - cache-control: ['no-cache, no-store, must-revalidate'] - connection: [close] - content-disposition: [attachment; filename="f.txt"] - content-type: [application/json; charset=UTF-8] - date: ['Mon, 30 Nov 2015 11:56:42 GMT'] - expires: ['Fri, 01 Jan 1990 00:00:00 GMT'] - pragma: [no-cache] - server: [HTTP server (unknown)] - vary: [Accept-Encoding] - x-content-type-options: [nosniff] - x-frame-options: [SAMEORIGIN] - x-xss-protection: [1; mode=block] - status: {code: 200, message: OK} -version: 1 diff --git a/testproject/fixtures/vcr_cassettes/test_47_azure_ajax_translation.yaml b/testproject/fixtures/vcr_cassettes/test_47_azure_ajax_translation.yaml new file mode 100644 index 0000000..408c01e --- /dev/null +++ b/testproject/fixtures/vcr_cassettes/test_47_azure_ajax_translation.yaml @@ -0,0 +1,25 @@ +interactions: +- request: + body: '[{"text": "hello world"}]' + headers: + Accept: ['*/*'] + Accept-Encoding: ['gzip, deflate'] + Connection: [keep-alive] + Content-Length: ['25'] + Content-type: [application/json] + Ocp-Apim-Subscription-Key: [FAKE] + User-Agent: [python-requests/2.19.1] + X-ClientTraceId: [8d466015-2825-495a-8f12-9f88c6e227a9] + method: POST + uri: https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&from=en&to=fr + response: + body: {string: '[{"translations":[{"text":"Salut tout le monde","to":"fr"}]}]'} + headers: + Access-Control-Expose-Headers: [X-RequestId] + Content-Length: ['61'] + Content-Type: [application/json; charset=utf-8] + Date: ['Tue, 07 Aug 2018 06:18:08 GMT'] + X-Content-Type-Options: [nosniff] + X-RequestId: [TRAN.F3F4.8A3126A3] + status: {code: 200, message: OK} +version: 1 diff --git a/testproject/settings.py b/testproject/settings.py index 7d54b39..3bb9acb 100644 --- a/testproject/settings.py +++ b/testproject/settings.py @@ -115,3 +115,7 @@ SECRET_KEY = 'empty' ROSETTA_ENABLE_REFLANG = True ROSETTA_ENABLE_TRANSLATION_SUGGESTIONS = True ROSETTA_SHOW_AT_ADMIN_PANEL = True + +# fake azure key that matches the one in +# fixtures/vcr_cassettes/test_47_azure_ajax_translation.yaml +AZURE_CLIENT_SECRET = 'FAKE'