From 07010b089333152920ad21dc28795927c41d0f32 Mon Sep 17 00:00:00 2001 From: andriy Date: Fri, 30 Sep 2022 07:29:38 +0300 Subject: [PATCH] add vendors enterprise endpoints --- crowdin_api/api_resources/__init__.py | 2 + .../api_resources/abstract/__init__.py | 1 - .../api_resources/dictionaries/__init__.py | 1 - .../api_resources/distributions/__init__.py | 1 - .../api_resources/glossaries/__init__.py | 1 - crowdin_api/api_resources/groups/__init__.py | 1 - crowdin_api/api_resources/labels/__init__.py | 1 - .../api_resources/languages/__init__.py | 1 - .../machine_translation_engines/__init__.py | 1 - .../api_resources/projects/__init__.py | 1 - crowdin_api/api_resources/reports/__init__.py | 1 - .../api_resources/screenshots/__init__.py | 1 - .../api_resources/source_files/__init__.py | 1 - .../api_resources/source_strings/__init__.py | 1 - .../api_resources/storages/__init__.py | 1 - .../api_resources/string_comments/__init__.py | 1 - .../string_translations/__init__.py | 1 - crowdin_api/api_resources/tasks/__init__.py | 1 - .../teams/tests/test_teams_resources.py | 2 +- .../translation_status/__init__.py | 1 - .../api_resources/translations/__init__.py | 1 - crowdin_api/api_resources/vendors/__init__.py | 1 + crowdin_api/api_resources/vendors/resource.py | 32 +++++++++++++ .../vendors/tests/test_vendos_resources.py | 47 +++++++++++++++++++ .../api_resources/webhooks/__init__.py | 1 - crowdin_api/client.py | 9 ++++ crowdin_api/tests/test_client.py | 1 + crowdin_api/tests/test_client_methods.py | 7 +++ 28 files changed, 100 insertions(+), 21 deletions(-) create mode 100644 crowdin_api/api_resources/vendors/__init__.py create mode 100644 crowdin_api/api_resources/vendors/resource.py create mode 100644 crowdin_api/api_resources/vendors/tests/test_vendos_resources.py diff --git a/crowdin_api/api_resources/__init__.py b/crowdin_api/api_resources/__init__.py index a4e06af..342fee4 100644 --- a/crowdin_api/api_resources/__init__.py +++ b/crowdin_api/api_resources/__init__.py @@ -20,6 +20,7 @@ from .translation_status.resource import TranslationStatusResource from .translations.resource import TranslationsResource from .users.resource import UsersResource, EnterpriseUsersResource +from .vendors.resource import VendorsResource from .webhooks.resource import WebhooksResource __all__ = [ @@ -47,5 +48,6 @@ "TranslationsResource", "UsersResource", "EnterpriseUsersResource", + "VendorsResource", "WebhooksResource", ] diff --git a/crowdin_api/api_resources/abstract/__init__.py b/crowdin_api/api_resources/abstract/__init__.py index 5468470..9f77d63 100644 --- a/crowdin_api/api_resources/abstract/__init__.py +++ b/crowdin_api/api_resources/abstract/__init__.py @@ -1,2 +1 @@ __pdoc__ = {'tests': False} - diff --git a/crowdin_api/api_resources/dictionaries/__init__.py b/crowdin_api/api_resources/dictionaries/__init__.py index 5468470..9f77d63 100644 --- a/crowdin_api/api_resources/dictionaries/__init__.py +++ b/crowdin_api/api_resources/dictionaries/__init__.py @@ -1,2 +1 @@ __pdoc__ = {'tests': False} - diff --git a/crowdin_api/api_resources/distributions/__init__.py b/crowdin_api/api_resources/distributions/__init__.py index 5468470..9f77d63 100644 --- a/crowdin_api/api_resources/distributions/__init__.py +++ b/crowdin_api/api_resources/distributions/__init__.py @@ -1,2 +1 @@ __pdoc__ = {'tests': False} - diff --git a/crowdin_api/api_resources/glossaries/__init__.py b/crowdin_api/api_resources/glossaries/__init__.py index 5468470..9f77d63 100644 --- a/crowdin_api/api_resources/glossaries/__init__.py +++ b/crowdin_api/api_resources/glossaries/__init__.py @@ -1,2 +1 @@ __pdoc__ = {'tests': False} - diff --git a/crowdin_api/api_resources/groups/__init__.py b/crowdin_api/api_resources/groups/__init__.py index 5468470..9f77d63 100644 --- a/crowdin_api/api_resources/groups/__init__.py +++ b/crowdin_api/api_resources/groups/__init__.py @@ -1,2 +1 @@ __pdoc__ = {'tests': False} - diff --git a/crowdin_api/api_resources/labels/__init__.py b/crowdin_api/api_resources/labels/__init__.py index 5468470..9f77d63 100644 --- a/crowdin_api/api_resources/labels/__init__.py +++ b/crowdin_api/api_resources/labels/__init__.py @@ -1,2 +1 @@ __pdoc__ = {'tests': False} - diff --git a/crowdin_api/api_resources/languages/__init__.py b/crowdin_api/api_resources/languages/__init__.py index 5468470..9f77d63 100644 --- a/crowdin_api/api_resources/languages/__init__.py +++ b/crowdin_api/api_resources/languages/__init__.py @@ -1,2 +1 @@ __pdoc__ = {'tests': False} - diff --git a/crowdin_api/api_resources/machine_translation_engines/__init__.py b/crowdin_api/api_resources/machine_translation_engines/__init__.py index 5468470..9f77d63 100644 --- a/crowdin_api/api_resources/machine_translation_engines/__init__.py +++ b/crowdin_api/api_resources/machine_translation_engines/__init__.py @@ -1,2 +1 @@ __pdoc__ = {'tests': False} - diff --git a/crowdin_api/api_resources/projects/__init__.py b/crowdin_api/api_resources/projects/__init__.py index 5468470..9f77d63 100644 --- a/crowdin_api/api_resources/projects/__init__.py +++ b/crowdin_api/api_resources/projects/__init__.py @@ -1,2 +1 @@ __pdoc__ = {'tests': False} - diff --git a/crowdin_api/api_resources/reports/__init__.py b/crowdin_api/api_resources/reports/__init__.py index 5468470..9f77d63 100644 --- a/crowdin_api/api_resources/reports/__init__.py +++ b/crowdin_api/api_resources/reports/__init__.py @@ -1,2 +1 @@ __pdoc__ = {'tests': False} - diff --git a/crowdin_api/api_resources/screenshots/__init__.py b/crowdin_api/api_resources/screenshots/__init__.py index 5468470..9f77d63 100644 --- a/crowdin_api/api_resources/screenshots/__init__.py +++ b/crowdin_api/api_resources/screenshots/__init__.py @@ -1,2 +1 @@ __pdoc__ = {'tests': False} - diff --git a/crowdin_api/api_resources/source_files/__init__.py b/crowdin_api/api_resources/source_files/__init__.py index 5468470..9f77d63 100644 --- a/crowdin_api/api_resources/source_files/__init__.py +++ b/crowdin_api/api_resources/source_files/__init__.py @@ -1,2 +1 @@ __pdoc__ = {'tests': False} - diff --git a/crowdin_api/api_resources/source_strings/__init__.py b/crowdin_api/api_resources/source_strings/__init__.py index 5468470..9f77d63 100644 --- a/crowdin_api/api_resources/source_strings/__init__.py +++ b/crowdin_api/api_resources/source_strings/__init__.py @@ -1,2 +1 @@ __pdoc__ = {'tests': False} - diff --git a/crowdin_api/api_resources/storages/__init__.py b/crowdin_api/api_resources/storages/__init__.py index 5468470..9f77d63 100644 --- a/crowdin_api/api_resources/storages/__init__.py +++ b/crowdin_api/api_resources/storages/__init__.py @@ -1,2 +1 @@ __pdoc__ = {'tests': False} - diff --git a/crowdin_api/api_resources/string_comments/__init__.py b/crowdin_api/api_resources/string_comments/__init__.py index 5468470..9f77d63 100644 --- a/crowdin_api/api_resources/string_comments/__init__.py +++ b/crowdin_api/api_resources/string_comments/__init__.py @@ -1,2 +1 @@ __pdoc__ = {'tests': False} - diff --git a/crowdin_api/api_resources/string_translations/__init__.py b/crowdin_api/api_resources/string_translations/__init__.py index 5468470..9f77d63 100644 --- a/crowdin_api/api_resources/string_translations/__init__.py +++ b/crowdin_api/api_resources/string_translations/__init__.py @@ -1,2 +1 @@ __pdoc__ = {'tests': False} - diff --git a/crowdin_api/api_resources/tasks/__init__.py b/crowdin_api/api_resources/tasks/__init__.py index 5468470..9f77d63 100644 --- a/crowdin_api/api_resources/tasks/__init__.py +++ b/crowdin_api/api_resources/tasks/__init__.py @@ -1,2 +1 @@ __pdoc__ = {'tests': False} - diff --git a/crowdin_api/api_resources/teams/tests/test_teams_resources.py b/crowdin_api/api_resources/teams/tests/test_teams_resources.py index 3b53672..1b57918 100644 --- a/crowdin_api/api_resources/teams/tests/test_teams_resources.py +++ b/crowdin_api/api_resources/teams/tests/test_teams_resources.py @@ -8,7 +8,7 @@ from crowdin_api.requester import APIRequester -class TestBundlesResource: +class TestTeamsResources: resource_class = TeamsResource def get_resource(self, base_absolut_url): diff --git a/crowdin_api/api_resources/translation_status/__init__.py b/crowdin_api/api_resources/translation_status/__init__.py index 5468470..9f77d63 100644 --- a/crowdin_api/api_resources/translation_status/__init__.py +++ b/crowdin_api/api_resources/translation_status/__init__.py @@ -1,2 +1 @@ __pdoc__ = {'tests': False} - diff --git a/crowdin_api/api_resources/translations/__init__.py b/crowdin_api/api_resources/translations/__init__.py index 5468470..9f77d63 100644 --- a/crowdin_api/api_resources/translations/__init__.py +++ b/crowdin_api/api_resources/translations/__init__.py @@ -1,2 +1 @@ __pdoc__ = {'tests': False} - diff --git a/crowdin_api/api_resources/vendors/__init__.py b/crowdin_api/api_resources/vendors/__init__.py new file mode 100644 index 0000000..9f77d63 --- /dev/null +++ b/crowdin_api/api_resources/vendors/__init__.py @@ -0,0 +1 @@ +__pdoc__ = {'tests': False} diff --git a/crowdin_api/api_resources/vendors/resource.py b/crowdin_api/api_resources/vendors/resource.py new file mode 100644 index 0000000..3b31e94 --- /dev/null +++ b/crowdin_api/api_resources/vendors/resource.py @@ -0,0 +1,32 @@ +from typing import Optional + +from crowdin_api.api_resources.abstract.resources import BaseResource + + +class VendorsResource(BaseResource): + """ + Resource for Vendors. + + Vendors are the organizations that provide professional translation services. + To assign a Vendor to a project workflow you should invite an existing Organization + to be a Vendor for you. + + Use API to get the list of the Vendors you already invited to your organization. + + Link to documentation: + https://developer.crowdin.com/enterprise/api/v2/#tag/Vendors + """ + + def list_vendors(self, offset: Optional[int] = None, limit: Optional[int] = None): + """ + List Teams. + + Link to documentation: + https://developer.crowdin.com/enterprise/api/v2/#operation/api.teams.getMany + """ + + return self.requester.request( + method="get", + path="vendors", + params=self.get_page_params(offset=offset, limit=limit), + ) diff --git a/crowdin_api/api_resources/vendors/tests/test_vendos_resources.py b/crowdin_api/api_resources/vendors/tests/test_vendos_resources.py new file mode 100644 index 0000000..7a37b52 --- /dev/null +++ b/crowdin_api/api_resources/vendors/tests/test_vendos_resources.py @@ -0,0 +1,47 @@ +from unittest import mock + +import pytest + +from crowdin_api.api_resources.vendors.resource import VendorsResource +from crowdin_api.requester import APIRequester + + +class TestVendorsResources: + resource_class = VendorsResource + + def get_resource(self, base_absolut_url): + return self.resource_class(requester=APIRequester(base_url=base_absolut_url)) + + @pytest.mark.parametrize( + "incoming_data, request_params", + ( + ( + {}, + { + "limit": 25, + "offset": 0, + }, + ), + ( + { + "limit": 10, + "offset": 2, + }, + { + "limit": 10, + "offset": 2, + }, + ), + ), + ) + @mock.patch("crowdin_api.requester.APIRequester.request") + def test_list_vendors(self, m_request, incoming_data, request_params, base_absolut_url): + m_request.return_value = "response" + + resource = self.get_resource(base_absolut_url) + assert resource.list_vendors(**incoming_data) == "response" + m_request.assert_called_once_with( + method="get", + path="vendors", + params=request_params, + ) diff --git a/crowdin_api/api_resources/webhooks/__init__.py b/crowdin_api/api_resources/webhooks/__init__.py index 5468470..9f77d63 100644 --- a/crowdin_api/api_resources/webhooks/__init__.py +++ b/crowdin_api/api_resources/webhooks/__init__.py @@ -1,2 +1 @@ __pdoc__ = {'tests': False} - diff --git a/crowdin_api/client.py b/crowdin_api/client.py index f525887..078b910 100644 --- a/crowdin_api/client.py +++ b/crowdin_api/client.py @@ -214,6 +214,15 @@ def users(self) -> Union[api_resources.UsersResource, api_resources.EnterpriseUs requester=self.get_api_requestor(), page_size=self.PAGE_SIZE ) + @property + def vendors(self) -> api_resources.VendorsResource: + if not self._is_enterprise_platform: + raise CrowdinException(detail="Not implemented for the base API") + + return api_resources.VendorsResource( + requester=self.get_api_requestor(), page_size=self.PAGE_SIZE + ) + @property def webhooks(self) -> api_resources.WebhooksResource: return api_resources.WebhooksResource( diff --git a/crowdin_api/tests/test_client.py b/crowdin_api/tests/test_client.py index 3813a9a..080bee2 100644 --- a/crowdin_api/tests/test_client.py +++ b/crowdin_api/tests/test_client.py @@ -160,6 +160,7 @@ class TestCrowdinClientEnterprise: ("translation_status", "TranslationStatusResource"), ("translations", "TranslationsResource"), ("users", "EnterpriseUsersResource"), + ("vendors", "VendorsResource"), ("webhooks", "WebhooksResource"), ), ) diff --git a/crowdin_api/tests/test_client_methods.py b/crowdin_api/tests/test_client_methods.py index 9819132..cae64fa 100644 --- a/crowdin_api/tests/test_client_methods.py +++ b/crowdin_api/tests/test_client_methods.py @@ -11,6 +11,13 @@ def test_groups_without_organization(): client.groups.list_groups() +def test_vendors_without_organization(): + client = CrowdinClient() + + with pytest.raises(CrowdinException, match="Not implemented for the base API"): + client.vendors.list_vendors() + + def test_teams_without_organization(): client = CrowdinClient()