Skip to content

Commit

Permalink
Fix UsersManagement.delete_user().
Browse files Browse the repository at this point in the history
  • Loading branch information
koval committed Nov 20, 2023
1 parent ecbda08 commit 29d2511
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
9 changes: 7 additions & 2 deletions huntflow_api_client/entities/users_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,23 @@ async def create_user(
)
return CreatedUserControlTaskResponse.model_validate(response.json())

async def delete_user(self, account_id: int, foreign_user_id: str) -> None:
async def delete_user(
self,
account_id: int,
foreign_user_id: str,
) -> CreatedUserControlTaskResponse:
"""
API method reference
https://api.huntflow.ai/v2/docs#delete-/accounts/-account_id-/users/foreign/-foreign_user_id-
:param account_id: Organization ID
:param foreign_user_id: Foreign ID of User
"""
await self._api.request(
response = await self._api.request(
"DELETE",
f"/accounts/{account_id}/users/foreign/{foreign_user_id}",
)
return CreatedUserControlTaskResponse.model_validate(response.json())

async def get_user_internal_id_by_foreign(
self,
Expand Down
12 changes: 7 additions & 5 deletions tests/test_entities/test_users_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"completed": "2020-01-01T00:00:00+03:00",
}
GET_USER_ID_BY_FOREIGN_RESPONSE: Dict[str, Any] = {"id": 12345}
CREATE_USER_RESPONSE: Dict[str, Any] = {
CREATE_USER_TASK_RESPONSE: Dict[str, Any] = {
"task_id": TASK_ID,
"action": "CREATE",
"created": "2020-01-01T00:00:00+03:00",
Expand Down Expand Up @@ -142,12 +142,14 @@ async def test_delete_user(
) -> None:
httpx_mock.add_response(
url=f"{BASE_URL}/accounts/{ACCOUNT_ID}/users/foreign/{FOREIGN_USER_ID}",
status_code=204,
status_code=202,
json=CREATE_USER_TASK_RESPONSE,
)
api_client = HuntflowAPI(BASE_URL, token_proxy=token_proxy)
users_management = UsersManagement(api_client)

await users_management.delete_user(ACCOUNT_ID, FOREIGN_USER_ID)
response = await users_management.delete_user(ACCOUNT_ID, FOREIGN_USER_ID)
assert response == CreatedUserControlTaskResponse(**CREATE_USER_TASK_RESPONSE)


async def test_create_user(
Expand All @@ -156,7 +158,7 @@ async def test_create_user(
) -> None:
httpx_mock.add_response(
url=f"{BASE_URL}/accounts/{ACCOUNT_ID}/users/foreign",
json=CREATE_USER_RESPONSE,
json=CREATE_USER_TASK_RESPONSE,
)
api_client = HuntflowAPI(BASE_URL, token_proxy=token_proxy)
users_management = UsersManagement(api_client)
Expand All @@ -167,7 +169,7 @@ async def test_create_user(
type=MemberType.owner,
)
response = await users_management.create_user(account_id=ACCOUNT_ID, data=data)
assert response == CreatedUserControlTaskResponse(**CREATE_USER_RESPONSE)
assert response == CreatedUserControlTaskResponse(**CREATE_USER_TASK_RESPONSE)


async def test_update_user(
Expand Down

0 comments on commit 29d2511

Please sign in to comment.