mirror of
https://github.com/Hopiu/django-rosetta.git
synced 2026-03-16 21:30:24 +00:00
Adds a test for Azure translation
This commit is contained in:
parent
e3dd1f9b91
commit
0e77a93552
6 changed files with 38 additions and 30 deletions
4
CHANGES
4
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)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
2
setup.py
2
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},
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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'
|
||||
|
|
|
|||
Loading…
Reference in a new issue