Skip to content

Commit

Permalink
add vendors enterprise endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
ayatsyny committed Sep 30, 2022
1 parent f4bdfcd commit 07010b0
Show file tree
Hide file tree
Showing 28 changed files with 100 additions and 21 deletions.
2 changes: 2 additions & 0 deletions crowdin_api/api_resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__ = [
Expand Down Expand Up @@ -47,5 +48,6 @@
"TranslationsResource",
"UsersResource",
"EnterpriseUsersResource",
"VendorsResource",
"WebhooksResource",
]
1 change: 0 additions & 1 deletion crowdin_api/api_resources/abstract/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
__pdoc__ = {'tests': False}

1 change: 0 additions & 1 deletion crowdin_api/api_resources/dictionaries/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
__pdoc__ = {'tests': False}

1 change: 0 additions & 1 deletion crowdin_api/api_resources/distributions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
__pdoc__ = {'tests': False}

1 change: 0 additions & 1 deletion crowdin_api/api_resources/glossaries/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
__pdoc__ = {'tests': False}

1 change: 0 additions & 1 deletion crowdin_api/api_resources/groups/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
__pdoc__ = {'tests': False}

1 change: 0 additions & 1 deletion crowdin_api/api_resources/labels/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
__pdoc__ = {'tests': False}

1 change: 0 additions & 1 deletion crowdin_api/api_resources/languages/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
__pdoc__ = {'tests': False}

Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
__pdoc__ = {'tests': False}

1 change: 0 additions & 1 deletion crowdin_api/api_resources/projects/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
__pdoc__ = {'tests': False}

1 change: 0 additions & 1 deletion crowdin_api/api_resources/reports/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
__pdoc__ = {'tests': False}

1 change: 0 additions & 1 deletion crowdin_api/api_resources/screenshots/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
__pdoc__ = {'tests': False}

1 change: 0 additions & 1 deletion crowdin_api/api_resources/source_files/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
__pdoc__ = {'tests': False}

1 change: 0 additions & 1 deletion crowdin_api/api_resources/source_strings/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
__pdoc__ = {'tests': False}

1 change: 0 additions & 1 deletion crowdin_api/api_resources/storages/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
__pdoc__ = {'tests': False}

1 change: 0 additions & 1 deletion crowdin_api/api_resources/string_comments/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
__pdoc__ = {'tests': False}

1 change: 0 additions & 1 deletion crowdin_api/api_resources/string_translations/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
__pdoc__ = {'tests': False}

1 change: 0 additions & 1 deletion crowdin_api/api_resources/tasks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
__pdoc__ = {'tests': False}

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from crowdin_api.requester import APIRequester


class TestBundlesResource:
class TestTeamsResources:
resource_class = TeamsResource

def get_resource(self, base_absolut_url):
Expand Down
1 change: 0 additions & 1 deletion crowdin_api/api_resources/translation_status/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
__pdoc__ = {'tests': False}

1 change: 0 additions & 1 deletion crowdin_api/api_resources/translations/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
__pdoc__ = {'tests': False}

1 change: 1 addition & 0 deletions crowdin_api/api_resources/vendors/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pdoc__ = {'tests': False}
32 changes: 32 additions & 0 deletions crowdin_api/api_resources/vendors/resource.py
Original file line number Diff line number Diff line change
@@ -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),
)
47 changes: 47 additions & 0 deletions crowdin_api/api_resources/vendors/tests/test_vendos_resources.py
Original file line number Diff line number Diff line change
@@ -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,
)
1 change: 0 additions & 1 deletion crowdin_api/api_resources/webhooks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
__pdoc__ = {'tests': False}

9 changes: 9 additions & 0 deletions crowdin_api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions crowdin_api/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ class TestCrowdinClientEnterprise:
("translation_status", "TranslationStatusResource"),
("translations", "TranslationsResource"),
("users", "EnterpriseUsersResource"),
("vendors", "VendorsResource"),
("webhooks", "WebhooksResource"),
),
)
Expand Down
7 changes: 7 additions & 0 deletions crowdin_api/tests/test_client_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 07010b0

Please sign in to comment.