From 60b8d5d20acaf858ac9be37ddb512acbc7d7176e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chr=C3=A1stek=20Martin?= Date: Mon, 26 Jun 2023 16:29:24 +0200 Subject: [PATCH 1/3] feat: Serialize datetime in Job Create DTO into JSON --- README.md | 2 +- phrasetms_client/__init__.py | 2 +- phrasetms_client/configuration.py | 2 +- .../models/job_create_request_dto.py | 3 +- phrasetms_client/utils.py | 9 ++++ pyproject.toml | 2 +- setup.py | 2 +- test/test_job_api.py | 54 ++++++++++++++++++- 8 files changed, 69 insertions(+), 7 deletions(-) create mode 100644 phrasetms_client/utils.py diff --git a/README.md b/README.md index 6b13c313..09e14e51 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Please, include the `User-Agent` header with the name of your application or pro This Python package is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project: - API version: Latest -- Package version: 0.3.0 +- Package version: 0.3.1 - Build package: org.openapitools.codegen.languages.PythonClientCodegen ## Requirements. diff --git a/phrasetms_client/__init__.py b/phrasetms_client/__init__.py index e98e657e..29abb778 100644 --- a/phrasetms_client/__init__.py +++ b/phrasetms_client/__init__.py @@ -14,7 +14,7 @@ """ -__version__ = "0.3.0" +__version__ = "0.3.1" # import apis into sdk package from phrasetms_client.api.additional_workflow_step_api import AdditionalWorkflowStepApi diff --git a/phrasetms_client/configuration.py b/phrasetms_client/configuration.py index 7ce21389..42ff2553 100644 --- a/phrasetms_client/configuration.py +++ b/phrasetms_client/configuration.py @@ -423,7 +423,7 @@ def to_debug_report(self): "OS: {env}\n" "Python Version: {pyversion}\n" "Version of the API: Latest\n" - "SDK Package Version: 0.3.0".format(env=sys.platform, pyversion=sys.version) + "SDK Package Version: 0.3.1".format(env=sys.platform, pyversion=sys.version) ) def get_host_settings(self): diff --git a/phrasetms_client/models/job_create_request_dto.py b/phrasetms_client/models/job_create_request_dto.py index 922975e4..128b3590 100644 --- a/phrasetms_client/models/job_create_request_dto.py +++ b/phrasetms_client/models/job_create_request_dto.py @@ -25,6 +25,7 @@ from phrasetms_client.models.providers_per_language import ProvidersPerLanguage from phrasetms_client.models.uid_reference import UidReference from phrasetms_client.models.workflow_step_configuration import WorkflowStepConfiguration +from phrasetms_client.utils import DateTimeEncoder class JobCreateRequestDto(BaseModel): """ @@ -54,7 +55,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - return json.dumps(self.to_dict()) + return json.dumps(self.to_dict(), cls=DateTimeEncoder) @classmethod def from_json(cls, json_str: str) -> JobCreateRequestDto: diff --git a/phrasetms_client/utils.py b/phrasetms_client/utils.py new file mode 100644 index 00000000..49cb59a9 --- /dev/null +++ b/phrasetms_client/utils.py @@ -0,0 +1,9 @@ +from datetime import datetime +import json + +class DateTimeEncoder(json.JSONEncoder): + def default(self, o): + if isinstance(o, datetime): + return o.isoformat() + + return super().default(o) \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 53acfbd5..28e1b41b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "phrasetms_client" -version = "0.3.0" +version = "0.3.1" description = "Phrase TMS API" authors = ["Martin Chrástek"] license = "NoLicense" diff --git a/setup.py b/setup.py index 0deeda1b..aaa86ebb 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ # prerequisite: setuptools # http://pypi.python.org/pypi/setuptools NAME = "phrasetms-client" -VERSION = "0.3.0" +VERSION = "0.3.1" PYTHON_REQUIRES = ">=3.7" REQUIRES = ["urllib3 >= 1.25.3", "python-dateutil", "pydantic >= 1.10.5, < 2", "aenum"] diff --git a/test/test_job_api.py b/test/test_job_api.py index 96dfcadf..70e5a5b5 100644 --- a/test/test_job_api.py +++ b/test/test_job_api.py @@ -12,6 +12,7 @@ """ +from datetime import datetime, timezone import unittest import phrasetms_client @@ -61,6 +62,57 @@ def test_create_job(self): Create job # noqa: E501 """ + # Defining the host is optional and defaults to https://cloud.memsource.com/web + # See configuration.py for a list of all supported configuration parameters. + configuration = phrasetms_client.Configuration( + host="https://cloud.memsource.com/web" + ) + + # Enter a context with an instance of the API client + with phrasetms_client.ApiClient(configuration) as api_client: + # Create an instance of the API class + api_instance = phrasetms_client.JobApi(api_client) + project_uid = "project_uid_example" # str | + workflow_settings = [ + phrasetms_client.WorkflowStepConfiguration( + assignments=[ + phrasetms_client.ProvidersPerLanguage( + targetLang="cs_cz", + providers=[ + phrasetms_client.ProviderReference( + type="USER", id="id_example", uid="uid_example" + ) + ], + ) + ], + due=datetime(2024, 1, 2, 3, 4, 5, 6, tzinfo=timezone.utc), + notify_provider=phrasetms_client.NotifyProviderDto( + organizationEmailTemplate=phrasetms_client.IdReference( + id="id_example" + ), + ), + ) + ] + memsource = phrasetms_client.JobCreateRequestDto( + target_langs=["cs_cz", "de_de"], + due=datetime(2024, 4, 5, 6, 7, 8, 9, tzinfo=timezone.utc), + workflow_settings=workflow_settings, + ).to_json() + content_disposition = "content_disposition_example" # str | must match pattern `((inline|attachment); )?(filename\\*=UTF-8''(.+)|filename=\"?(.+)\"?)` (optional) + body = None # object | (optional) + + try: + # Create job + api_response = api_instance.create_job( + project_uid, + memsource=memsource, + content_disposition=content_disposition, + body=body, + ) + print("The response of JobApi->create_job:\n") + + except Exception as e: + print("Exception when calling JobApi->create_job: %s\n" % e) pass def test_create_job_from_async_download_task(self): @@ -386,5 +438,5 @@ def test_wild_card_search_by_job3(self): pass -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() From 364bde1111781142c2e62349680861a56e6be09b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chr=C3=A1stek=20Martin?= Date: Mon, 26 Jun 2023 16:34:38 +0200 Subject: [PATCH 2/3] chore: Revert implementation of test --- test/test_job_api.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_job_api.py b/test/test_job_api.py index 70e5a5b5..e7238c8f 100644 --- a/test/test_job_api.py +++ b/test/test_job_api.py @@ -98,7 +98,7 @@ def test_create_job(self): due=datetime(2024, 4, 5, 6, 7, 8, 9, tzinfo=timezone.utc), workflow_settings=workflow_settings, ).to_json() - content_disposition = "content_disposition_example" # str | must match pattern `((inline|attachment); )?(filename\\*=UTF-8''(.+)|filename=\"?(.+)\"?)` (optional) + content_disposition = 'filename="test.xlsx"' # str | must match pattern `((inline|attachment); )?(filename\\*=UTF-8''(.+)|filename=\"?(.+)\"?)` (optional) body = None # object | (optional) try: @@ -110,6 +110,7 @@ def test_create_job(self): body=body, ) print("The response of JobApi->create_job:\n") + pprint(api_response) except Exception as e: print("Exception when calling JobApi->create_job: %s\n" % e) From 88f6b183b72ba776ec974833078f758a44b82510 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chr=C3=A1stek=20Martin?= Date: Mon, 26 Jun 2023 16:50:34 +0200 Subject: [PATCH 3/3] chore: Revert implementation of test --- test/test_job_api.py | 55 +------------------------------------------- 1 file changed, 1 insertion(+), 54 deletions(-) diff --git a/test/test_job_api.py b/test/test_job_api.py index e7238c8f..96dfcadf 100644 --- a/test/test_job_api.py +++ b/test/test_job_api.py @@ -12,7 +12,6 @@ """ -from datetime import datetime, timezone import unittest import phrasetms_client @@ -62,58 +61,6 @@ def test_create_job(self): Create job # noqa: E501 """ - # Defining the host is optional and defaults to https://cloud.memsource.com/web - # See configuration.py for a list of all supported configuration parameters. - configuration = phrasetms_client.Configuration( - host="https://cloud.memsource.com/web" - ) - - # Enter a context with an instance of the API client - with phrasetms_client.ApiClient(configuration) as api_client: - # Create an instance of the API class - api_instance = phrasetms_client.JobApi(api_client) - project_uid = "project_uid_example" # str | - workflow_settings = [ - phrasetms_client.WorkflowStepConfiguration( - assignments=[ - phrasetms_client.ProvidersPerLanguage( - targetLang="cs_cz", - providers=[ - phrasetms_client.ProviderReference( - type="USER", id="id_example", uid="uid_example" - ) - ], - ) - ], - due=datetime(2024, 1, 2, 3, 4, 5, 6, tzinfo=timezone.utc), - notify_provider=phrasetms_client.NotifyProviderDto( - organizationEmailTemplate=phrasetms_client.IdReference( - id="id_example" - ), - ), - ) - ] - memsource = phrasetms_client.JobCreateRequestDto( - target_langs=["cs_cz", "de_de"], - due=datetime(2024, 4, 5, 6, 7, 8, 9, tzinfo=timezone.utc), - workflow_settings=workflow_settings, - ).to_json() - content_disposition = 'filename="test.xlsx"' # str | must match pattern `((inline|attachment); )?(filename\\*=UTF-8''(.+)|filename=\"?(.+)\"?)` (optional) - body = None # object | (optional) - - try: - # Create job - api_response = api_instance.create_job( - project_uid, - memsource=memsource, - content_disposition=content_disposition, - body=body, - ) - print("The response of JobApi->create_job:\n") - pprint(api_response) - - except Exception as e: - print("Exception when calling JobApi->create_job: %s\n" % e) pass def test_create_job_from_async_download_task(self): @@ -439,5 +386,5 @@ def test_wild_card_search_by_job3(self): pass -if __name__ == "__main__": +if __name__ == '__main__': unittest.main()