|
2 | 2 | from unittest import mock |
3 | 3 |
|
4 | 4 | import pytest |
5 | | - |
6 | 5 | from crowdin_api.api_resources.ai.enums import ( |
7 | 6 | AIPromptAction, |
| 7 | + AiPromptFineTuningJobStatus, |
8 | 8 | AIProviderType, |
| 9 | + AiReportFormat, |
| 10 | + AiToolType, |
9 | 11 | DatasetPurpose, |
10 | | - AiPromptFineTuningJobStatus, |
11 | | - ListAiPromptFineTuningJobsOrderBy, |
12 | 12 | EditAiCustomPlaceholderPatchPath, |
13 | | - AiToolType, |
14 | | - AiReportFormat, |
15 | | - EditAiSettingsPatchPath, ListSupportedAiModelsOrderBy |
| 13 | + EditAiSettingsPatchPath, |
| 14 | + ListAiPromptFineTuningJobsOrderBy, |
| 15 | + ListSupportedAiModelsOrderBy, |
16 | 16 | ) |
17 | 17 | from crowdin_api.api_resources.ai.resource import AIResource, EnterpriseAIResource |
18 | 18 | from crowdin_api.api_resources.ai.types import ( |
| 19 | + AiFileTranslationRequest, |
19 | 20 | AIPromptOperation, |
20 | | - EditAIPromptPath, |
21 | | - CreateAIPromptFineTuningJobRequest, |
22 | | - HyperParameters, |
23 | | - TrainingOptions, |
24 | | - GenerateAIPromptFineTuningDatasetRequest, |
25 | | - GenerateAiPromptCompletionRequest, |
26 | | - PreTranslateActionAiPromptContextResources, |
27 | 21 | AiTool, |
28 | | - AiToolObject, |
29 | 22 | AiToolFunction, |
30 | | - GenerateAiReportRequest, |
| 23 | + AiToolObject, |
| 24 | + AiTranslateStringsRequest, |
| 25 | + CreateAIPromptFineTuningJobRequest, |
| 26 | + EditAIPromptPath, |
31 | 27 | GeneralReportSchema, |
32 | | - AiFileTranslationRequest, |
| 28 | + GenerateAiPromptCompletionRequest, |
| 29 | + GenerateAIPromptFineTuningDatasetRequest, |
| 30 | + GenerateAiReportRequest, |
| 31 | + HyperParameters, |
| 32 | + PreTranslateActionAiPromptContextResources, |
| 33 | + TrainingOptions, |
33 | 34 | ) |
34 | 35 | from crowdin_api.api_resources.enums import PatchOperation |
35 | 36 | from crowdin_api.requester import APIRequester |
36 | | -from crowdin_api.sorting import Sorting, SortingRule, SortingOrder |
| 37 | +from crowdin_api.sorting import Sorting, SortingOrder, SortingRule |
37 | 38 |
|
38 | 39 |
|
39 | 40 | class TestAIResources: |
@@ -1205,6 +1206,64 @@ def test_download_ai_file_translation_strings(self, m_request, base_absolut_url) |
1205 | 1206 | path=f"users/{user_id}/ai/file-translations/{job_identifier}/translations", |
1206 | 1207 | ) |
1207 | 1208 |
|
| 1209 | + @pytest.mark.parametrize( |
| 1210 | + "incoming_data, request_data", |
| 1211 | + ( |
| 1212 | + ( |
| 1213 | + AiTranslateStringsRequest( |
| 1214 | + strings=["Some text to translate!"], |
| 1215 | + targetLanguageId="uk", |
| 1216 | + ), |
| 1217 | + { |
| 1218 | + "strings": ["Some text to translate!"], |
| 1219 | + "targetLanguageId": "uk", |
| 1220 | + }, |
| 1221 | + ), |
| 1222 | + ( |
| 1223 | + AiTranslateStringsRequest( |
| 1224 | + strings=["Some text to translate!"], |
| 1225 | + targetLanguageId="uk", |
| 1226 | + sourceLanguageId="en", |
| 1227 | + tmIds=[123], |
| 1228 | + glossaryIds=[456], |
| 1229 | + styleGuideIds=[654], |
| 1230 | + aiPromptId=789, |
| 1231 | + aiProviderId=12, |
| 1232 | + aiModelId="gpt-4.1", |
| 1233 | + instructions=["Keep a formal tone"], |
| 1234 | + attachmentIds=[123], |
| 1235 | + ), |
| 1236 | + { |
| 1237 | + "strings": ["Some text to translate!"], |
| 1238 | + "targetLanguageId": "uk", |
| 1239 | + "sourceLanguageId": "en", |
| 1240 | + "tmIds": [123], |
| 1241 | + "glossaryIds": [456], |
| 1242 | + "styleGuideIds": [654], |
| 1243 | + "aiPromptId": 789, |
| 1244 | + "aiProviderId": 12, |
| 1245 | + "aiModelId": "gpt-4.1", |
| 1246 | + "instructions": ["Keep a formal tone"], |
| 1247 | + "attachmentIds": [123], |
| 1248 | + }, |
| 1249 | + ), |
| 1250 | + ), |
| 1251 | + ) |
| 1252 | + @mock.patch("crowdin_api.requester.APIRequester.request") |
| 1253 | + def test_translate_ai_strings(self, m_request, incoming_data, request_data, base_absolut_url): |
| 1254 | + m_request.return_value = "response" |
| 1255 | + |
| 1256 | + user_id = 1 |
| 1257 | + |
| 1258 | + resource = self.get_resource(base_absolut_url) |
| 1259 | + assert resource.translate_ai_strings(user_id, incoming_data) == "response" |
| 1260 | + |
| 1261 | + m_request.assert_called_once_with( |
| 1262 | + method="post", |
| 1263 | + path=f"users/{user_id}/ai/translate", |
| 1264 | + request_data=request_data, |
| 1265 | + ) |
| 1266 | + |
1208 | 1267 |
|
1209 | 1268 | class TestEnterpriseAIResources: |
1210 | 1269 | resource_class = EnterpriseAIResource |
@@ -2301,3 +2360,59 @@ def test_download_ai_file_translation_strings(self, m_request, base_absolut_url) |
2301 | 2360 | method="get", |
2302 | 2361 | path=f"ai/file-translations/{job_identifier}/translations", |
2303 | 2362 | ) |
| 2363 | + |
| 2364 | + @pytest.mark.parametrize( |
| 2365 | + "incoming_data, request_data", |
| 2366 | + ( |
| 2367 | + ( |
| 2368 | + AiTranslateStringsRequest( |
| 2369 | + strings=["Some text to translate!"], |
| 2370 | + targetLanguageId="uk", |
| 2371 | + ), |
| 2372 | + { |
| 2373 | + "strings": ["Some text to translate!"], |
| 2374 | + "targetLanguageId": "uk", |
| 2375 | + }, |
| 2376 | + ), |
| 2377 | + ( |
| 2378 | + AiTranslateStringsRequest( |
| 2379 | + strings=["Some text to translate!"], |
| 2380 | + targetLanguageId="uk", |
| 2381 | + sourceLanguageId="en", |
| 2382 | + tmIds=[123], |
| 2383 | + glossaryIds=[456], |
| 2384 | + styleGuideIds=[654], |
| 2385 | + aiPromptId=789, |
| 2386 | + aiProviderId=12, |
| 2387 | + aiModelId="gpt-4.1", |
| 2388 | + instructions=["Keep a formal tone"], |
| 2389 | + attachmentIds=[123], |
| 2390 | + ), |
| 2391 | + { |
| 2392 | + "strings": ["Some text to translate!"], |
| 2393 | + "targetLanguageId": "uk", |
| 2394 | + "sourceLanguageId": "en", |
| 2395 | + "tmIds": [123], |
| 2396 | + "glossaryIds": [456], |
| 2397 | + "styleGuideIds": [654], |
| 2398 | + "aiPromptId": 789, |
| 2399 | + "aiProviderId": 12, |
| 2400 | + "aiModelId": "gpt-4.1", |
| 2401 | + "instructions": ["Keep a formal tone"], |
| 2402 | + "attachmentIds": [123], |
| 2403 | + }, |
| 2404 | + ), |
| 2405 | + ), |
| 2406 | + ) |
| 2407 | + @mock.patch("crowdin_api.requester.APIRequester.request") |
| 2408 | + def test_translate_ai_strings(self, m_request, incoming_data, request_data, base_absolut_url): |
| 2409 | + m_request.return_value = "response" |
| 2410 | + |
| 2411 | + resource = self.get_resource(base_absolut_url) |
| 2412 | + assert resource.translate_ai_strings(incoming_data) == "response" |
| 2413 | + |
| 2414 | + m_request.assert_called_once_with( |
| 2415 | + method="post", |
| 2416 | + path="ai/translate", |
| 2417 | + request_data=request_data, |
| 2418 | + ) |
0 commit comments