Skip to content

Commit 9abc1d0

Browse files
author
koval
committed
Add tests.
1 parent ed781f4 commit 9abc1d0

2 files changed

Lines changed: 128 additions & 17 deletions

File tree

huntflow_api_client/models/request/user_settings.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ class OtherEmailAccountRequest(JsonRequestModel):
2626
email: EmailStr = Field(..., description="Email address")
2727
password: str = Field(..., description="Mailbox password")
2828

29-
inhost: str = Field(..., description="Inbound mail server URL without protocol")
30-
inport: Optional[PositiveInt] = Field(None, description="Inbound mail port")
31-
in_secure: bool = Field(False, description="Inbound mail server uses SSL")
32-
outhost: str = Field(..., description="Outbound mail server URL without protocol")
33-
outport: Optional[PositiveInt] = Field(None, description="Outbound mail port")
34-
out_secure: bool = Field(False, description="Outbound mail server uses SSL")
29+
inbound_host: str = Field(..., description="Inbound mail server URL without protocol")
30+
inbound_port: Optional[PositiveInt] = Field(None, description="Inbound mail port")
31+
inbound_ssl: bool = Field(False, description="Inbound mail server uses SSL")
32+
outbound_host: str = Field(..., description="Outbound mail server URL without protocol")
33+
outbound_port: Optional[PositiveInt] = Field(None, description="Outbound mail port")
34+
outbound_ssl: bool = Field(False, description="Outbound mail server uses SSL")
3535
type: EmailInboundType = Field(..., description="Type of inbound mail server")

tests/test_entities/test_user_settings.py

Lines changed: 122 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,30 @@
44

55
from huntflow_api_client import HuntflowAPI
66
from huntflow_api_client.entities.user_settings import UserSettings
7+
from huntflow_api_client.models.common import StatusResponse
8+
from huntflow_api_client.models.request.user_settings import (
9+
ExchangeEmailAccountRequest,
10+
OtherEmailAccountRequest,
11+
)
712
from huntflow_api_client.models.response.user_settings import (
813
CalendarAccountsListResponse,
14+
EmailAccount,
915
EmailAccountsListResponse,
1016
)
1117
from huntflow_api_client.tokens.proxy import HuntflowTokenProxy
1218
from tests.api import BASE_URL, VERSIONED_BASE_URL
1319

14-
GET_USER_EMAIL_ACCOUNTS_RESPONSE: Dict[str, Any] = {
15-
"items": [
16-
{
17-
"id": 10,
18-
"name": "test@example.com",
19-
"email": "test@example.com",
20-
"receive": False,
21-
"send": False,
22-
"last_sync": "2020-01-01T00:00:00+03:00",
23-
},
24-
],
20+
EMAIL_ACCOUNT: Dict[str, Any] = {
21+
"id": 10,
22+
"name": "test@example.com",
23+
"email": "test@example.com",
24+
"receive": False,
25+
"send": False,
26+
"last_sync": "2020-01-01T00:00:00+03:00",
2527
}
2628

29+
GET_USER_EMAIL_ACCOUNTS_RESPONSE: Dict[str, Any] = {"items": [EMAIL_ACCOUNT]}
30+
2731
GET_USER_CALENDAR_ACCOUNTS_RESPONSE: Dict[str, Any] = {
2832
"items": [
2933
{
@@ -43,6 +47,30 @@
4347
],
4448
}
4549

50+
EXCHANGE_EMAIL_ACCOUNT_CREATE_REQUEST: Dict[str, Any] = {
51+
"access_type": "DEFAULT",
52+
"email": "mail@mail.ru",
53+
"ews_url": "https://your-company.org/ews/exchange.asmx",
54+
"password": "string",
55+
"user": "string",
56+
}
57+
58+
ACCOUNT_EMAIL_ID = 1
59+
60+
IMAP_EMAIL_ACCOUNT_CREATE_REQUEST: Dict[str, Any] = {
61+
"email": "mail@mail.ru",
62+
"password": "string",
63+
"inbound_host": "imap.your-company.org",
64+
"inbound_port": 1,
65+
"inbound_ssl": False,
66+
"outbound_host": "smtp.your-company.org",
67+
"outbound_port": 1,
68+
"outbound_ssl": False,
69+
"type": "IMAP",
70+
}
71+
72+
DELETE_ACCOUNT_EMAIL_RESPONSE: Dict[str, Any] = {"status": True}
73+
4674

4775
async def test_get_email_accounts(
4876
httpx_mock: HTTPXMock,
@@ -72,3 +100,86 @@ async def test_get_calendar_accounts(
72100

73101
response = await settings.get_calendar_accounts()
74102
assert response == CalendarAccountsListResponse(**GET_USER_CALENDAR_ACCOUNTS_RESPONSE)
103+
104+
105+
async def test_create_exchange_email_account(
106+
httpx_mock: HTTPXMock,
107+
token_proxy: HuntflowTokenProxy,
108+
) -> None:
109+
httpx_mock.add_response(
110+
url=f"{VERSIONED_BASE_URL}/email_accounts/exchange",
111+
json=EMAIL_ACCOUNT,
112+
)
113+
api_client = HuntflowAPI(BASE_URL, token_proxy=token_proxy)
114+
115+
api_request = ExchangeEmailAccountRequest(**EXCHANGE_EMAIL_ACCOUNT_CREATE_REQUEST)
116+
settings = UserSettings(api_client)
117+
118+
response = await settings.create_exchange_email_account(api_request)
119+
assert response == EmailAccount(**EMAIL_ACCOUNT)
120+
121+
122+
async def test_update_exchange_email_account(
123+
httpx_mock: HTTPXMock,
124+
token_proxy: HuntflowTokenProxy,
125+
) -> None:
126+
httpx_mock.add_response(
127+
url=f"{VERSIONED_BASE_URL}/email_accounts/exchange/{ACCOUNT_EMAIL_ID}",
128+
json=EMAIL_ACCOUNT,
129+
)
130+
api_client = HuntflowAPI(BASE_URL, token_proxy=token_proxy)
131+
132+
api_request = ExchangeEmailAccountRequest(**EXCHANGE_EMAIL_ACCOUNT_CREATE_REQUEST)
133+
settings = UserSettings(api_client)
134+
135+
response = await settings.update_exchange_email_account(api_request, ACCOUNT_EMAIL_ID)
136+
assert response == EmailAccount(**EMAIL_ACCOUNT)
137+
138+
139+
async def test_create_other_email_account(
140+
httpx_mock: HTTPXMock,
141+
token_proxy: HuntflowTokenProxy,
142+
) -> None:
143+
httpx_mock.add_response(
144+
url=f"{VERSIONED_BASE_URL}/email_accounts/other",
145+
json=EMAIL_ACCOUNT,
146+
)
147+
api_client = HuntflowAPI(BASE_URL, token_proxy=token_proxy)
148+
149+
api_request = OtherEmailAccountRequest(**IMAP_EMAIL_ACCOUNT_CREATE_REQUEST)
150+
settings = UserSettings(api_client)
151+
152+
response = await settings.create_other_email_account(api_request)
153+
assert response == EmailAccount(**EMAIL_ACCOUNT)
154+
155+
156+
async def test_update_other_email_account(
157+
httpx_mock: HTTPXMock,
158+
token_proxy: HuntflowTokenProxy,
159+
) -> None:
160+
httpx_mock.add_response(
161+
url=f"{VERSIONED_BASE_URL}/email_accounts/other/{ACCOUNT_EMAIL_ID}",
162+
json=EMAIL_ACCOUNT,
163+
)
164+
api_client = HuntflowAPI(BASE_URL, token_proxy=token_proxy)
165+
166+
api_request = OtherEmailAccountRequest(**IMAP_EMAIL_ACCOUNT_CREATE_REQUEST)
167+
settings = UserSettings(api_client)
168+
169+
response = await settings.update_other_email_account(api_request, ACCOUNT_EMAIL_ID)
170+
assert response == EmailAccount(**EMAIL_ACCOUNT)
171+
172+
173+
async def test_delete_email_account(
174+
httpx_mock: HTTPXMock,
175+
token_proxy: HuntflowTokenProxy,
176+
) -> None:
177+
httpx_mock.add_response(
178+
url=f"{VERSIONED_BASE_URL}/email_accounts/{ACCOUNT_EMAIL_ID}",
179+
json=DELETE_ACCOUNT_EMAIL_RESPONSE,
180+
)
181+
api_client = HuntflowAPI(BASE_URL, token_proxy=token_proxy)
182+
settings = UserSettings(api_client)
183+
184+
response = await settings.delete_email_account(ACCOUNT_EMAIL_ID)
185+
assert response == StatusResponse(**DELETE_ACCOUNT_EMAIL_RESPONSE)

0 commit comments

Comments
 (0)