Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(users): Fix list project members API endpoint for enterprise. #158

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 59 additions & 6 deletions crowdin_api/api_resources/users/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,28 @@ def get_members_path(self, projectId: int, memberId: Optional[int] = None):

return f"projects/{projectId}/members"

def list_project_members(
def _list_project_members(
self,
projectId: Optional[int] = None,
search: Optional[str] = None,
role: Optional[UserRole] = None,
languageId: Optional[str] = None,
page: Optional[int] = None,
offset: Optional[int] = None,
limit: Optional[int] = None,
extraParams: Optional[dict] = None
):
"""
List Project Members.

Link to documentation:
https://developer.crowdin.com/api/v2/#operation/api.projects.members.getMany

Link to documentation for enterprise:
https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.members.getMany
"""

projectId = projectId or self.get_project_id()
params = {"search": search, "role": role, "languageId": languageId}
params = {"search": search, "languageId": languageId}
if extraParams:
params.update(extraParams)

params.update(self.get_page_params(page=page, offset=offset, limit=limit))

return self._get_entire_data(
Expand All @@ -58,6 +58,32 @@ class UsersResource(BaseUsersResource):
https://developer.crowdin.com/api/v2/#tag/Users
"""

def list_project_members(
self,
projectId: Optional[int] = None,
search: Optional[str] = None,
role: Optional[UserRole] = None,
languageId: Optional[str] = None,
page: Optional[int] = None,
offset: Optional[int] = None,
limit: Optional[int] = None,
):
"""
List Project Members.

Link to documentation:
https://developer.crowdin.com/api/v2/#operation/api.projects.members.getMany
"""
return self._list_project_members(
projectId=projectId,
search=search,
languageId=languageId,
page=page,
offset=offset,
limit=limit,
extraParams={"role": role}
andrii-bodnar marked this conversation as resolved.
Show resolved Hide resolved
)

def get_member_info(self, memberId: int, projectId: Optional[int] = None):
"""
Get Member Info.
Expand Down Expand Up @@ -90,6 +116,33 @@ def get_users_path(self, userId: Optional[int] = None):

return "users"

def list_project_members(
self,
projectId: Optional[int] = None,
search: Optional[str] = None,
workflowStepId: Optional[int] = None,
languageId: Optional[str] = None,
page: Optional[int] = None,
offset: Optional[int] = None,
limit: Optional[int] = None,
):
"""
List Project Members.

Link to documentation for enterprise:
https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.members.getMany
"""

return self._list_project_members(
projectId=projectId,
search=search,
languageId=languageId,
page=page,
offset=offset,
limit=limit,
extraParams={"workflowStepId": workflowStepId}
)

def add_project_member(
self,
userIds: Iterable[int],
Expand Down
95 changes: 68 additions & 27 deletions crowdin_api/api_resources/users/tests/test_users_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,33 @@ def test_get_authenticated_user(self, m_request, base_absolut_url):
assert resource.get_authenticated_user() == "response"
m_request.assert_called_once_with(method="get", path="user")


class TestUsersResource:
resource_class = UsersResource

def get_resource(self, base_absolut_url):
return self.resource_class(requester=APIRequester(base_url=base_absolut_url))

@pytest.mark.parametrize(
"name_method",
[
"get_authenticated_user",
"get_members_path",
"list_project_members",
"get_member_info",
]
)
def test_present_methods(self, name_method):
assert hasattr(self.resource_class, name_method)

@mock.patch("crowdin_api.requester.APIRequester.request")
def test_get_member_info(self, m_request, base_absolut_url):
m_request.return_value = "response"

resource = self.get_resource(base_absolut_url)
assert resource.get_member_info(projectId=1, memberId=2) == "response"
m_request.assert_called_once_with(method="get", path="projects/1/members/2")

@pytest.mark.parametrize(
"in_params, request_params",
(
Expand Down Expand Up @@ -87,33 +114,6 @@ def test_list_project_members(self, m_request, in_params, request_params, base_a
)


class TestUsersResource:
resource_class = UsersResource

def get_resource(self, base_absolut_url):
return self.resource_class(requester=APIRequester(base_url=base_absolut_url))

@pytest.mark.parametrize(
"name_method",
[
"get_authenticated_user",
"get_members_path",
"list_project_members",
"get_member_info",
]
)
def test_present_methods(self, name_method):
assert hasattr(self.resource_class, name_method)

@mock.patch("crowdin_api.requester.APIRequester.request")
def test_get_member_info(self, m_request, base_absolut_url):
m_request.return_value = "response"

resource = self.get_resource(base_absolut_url)
assert resource.get_member_info(projectId=1, memberId=2) == "response"
m_request.assert_called_once_with(method="get", path="projects/1/members/2")


class TestEnterpriseUsersResource:
resource_class = EnterpriseUsersResource

Expand Down Expand Up @@ -153,6 +153,47 @@ def test_get_users_path(self, userId, path, base_absolut_url):
resource = self.get_resource(base_absolut_url)
assert resource.get_users_path(userId=userId) == path

@pytest.mark.parametrize(
"in_params, request_params",
(
(
{},
{
"search": None,
"workflowStepId": None,
"languageId": None,
"offset": 0,
"limit": 25,
},
),
(
{
"search": "search",
"workflowStepId": 72,
"languageId": "ua",
"offset": 0,
"limit": 25,
},
{
"search": "search",
"workflowStepId": 72,
"languageId": "ua",
"offset": 0,
"limit": 25,
},
),
),
)
@mock.patch("crowdin_api.requester.APIRequester.request")
def test_list_project_members(self, m_request, in_params, request_params, base_absolut_url):
m_request.return_value = "response"

resource = self.get_resource(base_absolut_url)
assert resource.list_project_members(projectId=1, **in_params) == "response"
m_request.assert_called_once_with(
method="get", params=request_params, path="projects/1/members"
)

@pytest.mark.parametrize(
"in_params, request_params",
(
Expand Down