Skip to content

Commit

Permalink
Merge pull request #94 from huntflow/INT-576_update_UsersManagement_e…
Browse files Browse the repository at this point in the history
…ntity

[INT-576] - Update UsersManagement entity.
  • Loading branch information
polina-koval authored May 6, 2024
2 parents 5cef058 + a55e2d0 commit f55c464
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 4 deletions.
7 changes: 6 additions & 1 deletion huntflow_api_client/entities/users_management.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Any, Dict, Optional
from typing import Any, Dict, List, Optional

from huntflow_api_client.entities.base import BaseEntity
from huntflow_api_client.models.consts import MemberType
from huntflow_api_client.models.request.users_management import ForeignUserRequest
from huntflow_api_client.models.response.users_management import (
CreatedUserControlTaskResponse,
Expand All @@ -15,6 +16,7 @@ class UsersManagement(BaseEntity):
async def get_users_with_foreign(
self,
account_id: int,
member_types: Optional[List[MemberType]] = None,
count: Optional[int] = 30,
page: Optional[int] = 1,
) -> ForeignUsersListResponse:
Expand All @@ -23,6 +25,7 @@ async def get_users_with_foreign(
https://api.huntflow.ai/v2/docs#get-/accounts/-account_id-/users/foreign
:param account_id: Organization ID
:param member_types: Array of member types
:param count: Number of items per page
:param page: Page number
Expand All @@ -32,6 +35,8 @@ async def get_users_with_foreign(
All identifiers in response are foreign.
"""
params: Dict[str, Any] = {"count": count, "page": page}
if member_types:
params["member_types"] = [member_type.value for member_type in member_types]
response = await self._api.request(
"GET",
f"/accounts/{account_id}/users/foreign",
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

[project]
name = "huntflow-api-client"
version = "2.1.0"
version = "2.2.0"
description = "Huntflow API Client for Python"
authors = [
{name = "Developers huntflow", email = "[email protected]"},
Expand Down
50 changes: 48 additions & 2 deletions tests/test_entities/test_users_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,34 @@
},
],
}
GET_USERS_RESPONSE_TWO_MEMBERS: Dict[str, Any] = {
"page": 1,
"count": 30,
"total_pages": 1,
"total_items": 2,
"items": [
{
"id": "some_foreign_id_1",
"name": "John Doe",
"email": "[email protected]",
"type": "owner",
"head_id": "user-032044",
"division_ids": ["division-154", "division-871"],
"permissions": ["string"],
"meta": {},
},
{
"id": "some_foreign_id_2",
"name": "Nick Smith",
"email": "[email protected]",
"type": "manager",
"head_id": "user-1234",
"division_ids": ["division-123", "division-321"],
"permissions": ["string"],
"meta": {},
},
],
}
GET_USER_BY_FOREIGN_RESPONSE: Dict[str, Any] = {
"id": FOREIGN_USER_ID,
"name": "John Doe",
Expand Down Expand Up @@ -75,15 +103,33 @@ async def test_get_users_with_foreign(
token_proxy: HuntflowTokenProxy,
) -> None:
httpx_mock.add_response(
url=f"{VERSIONED_BASE_URL}/accounts/{ACCOUNT_ID}/users/foreign?count=30&page=1",
url=f"{VERSIONED_BASE_URL}/accounts/{ACCOUNT_ID}/users/"
f"foreign?count=30&page=1&member_types=owner",
json=GET_USERS_RESPONSE,
)
api_client = HuntflowAPI(BASE_URL, token_proxy=token_proxy)
users_management = UsersManagement(api_client)

response = await users_management.get_users_with_foreign(account_id=ACCOUNT_ID)
response = await users_management.get_users_with_foreign(
account_id=ACCOUNT_ID,
member_types=[MemberType.owner],
)
assert response == ForeignUsersListResponse(**GET_USERS_RESPONSE)

httpx_mock.add_response(
url=f"{VERSIONED_BASE_URL}/accounts/{ACCOUNT_ID}/users/"
f"foreign?count=30&page=1&member_types=owner&member_types=manager",
json=GET_USERS_RESPONSE_TWO_MEMBERS,
)
api_client = HuntflowAPI(BASE_URL, token_proxy=token_proxy)
users_management = UsersManagement(api_client)

response = await users_management.get_users_with_foreign(
account_id=ACCOUNT_ID,
member_types=[MemberType.owner, MemberType.manager],
)
assert response == ForeignUsersListResponse(**GET_USERS_RESPONSE_TWO_MEMBERS)


async def test_get_user_by_foreign(
httpx_mock: HTTPXMock,
Expand Down

0 comments on commit f55c464

Please sign in to comment.