| LEFT | RIGHT |
| 1 # This file is part of the Adblock Plus web scripts, | 1 # This file is part of the Adblock Plus web scripts, |
| 2 # Copyright (C) 2006-present eyeo GmbH | 2 # Copyright (C) 2006-present eyeo GmbH |
| 3 # | 3 # |
| 4 # Adblock Plus is free software: you can redistribute it and/or modify | 4 # Adblock Plus is free software: you can redistribute it and/or modify |
| 5 # it under the terms of the GNU General Public License version 3 as | 5 # it under the terms of the GNU General Public License version 3 as |
| 6 # published by the Free Software Foundation. | 6 # published by the Free Software Foundation. |
| 7 # | 7 # |
| 8 # Adblock Plus is distributed in the hope that it will be useful, | 8 # Adblock Plus is distributed in the hope that it will be useful, |
| 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 # GNU General Public License for more details. | 11 # GNU General Public License for more details. |
| 12 # | 12 # |
| 13 # You should have received a copy of the GNU General Public License | 13 # You should have received a copy of the GNU General Public License |
| 14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 15 | 15 |
| 16 """Tests for the XTM API integration.""" | 16 """Tests for the XTM API integration.""" |
| 17 | 17 |
| 18 from __future__ import unicode_literals | 18 from __future__ import unicode_literals |
| 19 | 19 |
| 20 import json | 20 import json |
| 21 import zipfile | 21 import zipfile |
| 22 from io import BytesIO | 22 from io import BytesIO |
| 23 | 23 |
| 24 import pytest | 24 import pytest |
| 25 | 25 |
| 26 from cms.bin.xtm_translations.xtm_api import (XTMCloudException, XTMCloudAPI, | 26 from cms.translations.xtm.xtm_api import (XTMCloudException, XTMCloudAPI, |
| 27 get_token) | 27 get_token) |
| 28 from tests.utils import exception_test | 28 from tests.utils import exception_test |
| 29 | 29 |
| 30 _VALID_TOKEN = 'TheXTM-APIToken-VALID' | 30 _VALID_TOKEN = 'TheXTM-APIToken-VALID' |
| 31 _INVALID_TOKEN = 'TheXTM-APIToken-INVALID' | 31 _INVALID_TOKEN = 'TheXTM-APIToken-INVALID' |
| 32 | 32 |
| 33 _FILES_UPLOAD = {'test.json': json.dumps({'foo': 'bar'})} | 33 _FILES_UPLOAD = {'test.json': json.dumps({'foo': 'bar'})} |
| 34 _EXPECTED_JOBS = [{'fileName': 'test.json', 'jobId': 1, | 34 _EXPECTED_JOBS = [{'fileName': 'test.json', 'jobId': 1, |
| 35 'sourceLanguage': 'en_US', 'targetLanguage': 'de_DE'}] | 35 'sourceLanguage': 'en_US', 'targetLanguage': 'de_DE'}] |
| 36 | 36 |
| 37 | 37 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 (_VALID_TOKEN, 1234, _FILES_UPLOAD, None, None, _EXPECTED_JOBS), | 131 (_VALID_TOKEN, 1234, _FILES_UPLOAD, None, None, _EXPECTED_JOBS), |
| 132 ]) | 132 ]) |
| 133 def test_file_upload(intercept, token, project_id, files, exp_err, exp_msg, | 133 def test_file_upload(intercept, token, project_id, files, exp_err, exp_msg, |
| 134 exp_jobs): | 134 exp_jobs): |
| 135 """Test file uploading.""" | 135 """Test file uploading.""" |
| 136 api = XTMCloudAPI(token) | 136 api = XTMCloudAPI(token) |
| 137 if exp_msg is not None: | 137 if exp_msg is not None: |
| 138 exception_test(api.upload_files, exp_err, exp_msg, files, project_id) | 138 exception_test(api.upload_files, exp_err, exp_msg, files, project_id) |
| 139 else: | 139 else: |
| 140 assert exp_jobs == api.upload_files(files, project_id) | 140 assert exp_jobs == api.upload_files(files, project_id) |
| LEFT | RIGHT |