-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added fields into UserFromSearch: active, created_at, cts_id, d…
…escription, ip_phone, manager, office, other_ip_phone, other_phone, public_name, rts_id, update_at (#483) Co-authored-by: Leonid Gorbunov <[email protected]>
- Loading branch information
Showing
10 changed files
with
402 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "pybotx" | ||
version = "0.69.1" | ||
version = "0.70.0" | ||
description = "A python library for interacting with eXpress BotX API" | ||
authors = [ | ||
"Sidnev Nikolay <[email protected]>", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
from typing import Any, Dict | ||
from uuid import UUID | ||
|
||
import pytest | ||
|
||
from pybotx import UserFromSearch, UserKinds | ||
from tests.client.users_api.convert_to_datetime import convert_to_datetime | ||
|
||
|
||
@pytest.fixture() | ||
def user_from_search_with_data_json() -> Dict[str, Any]: | ||
return { | ||
"user_huid": "6fafda2c-6505-57a5-a088-25ea5d1d0364", | ||
"ad_login": "ad_user_login", | ||
"ad_domain": "cts.com", | ||
"name": "Bob", | ||
"company": "Bobs Co", | ||
"company_position": "Director", | ||
"department": "Owners", | ||
"emails": ["[email protected]"], | ||
"user_kind": "cts_user", | ||
"active": True, | ||
"created_at": "2023-03-26T14:36:08.740618Z", | ||
"cts_id": "e0140f4c-4af2-5a2e-9ad1-5f37fceafbaf", | ||
"description": "Director in Owners dep", | ||
"ip_phone": 1271020, | ||
"manager": "Alice", | ||
"office": "SUN", | ||
"other_ip_phone": 32593, | ||
"other_phone": 1254218, | ||
"public_name": "Bobby", | ||
"rts_id": "f46440a4-d930-58d4-b3f5-8110ab846ee3", | ||
"updated_at": "2023-03-26T14:36:08.740618Z", | ||
} | ||
|
||
|
||
@pytest.fixture | ||
def user_from_search_with_data() -> UserFromSearch: | ||
return UserFromSearch( | ||
huid=UUID("6fafda2c-6505-57a5-a088-25ea5d1d0364"), | ||
ad_login="ad_user_login", | ||
ad_domain="cts.com", | ||
username="Bob", | ||
company="Bobs Co", | ||
company_position="Director", | ||
department="Owners", | ||
emails=["[email protected]"], | ||
other_id=None, | ||
user_kind=UserKinds.CTS_USER, | ||
active=True, | ||
created_at=convert_to_datetime("2023-03-26T14:36:08.740618Z"), | ||
cts_id=UUID("e0140f4c-4af2-5a2e-9ad1-5f37fceafbaf"), | ||
description="Director in Owners dep", | ||
ip_phone=1271020, | ||
manager="Alice", | ||
office="SUN", | ||
other_ip_phone=32593, | ||
other_phone=1254218, | ||
public_name="Bobby", | ||
rts_id=UUID("f46440a4-d930-58d4-b3f5-8110ab846ee3"), | ||
updated_at=convert_to_datetime("2023-03-26T14:36:08.740618Z"), | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def user_from_search_without_data_json() -> Dict[str, Any]: | ||
return { | ||
"user_huid": "6fafda2c-6505-57a5-a088-25ea5d1d0364", | ||
"ad_login": "ad_user_login", | ||
"ad_domain": "cts.com", | ||
"name": "Bob", | ||
"company": "Bobs Co", | ||
"company_position": "Director", | ||
"department": "Owners", | ||
"emails": ["[email protected]"], | ||
"user_kind": "cts_user", | ||
"active": None, | ||
"created_at": None, | ||
"cts_id": None, | ||
"description": None, | ||
"ip_phone": None, | ||
"manager": None, | ||
"office": None, | ||
"other_ip_phone": None, | ||
"other_phone": None, | ||
"public_name": None, | ||
"rts_id": None, | ||
"updated_at": None, | ||
} | ||
|
||
|
||
@pytest.fixture | ||
def user_from_search_without_data() -> UserFromSearch: | ||
return UserFromSearch( | ||
huid=UUID("6fafda2c-6505-57a5-a088-25ea5d1d0364"), | ||
ad_login="ad_user_login", | ||
ad_domain="cts.com", | ||
username="Bob", | ||
company="Bobs Co", | ||
company_position="Director", | ||
department="Owners", | ||
emails=["[email protected]"], | ||
other_id=None, | ||
user_kind=UserKinds.CTS_USER, | ||
active=None, | ||
created_at=None, | ||
cts_id=None, | ||
description=None, | ||
ip_phone=None, | ||
manager=None, | ||
office=None, | ||
other_ip_phone=None, | ||
other_phone=None, | ||
public_name=None, | ||
rts_id=None, | ||
updated_at=None, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from datetime import datetime, timezone | ||
|
||
|
||
def convert_to_datetime(str_datetime: str) -> datetime: | ||
datetime_instance = datetime.strptime( | ||
str_datetime, | ||
"%Y-%m-%dT%H:%M:%S.%fZ", # noqa: WPS325 | ||
) | ||
return datetime_instance.replace(tzinfo=timezone.utc) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from http import HTTPStatus | ||
from typing import Any, Dict | ||
from uuid import UUID | ||
|
||
import httpx | ||
|
@@ -13,7 +14,6 @@ | |
UserNotFoundError, | ||
lifespan_wrapper, | ||
) | ||
from pybotx.models.enums import UserKinds | ||
|
||
pytestmark = [ | ||
pytest.mark.asyncio, | ||
|
@@ -65,6 +65,8 @@ async def test__search_user_by_email__succeed( | |
host: str, | ||
bot_id: UUID, | ||
bot_account: BotAccountWithSecret, | ||
user_from_search_with_data: UserFromSearch, | ||
user_from_search_with_data_json: Dict[str, Any], | ||
) -> None: | ||
# - Arrange - | ||
endpoint = respx_mock.get( | ||
|
@@ -76,17 +78,7 @@ async def test__search_user_by_email__succeed( | |
HTTPStatus.OK, | ||
json={ | ||
"status": "ok", | ||
"result": { | ||
"user_huid": "6fafda2c-6505-57a5-a088-25ea5d1d0364", | ||
"ad_login": "ad_user_login", | ||
"ad_domain": "cts.com", | ||
"name": "Bob", | ||
"company": "Bobs Co", | ||
"company_position": "Director", | ||
"department": "Owners", | ||
"emails": ["[email protected]"], | ||
"user_kind": "cts_user", | ||
}, | ||
"result": user_from_search_with_data_json, | ||
}, | ||
), | ||
) | ||
|
@@ -101,17 +93,44 @@ async def test__search_user_by_email__succeed( | |
) | ||
|
||
# - Assert - | ||
assert user == UserFromSearch( | ||
huid=UUID("6fafda2c-6505-57a5-a088-25ea5d1d0364"), | ||
ad_login="ad_user_login", | ||
ad_domain="cts.com", | ||
username="Bob", | ||
company="Bobs Co", | ||
company_position="Director", | ||
department="Owners", | ||
emails=["[email protected]"], | ||
other_id=None, | ||
user_kind=UserKinds.CTS_USER, | ||
assert user == user_from_search_with_data | ||
|
||
assert endpoint.called | ||
|
||
|
||
async def test__search_user_by_email_without_extra_data__succeed( | ||
respx_mock: MockRouter, | ||
host: str, | ||
bot_id: UUID, | ||
bot_account: BotAccountWithSecret, | ||
user_from_search_without_data: UserFromSearch, | ||
user_from_search_without_data_json: Dict[str, Any], | ||
) -> None: | ||
# - Arrange - | ||
endpoint = respx_mock.get( | ||
f"https://{host}/api/v3/botx/users/by_email", | ||
headers={"Authorization": "Bearer token"}, | ||
params={"email": "[email protected]"}, | ||
).mock( | ||
return_value=httpx.Response( | ||
HTTPStatus.OK, | ||
json={ | ||
"status": "ok", | ||
"result": user_from_search_without_data_json, | ||
}, | ||
), | ||
) | ||
|
||
built_bot = Bot(collectors=[HandlerCollector()], bot_accounts=[bot_account]) | ||
|
||
# - Act - | ||
async with lifespan_wrapper(built_bot) as bot: | ||
user = await bot.search_user_by_email( | ||
bot_id=bot_id, | ||
email="[email protected]", | ||
) | ||
|
||
# - Assert - | ||
assert user == user_from_search_without_data | ||
|
||
assert endpoint.called |
Oops, something went wrong.