From 51b4b9a67a9f50b0073a261df477ffd57cf8279c Mon Sep 17 00:00:00 2001 From: Anatoly Artamonov Date: Thu, 29 Aug 2024 23:07:23 +0200 Subject: [PATCH] RPS-7890. Update api-python-sdk to the latest version --- builder/ApiSource.py | 10 ---------- changes.txt | 3 +++ setup.py | 4 ++-- smartlingApiSdk/api/AccountProjectsApi.py | 4 +++- smartlingApiSdk/api/ContextApi.py | 3 ++- smartlingApiSdk/api/EstimatesApi.py | 4 ++-- smartlingApiSdk/api/FilesApi.py | 4 +--- smartlingApiSdk/api/JobsApi.py | 4 ++-- smartlingApiSdk/api/TagsApi.py | 21 +++++++++++++++++++++ smartlingApiSdk/example/FilesExample.py | 3 +-- smartlingApiSdk/example/TagsExample.py | 4 ++++ smartlingApiSdk/version.py | 2 +- test/testApiChanges.py | 2 ++ test/testFiles.py | 3 +-- test/testJobs.py | 1 + test/testTags.py | 4 ++++ 16 files changed, 50 insertions(+), 26 deletions(-) diff --git a/builder/ApiSource.py b/builder/ApiSource.py index e492210..0d49aa9 100644 --- a/builder/ApiSource.py +++ b/builder/ApiSource.py @@ -44,16 +44,6 @@ def collectMethods(self, swaggerDict): self.methods.append(m) def patchMethods(self, descr, m, swaggerDict): - if descr['operationId'] == 'exportFileTranslations': - propDict = { - "type": "string", - "format": "binary", - "description": "The file contents to upload." - } - mp = MultipartProperty('file', propDict, swaggerDict) - mp.setRequired() - m.needMultipart = True - m.multipartParameters.insert(0, mp) if descr['operationId'] in ('getAllSourceStringsByProject'): m.method = 'post' m.isJson = True diff --git a/changes.txt b/changes.txt index 7030da8..36da6cd 100644 --- a/changes.txt +++ b/changes.txt @@ -1,3 +1,6 @@ +Aug 29, 2024 - 3.1.6 + - updated according the latest changes in Smartling SDK + Dec 09, 2022 - 3.1.5 - fix of ApiResponse get attribute may cause stack overflow on requesting non-existng attribute diff --git a/setup.py b/setup.py index c6ca7b0..13a8839 100644 --- a/setup.py +++ b/setup.py @@ -28,9 +28,9 @@ description="python library to work with Smartling translation services APIs", license='Apache License v2.0', keywords='translation localization internationalization', - url="https://api-reference.smartling.com/", + url="", long_description="python SDK to work with Smartling API for computer assisted translation", - packages=['smartlingApiSdk','smartlingApiSdk/example','smartlingApiSdk/api'], + packages=['smartlingApiSdk','smartlingApiSdk/example','smartlingApiSdk/api','smartlingApiSdk/resources'], include_package_data = True, package_data = { '': ['*.properties', '*.xml', '*.png', '*.csv'], diff --git a/smartlingApiSdk/api/AccountProjectsApi.py b/smartlingApiSdk/api/AccountProjectsApi.py index bc039a5..02b7408 100644 --- a/smartlingApiSdk/api/AccountProjectsApi.py +++ b/smartlingApiSdk/api/AccountProjectsApi.py @@ -26,7 +26,7 @@ class AccountProjectsApi(ApiV2): def __init__(self, userIdentifier, userSecret, projectId, proxySettings=None, permanentHeaders={}, env='prod'): ApiV2.__init__(self, userIdentifier, userSecret, projectId, proxySettings, permanentHeaders=permanentHeaders, env=env) - def getProjectsByAccount(self, accountUid, projectNameFilter='', includeArchived='', offset=0, limit=0, **kwargs): + def getProjectsByAccount(self, accountUid, projectNameFilter='', includeArchived='', offset=0, limit=0, projectTypeCode='', projectTypeCodes=[], **kwargs): """ method : GET api url : /accounts-api/v2/accounts/{accountUid}/projects @@ -40,6 +40,8 @@ def getProjectsByAccount(self, accountUid, projectNameFilter='', includeArchived 'includeArchived':includeArchived, 'offset':offset, 'limit':limit, + 'projectTypeCode':projectTypeCode, + 'projectTypeCodes':projectTypeCodes, } kw.update(kwargs) url = self.urlHelper.getUrl('/accounts-api/v2/accounts/{accountUid}/projects', accountUid=accountUid, **kwargs) diff --git a/smartlingApiSdk/api/ContextApi.py b/smartlingApiSdk/api/ContextApi.py index 9ccaa2b..2e5500b 100644 --- a/smartlingApiSdk/api/ContextApi.py +++ b/smartlingApiSdk/api/ContextApi.py @@ -131,7 +131,7 @@ def downloadVisualContextFileContent(self, contextUid, **kwargs): return response, status - def runAutomaticContextMatching(self, contextUid, contentFileUri='', stringHashcodes=[], translationJobUids=[], overrideContextOlderThanDays=0, **kwargs): + def runAutomaticContextMatching(self, contextUid, contentFileUri='', stringHashcodes=[], translationJobUids=[], overrideContextOlderThanDays=0, videoMatchingMode='', **kwargs): """ method : POST api url : /context-api/v2/projects/{projectId}/contexts/{contextUid}/match/async @@ -145,6 +145,7 @@ def runAutomaticContextMatching(self, contextUid, contentFileUri='', stringHashc 'stringHashcodes':stringHashcodes, 'translationJobUids':translationJobUids, 'overrideContextOlderThanDays':overrideContextOlderThanDays, + 'videoMatchingMode':videoMatchingMode, } kw.update(kwargs) url = self.urlHelper.getUrl('/context-api/v2/projects/{projectId}/contexts/{contextUid}/match/async', contextUid=contextUid, **kwargs) diff --git a/smartlingApiSdk/api/EstimatesApi.py b/smartlingApiSdk/api/EstimatesApi.py index 4241c04..468b855 100644 --- a/smartlingApiSdk/api/EstimatesApi.py +++ b/smartlingApiSdk/api/EstimatesApi.py @@ -51,7 +51,7 @@ def getJobFuzzyEstimateReports(self, translationJobUid, reportStatus='', content return response, status - def generateJobFuzzyEstimateReports(self, translationJobUid, contentType='', tags=[], **kwargs): + def generateJobFuzzyEstimateReports(self, translationJobUid, contentType='ALL_CONTENT', tags=[], **kwargs): """ method : POST api url : /estimates-api/v2/projects/{projectId}/jobs/{translationJobUid}/reports/fuzzy @@ -94,7 +94,7 @@ def getJobCostEstimateReports(self, translationJobUid, reportStatus='', contentC return response, status - def generateJobCostEstimateReports(self, translationJobUid, contentType='', tags=[], localeWorkflows=[], fuzzyProfileUid='', **kwargs): + def generateJobCostEstimateReports(self, translationJobUid, contentType='ALL_CONTENT', tags=[], localeWorkflows=[], fuzzyProfileUid='', **kwargs): """ method : POST api url : /estimates-api/v2/projects/{projectId}/jobs/{translationJobUid}/reports/cost diff --git a/smartlingApiSdk/api/FilesApi.py b/smartlingApiSdk/api/FilesApi.py index 11cb9ee..159f8ab 100644 --- a/smartlingApiSdk/api/FilesApi.py +++ b/smartlingApiSdk/api/FilesApi.py @@ -26,7 +26,7 @@ class FilesApi(ApiV2): def __init__(self, userIdentifier, userSecret, projectId, proxySettings=None, permanentHeaders={}, env='prod'): ApiV2.__init__(self, userIdentifier, userSecret, projectId, proxySettings, permanentHeaders=permanentHeaders, env=env) - def uploadSourceFile(self, file, fileUri, fileType, authorize=False, localeIdsToAuthorize=[], callbackUrl='', directives={}, **kwargs): + def uploadSourceFile(self, file, fileUri, fileType, callbackUrl='', directives={}, **kwargs): """ method : POST api url : /files-api/v2/projects/{projectId}/file @@ -41,8 +41,6 @@ def uploadSourceFile(self, file, fileUri, fileType, authorize=False, localeIdsTo 'file':self.processFile(file), 'fileUri':fileUri, 'fileType':fileType, - 'authorize':authorize, - 'localeIdsToAuthorize':localeIdsToAuthorize, 'callbackUrl':callbackUrl, } self.addLibIdDirective(kw) diff --git a/smartlingApiSdk/api/JobsApi.py b/smartlingApiSdk/api/JobsApi.py index 2a44244..a2aa5e6 100644 --- a/smartlingApiSdk/api/JobsApi.py +++ b/smartlingApiSdk/api/JobsApi.py @@ -121,7 +121,7 @@ def findJobsByStrings(self, hashcodes=[], localeIds=[], **kwargs): return response, status - def getStringsForTranslationJob(self, translationJobUid, targetLocaleId='', limit=0, offset=0, **kwargs): + def getStringsForTranslationJob(self, translationJobUid, targetLocaleId='', limit=1000, offset=0, **kwargs): """ method : GET api url : /jobs-api/v3/projects/{projectId}/jobs/{translationJobUid}/strings @@ -371,7 +371,7 @@ def removeFileFromJob(self, translationJobUid, fileUri='', **kwargs): return response, status - def getJobFilesList(self, translationJobUid, limit=0, offset=0, **kwargs): + def getJobFilesList(self, translationJobUid, limit=1000, offset=0, **kwargs): """ method : GET api url : /jobs-api/v3/projects/{projectId}/jobs/{translationJobUid}/files diff --git a/smartlingApiSdk/api/TagsApi.py b/smartlingApiSdk/api/TagsApi.py index 6406542..afba1bf 100644 --- a/smartlingApiSdk/api/TagsApi.py +++ b/smartlingApiSdk/api/TagsApi.py @@ -26,6 +26,27 @@ class TagsApi(ApiV2): def __init__(self, userIdentifier, userSecret, projectId, proxySettings=None, permanentHeaders={}, env='prod'): ApiV2.__init__(self, userIdentifier, userSecret, projectId, proxySettings, permanentHeaders=permanentHeaders, env=env) + def getTagsListByAccount(self, accountUid, projectIds=[], tagMask='', limit=1500, offset=0, **kwargs): + """ + method : POST + api url : /tags-api/v2/accounts/{accountUid}/tags + as curl : curl -H "Authorization: Bearer $smartlingToken" https://api.smartling.com/tags-api/v2/accounts/$smartlingAccountUid/tags + Responses: + 200 : OK + details : https://api-reference.smartling.com/#operation/getTagsListByAccount + """ + kw = { + 'projectIds':projectIds, + 'tagMask':tagMask, + 'limit':limit, + 'offset':offset, + } + kw.update(kwargs) + url = self.urlHelper.getUrl('/tags-api/v2/accounts/{accountUid}/tags', accountUid=accountUid, **kwargs) + response, status = self.commandJson('POST', url, kw) + return response, status + + def getTagsListByProject(self, tagMask='', limit=100, offset=0, **kwargs): """ method : GET diff --git a/smartlingApiSdk/example/FilesExample.py b/smartlingApiSdk/example/FilesExample.py index ec60d35..15e3918 100644 --- a/smartlingApiSdk/example/FilesExample.py +++ b/smartlingApiSdk/example/FilesExample.py @@ -133,8 +133,7 @@ def checkUploadSourceFile(self): file=self.FILE_PATH + self.FILE_NAME fileUri=self.uri fileType=self.FILE_TYPE - localeIdsToAuthorize=[self.MY_LOCALE] - res, status = self.files_api.uploadSourceFile(file=file, fileUri=fileUri, fileType=fileType, localeIdsToAuthorize=localeIdsToAuthorize) + res, status = self.files_api.uploadSourceFile(file=file, fileUri=fileUri, fileType=fileType) assert_equal(res.data.wordCount, 6) diff --git a/smartlingApiSdk/example/TagsExample.py b/smartlingApiSdk/example/TagsExample.py index 5ba55e6..7fae8ea 100644 --- a/smartlingApiSdk/example/TagsExample.py +++ b/smartlingApiSdk/example/TagsExample.py @@ -204,6 +204,10 @@ def example(): t.checkRemoveTagsFromStrings() t.checkAddTagToStrings() t.checkRemoveAllTagsFromStrings() + # not covered by tests # + ''' + getTagsListByAccount + ''' t.tearDown() if __name__ == '__main__': diff --git a/smartlingApiSdk/version.py b/smartlingApiSdk/version.py index ed0ec99..b815467 100644 --- a/smartlingApiSdk/version.py +++ b/smartlingApiSdk/version.py @@ -17,4 +17,4 @@ * limitations under the License. """ -version = "3.1.5" +version = "3.1.6" diff --git a/test/testApiChanges.py b/test/testApiChanges.py index 33ea0df..caecc22 100644 --- a/test/testApiChanges.py +++ b/test/testApiChanges.py @@ -71,6 +71,8 @@ def testAll(self): if 'JobBatchesV2' == api_name: api_name = 'Job Batches V2' + continue # api description is moved to yaml format whuch is not supported yet: + # "/job-batches-api/v2/projects/{projectId}/batches": { "$ref": "./spec/job_batches_v2/job_batches_endpoints.yaml#/x-paths/create_list_batches" print ("Cheking:%s" % api_name) apisrc = ApiBuilder(api_name).apisrc diff --git a/test/testFiles.py b/test/testFiles.py index 4a1cc37..73e673f 100644 --- a/test/testFiles.py +++ b/test/testFiles.py @@ -133,8 +133,7 @@ def checkUploadSourceFile(self): file=self.FILE_PATH + self.FILE_NAME fileUri=self.uri fileType=self.FILE_TYPE - localeIdsToAuthorize=[self.MY_LOCALE] - res, status = self.files_api.uploadSourceFile(file=file, fileUri=fileUri, fileType=fileType, localeIdsToAuthorize=localeIdsToAuthorize) + res, status = self.files_api.uploadSourceFile(file=file, fileUri=fileUri, fileType=fileType) assert_equal(res.data.wordCount, 6) diff --git a/test/testJobs.py b/test/testJobs.py index dcdcfc7..d64b468 100644 --- a/test/testJobs.py +++ b/test/testJobs.py @@ -562,6 +562,7 @@ def checkCancelJob(self): assert_equal(True, status in [200,202]) assert_equal(True, res.code in [self.CODE_SUCCESS_TOKEN, self.ACCEPTED_TOKEN]) + time.sleep(15) #wait for job to be cancelled print('cancelJob', 'OK') diff --git a/test/testTags.py b/test/testTags.py index 3319834..e856cee 100644 --- a/test/testTags.py +++ b/test/testTags.py @@ -203,3 +203,7 @@ def test_all(self): t.checkRemoveTagsFromStrings() t.checkAddTagToStrings() t.checkRemoveAllTagsFromStrings() + # not covered by tests # + ''' + getTagsListByAccount + '''