Skip to content

Commit f55c464

Browse files
authored
Merge pull request #94 from huntflow/INT-576_update_UsersManagement_entity
[INT-576] - Update UsersManagement entity.
2 parents 5cef058 + a55e2d0 commit f55c464

3 files changed

Lines changed: 55 additions & 4 deletions

File tree

huntflow_api_client/entities/users_management.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from typing import Any, Dict, Optional
1+
from typing import Any, Dict, List, Optional
22

33
from huntflow_api_client.entities.base import BaseEntity
4+
from huntflow_api_client.models.consts import MemberType
45
from huntflow_api_client.models.request.users_management import ForeignUserRequest
56
from huntflow_api_client.models.response.users_management import (
67
CreatedUserControlTaskResponse,
@@ -15,6 +16,7 @@ class UsersManagement(BaseEntity):
1516
async def get_users_with_foreign(
1617
self,
1718
account_id: int,
19+
member_types: Optional[List[MemberType]] = None,
1820
count: Optional[int] = 30,
1921
page: Optional[int] = 1,
2022
) -> ForeignUsersListResponse:
@@ -23,6 +25,7 @@ async def get_users_with_foreign(
2325
https://api.huntflow.ai/v2/docs#get-/accounts/-account_id-/users/foreign
2426
2527
:param account_id: Organization ID
28+
:param member_types: Array of member types
2629
:param count: Number of items per page
2730
:param page: Page number
2831
@@ -32,6 +35,8 @@ async def get_users_with_foreign(
3235
All identifiers in response are foreign.
3336
"""
3437
params: Dict[str, Any] = {"count": count, "page": page}
38+
if member_types:
39+
params["member_types"] = [member_type.value for member_type in member_types]
3540
response = await self._api.request(
3641
"GET",
3742
f"/accounts/{account_id}/users/foreign",

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
[project]
33
name = "huntflow-api-client"
4-
version = "2.1.0"
4+
version = "2.2.0"
55
description = "Huntflow API Client for Python"
66
authors = [
77
{name = "Developers huntflow", email = "developer@huntflow.ru"},

tests/test_entities/test_users_management.py

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,34 @@
3737
},
3838
],
3939
}
40+
GET_USERS_RESPONSE_TWO_MEMBERS: Dict[str, Any] = {
41+
"page": 1,
42+
"count": 30,
43+
"total_pages": 1,
44+
"total_items": 2,
45+
"items": [
46+
{
47+
"id": "some_foreign_id_1",
48+
"name": "John Doe",
49+
"email": "mail@gmail.com",
50+
"type": "owner",
51+
"head_id": "user-032044",
52+
"division_ids": ["division-154", "division-871"],
53+
"permissions": ["string"],
54+
"meta": {},
55+
},
56+
{
57+
"id": "some_foreign_id_2",
58+
"name": "Nick Smith",
59+
"email": "mail@example.com",
60+
"type": "manager",
61+
"head_id": "user-1234",
62+
"division_ids": ["division-123", "division-321"],
63+
"permissions": ["string"],
64+
"meta": {},
65+
},
66+
],
67+
}
4068
GET_USER_BY_FOREIGN_RESPONSE: Dict[str, Any] = {
4169
"id": FOREIGN_USER_ID,
4270
"name": "John Doe",
@@ -75,15 +103,33 @@ async def test_get_users_with_foreign(
75103
token_proxy: HuntflowTokenProxy,
76104
) -> None:
77105
httpx_mock.add_response(
78-
url=f"{VERSIONED_BASE_URL}/accounts/{ACCOUNT_ID}/users/foreign?count=30&page=1",
106+
url=f"{VERSIONED_BASE_URL}/accounts/{ACCOUNT_ID}/users/"
107+
f"foreign?count=30&page=1&member_types=owner",
79108
json=GET_USERS_RESPONSE,
80109
)
81110
api_client = HuntflowAPI(BASE_URL, token_proxy=token_proxy)
82111
users_management = UsersManagement(api_client)
83112

84-
response = await users_management.get_users_with_foreign(account_id=ACCOUNT_ID)
113+
response = await users_management.get_users_with_foreign(
114+
account_id=ACCOUNT_ID,
115+
member_types=[MemberType.owner],
116+
)
85117
assert response == ForeignUsersListResponse(**GET_USERS_RESPONSE)
86118

119+
httpx_mock.add_response(
120+
url=f"{VERSIONED_BASE_URL}/accounts/{ACCOUNT_ID}/users/"
121+
f"foreign?count=30&page=1&member_types=owner&member_types=manager",
122+
json=GET_USERS_RESPONSE_TWO_MEMBERS,
123+
)
124+
api_client = HuntflowAPI(BASE_URL, token_proxy=token_proxy)
125+
users_management = UsersManagement(api_client)
126+
127+
response = await users_management.get_users_with_foreign(
128+
account_id=ACCOUNT_ID,
129+
member_types=[MemberType.owner, MemberType.manager],
130+
)
131+
assert response == ForeignUsersListResponse(**GET_USERS_RESPONSE_TWO_MEMBERS)
132+
87133

88134
async def test_get_user_by_foreign(
89135
httpx_mock: HTTPXMock,

0 commit comments

Comments
 (0)