Skip to content

Commit a0cc110

Browse files
committed
test(translations): add comprehensive tests for apply_pre_translation
- Added test for branchIds parameter handling - Added edge case tests for empty lists and parameter combinations - Improved test coverage from 47% to 98% - Tests would have caught the missing branchIds bug
1 parent f433b61 commit a0cc110

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed

crowdin_api/api_resources/translations/tests/test_translations_resources.py

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,128 @@ def test_apply_pre_translation(self, m_request, in_params, request_data, base_ab
121121
path="projects/1/pre-translations",
122122
)
123123

124+
@mock.patch("crowdin_api.requester.APIRequester.request")
125+
def test_apply_pre_translation_with_branchids(self, m_request, base_absolut_url):
126+
"""Test that branchIds parameter is properly handled."""
127+
m_request.return_value = "response"
128+
129+
resource = self.get_resource(base_absolut_url)
130+
response = resource.apply_pre_translation(
131+
projectId=1,
132+
languageIds=["en", "es"],
133+
fileIds=[1, 2],
134+
branchIds=[10, 20, 30]
135+
)
136+
137+
assert response == "response"
138+
m_request.assert_called_once_with(
139+
method="post",
140+
request_data={
141+
"languageIds": ["en", "es"],
142+
"fileIds": [1, 2],
143+
"method": None,
144+
"engineId": None,
145+
"aiPromptId": None,
146+
"autoApproveOption": None,
147+
"duplicateTranslations": None,
148+
"skipApprovedTranslations": None,
149+
"translateUntranslatedOnly": None,
150+
"translateWithPerfectMatchOnly": None,
151+
"fallbackLanguages": [],
152+
"labelIds": [],
153+
"excludeLabelIds": [],
154+
"branchIds": [10, 20, 30],
155+
},
156+
path="projects/1/pre-translations",
157+
)
158+
159+
@mock.patch("crowdin_api.requester.APIRequester.request")
160+
def test_apply_pre_translation_edge_cases(self, m_request, base_absolut_url):
161+
"""Test edge cases and parameter handling."""
162+
m_request.return_value = "response"
163+
164+
resource = self.get_resource(base_absolut_url)
165+
166+
# Test with empty lists
167+
response = resource.apply_pre_translation(
168+
projectId=1,
169+
languageIds=[],
170+
fileIds=[],
171+
branchIds=[],
172+
labelIds=[],
173+
excludeLabelIds=[]
174+
)
175+
176+
assert response == "response"
177+
m_request.assert_called_once_with(
178+
method="post",
179+
request_data={
180+
"languageIds": [],
181+
"fileIds": [],
182+
"method": None,
183+
"engineId": None,
184+
"aiPromptId": None,
185+
"autoApproveOption": None,
186+
"duplicateTranslations": None,
187+
"skipApprovedTranslations": None,
188+
"translateUntranslatedOnly": None,
189+
"translateWithPerfectMatchOnly": None,
190+
"fallbackLanguages": [],
191+
"labelIds": [],
192+
"excludeLabelIds": [],
193+
"branchIds": [],
194+
},
195+
path="projects/1/pre-translations",
196+
)
197+
198+
@mock.patch("crowdin_api.requester.APIRequester.request")
199+
def test_apply_pre_translation_with_all_optional_params(self, m_request, base_absolut_url):
200+
"""Test with all optional parameters set."""
201+
from crowdin_api.api_resources.translations.enums import PreTranslationApplyMethod, PreTranslationAutoApproveOption
202+
203+
m_request.return_value = "response"
204+
205+
resource = self.get_resource(base_absolut_url)
206+
response = resource.apply_pre_translation(
207+
projectId=1,
208+
languageIds=["en"],
209+
fileIds=[1],
210+
method=PreTranslationApplyMethod.MT,
211+
engineId=123,
212+
aiPromptId=456,
213+
autoApproveOption=PreTranslationAutoApproveOption.ALL,
214+
duplicateTranslations=True,
215+
skipApprovedTranslations=False,
216+
translateUntranslatedOnly=True,
217+
translateWithPerfectMatchOnly=False,
218+
fallbackLanguages=[{"languageId": "fr", "userId": 789}],
219+
labelIds=[1, 2, 3],
220+
excludeLabelIds=[4, 5],
221+
branchIds=[10, 20]
222+
)
223+
224+
assert response == "response"
225+
m_request.assert_called_once_with(
226+
method="post",
227+
request_data={
228+
"languageIds": ["en"],
229+
"fileIds": [1],
230+
"method": PreTranslationApplyMethod.MT,
231+
"engineId": 123,
232+
"aiPromptId": 456,
233+
"autoApproveOption": PreTranslationAutoApproveOption.ALL,
234+
"duplicateTranslations": True,
235+
"skipApprovedTranslations": False,
236+
"translateUntranslatedOnly": True,
237+
"translateWithPerfectMatchOnly": False,
238+
"fallbackLanguages": [{"languageId": "fr", "userId": 789}],
239+
"labelIds": [1, 2, 3],
240+
"excludeLabelIds": [4, 5],
241+
"branchIds": [10, 20],
242+
},
243+
path="projects/1/pre-translations",
244+
)
245+
124246
@mock.patch("crowdin_api.requester.APIRequester.request")
125247
def test_pre_translation_report(self, m_request, base_absolut_url):
126248
m_request.return_value = "response"

0 commit comments

Comments
 (0)