-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathtest_search_user_by_emails.py
More file actions
129 lines (111 loc) · 3.12 KB
/
Copy pathtest_search_user_by_emails.py
File metadata and controls
129 lines (111 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
from http import HTTPStatus
from typing import Any
from uuid import UUID
import pytest
from respx.router import MockRouter
from pybotx import UserFromSearch
from tests.testkit import BotXRequest, assert_deep_equal, mock_botx, ok_payload
pytestmark = [
pytest.mark.asyncio,
pytest.mark.mock_authorization,
pytest.mark.usefixtures("respx_mock"),
]
async def test__search_user_by_email__succeed(
respx_mock: MockRouter,
host: str,
bot_id: UUID,
user_from_search_with_data: UserFromSearch,
user_from_search_with_data_json: dict[str, Any],
bot_factory: Any,
) -> None:
# - Arrange -
user_emails = ["ad_user@cts.com"]
request = BotXRequest(
method="POST",
path="/api/v3/botx/users/by_email",
json={"emails": user_emails},
)
endpoint = mock_botx(
respx_mock,
host,
request,
ok_payload([user_from_search_with_data_json]),
HTTPStatus.OK,
)
# - Act -
async with bot_factory() as bot:
users = await bot.search_user_by_emails(
bot_id=bot_id,
emails=user_emails,
)
# - Assert -
assert_deep_equal(users, [user_from_search_with_data])
assert endpoint.called
async def test__search_user_by_email_without_data__succeed(
respx_mock: MockRouter,
host: str,
bot_id: UUID,
user_from_search_without_data: UserFromSearch,
user_from_search_without_data_json: dict[str, Any],
bot_factory: Any,
) -> None:
# - Arrange -
user_emails = ["ad_user@cts.com"]
request = BotXRequest(
method="POST",
path="/api/v3/botx/users/by_email",
json={"emails": user_emails},
)
endpoint = mock_botx(
respx_mock,
host,
request,
ok_payload([user_from_search_without_data_json]),
HTTPStatus.OK,
)
# - Act -
async with bot_factory() as bot:
users = await bot.search_user_by_emails(
bot_id=bot_id,
emails=user_emails,
)
# - Assert -
assert_deep_equal(users, [user_from_search_without_data])
assert endpoint.called
async def test__search_user_by_email_with_trusts_search__succeed(
respx_mock: MockRouter,
host: str,
bot_id: UUID,
user_from_search_with_data: UserFromSearch,
user_from_search_with_data_json: dict[str, Any],
bot_factory: Any,
) -> None:
# - Arrange -
user_emails = ["ad_user@cts.com"]
request = BotXRequest(
method="POST",
path="/api/v3/botx/users/by_email",
json={
"emails": user_emails,
"trusts_search": True,
"partial_response": True,
},
)
endpoint = mock_botx(
respx_mock,
host,
request,
ok_payload([user_from_search_with_data_json]),
HTTPStatus.OK,
)
# - Act -
async with bot_factory() as bot:
users = await bot.search_user_by_emails(
bot_id=bot_id,
emails=user_emails,
trusts_search=True,
partial_response=True,
)
# - Assert -
assert_deep_equal(users, [user_from_search_with_data])
assert endpoint.called