OLD | NEW |
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 import contextlib | 16 import contextlib |
17 import os | 17 import os |
18 import signal | 18 import signal |
19 import subprocess | 19 import subprocess |
20 import time | 20 import time |
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.translations.xtm.projects_handler import ( |
| 27 create_project, upload_files, download_files, |
| 28 ) |
| 29 |
26 | 30 |
27 def get_dir_contents(path): | 31 def get_dir_contents(path): |
28 # TODO: This function is duplicated in test_page_outputs.py. | 32 # TODO: This function is duplicated in test_page_outputs.py. |
29 dirdata = {} | 33 dirdata = {} |
30 for dirpath, dirnames, filenames in os.walk(path): | 34 for dirpath, dirnames, filenames in os.walk(path): |
31 for output_file in filenames: | 35 for output_file in filenames: |
32 filepath = os.path.join(dirpath, output_file) | 36 filepath = os.path.join(dirpath, output_file) |
33 with open(filepath) as f: | 37 with open(filepath) as f: |
34 locale = os.path.split(os.path.split(filepath)[0])[1] | 38 locale = os.path.split(os.path.split(filepath)[0])[1] |
35 dirdata[os.path.join(locale, output_file)] = f.read().strip() | 39 dirdata[os.path.join(locale, output_file)] = f.read().strip() |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 | 77 |
74 with zipfile.ZipFile(memory_zip, 'w') as zf: | 78 with zipfile.ZipFile(memory_zip, 'w') as zf: |
75 for idx in range(len(file_names)): | 79 for idx in range(len(file_names)): |
76 zf.writestr(file_names[idx], file_data[idx], zipfile.ZIP_DEFLATED) | 80 zf.writestr(file_names[idx], file_data[idx], zipfile.ZIP_DEFLATED) |
77 | 81 |
78 memory_zip.seek(0) | 82 memory_zip.seek(0) |
79 return memory_zip | 83 return memory_zip |
80 | 84 |
81 | 85 |
82 def exception_test(func, exception, exp_msg, *args, **kw): | 86 def exception_test(func, exception, exp_msg, *args, **kw): |
| 87 """Test if a function raises the correct exception. |
| 88 |
| 89 Parameters |
| 90 ---------- |
| 91 func: function |
| 92 The function we're testing. |
| 93 exception: classobj |
| 94 The exception we expect to be raised. |
| 95 exp_msg: str |
| 96 The message we expect the exception to contain. |
| 97 |
| 98 """ |
83 with pytest.raises(exception) as err: | 99 with pytest.raises(exception) as err: |
84 func(*args, **kw) | 100 func(*args, **kw) |
85 | 101 |
86 assert exp_msg in str(err.value) | 102 assert exp_msg in str(err.value) |
| 103 |
| 104 |
| 105 class XtmMockArgs: |
| 106 """Mock arguments for the XTM integration script.""" |
| 107 |
| 108 class CreationArgsNamespace: |
| 109 """Mock arguments for creating a new XTM project.""" |
| 110 |
| 111 name = 'bar' |
| 112 desc = 'foo' |
| 113 client_id = 10 |
| 114 ref_id = 'faz' |
| 115 workflow_id = 20 |
| 116 save_id = False |
| 117 source_dir = None |
| 118 projects_func = staticmethod(create_project) |
| 119 source_lang = 'en_US' |
| 120 workflow_name = None |
| 121 |
| 122 class UploadArgsNamespace: |
| 123 """Mock arguments for uploading files to XTM for translation.""" |
| 124 |
| 125 source_dir = None |
| 126 projects_func = staticmethod(upload_files) |
| 127 no_overwrite = False |
| 128 |
| 129 class DownloadArgsNamespace: |
| 130 """Mock arguments for downloading translation from XTM.""" |
| 131 |
| 132 source_dir = None |
| 133 projects_func = staticmethod(download_files) |
OLD | NEW |