|
4 | 4 |
|
5 | 5 | from huntflow_api_client import HuntflowAPI |
6 | 6 | 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 | +) |
7 | 12 | from huntflow_api_client.models.response.user_settings import ( |
8 | 13 | CalendarAccountsListResponse, |
| 14 | + EmailAccount, |
9 | 15 | EmailAccountsListResponse, |
10 | 16 | ) |
11 | 17 | from huntflow_api_client.tokens.proxy import HuntflowTokenProxy |
12 | 18 | from tests.api import BASE_URL, VERSIONED_BASE_URL |
13 | 19 |
|
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", |
25 | 27 | } |
26 | 28 |
|
| 29 | +GET_USER_EMAIL_ACCOUNTS_RESPONSE: Dict[str, Any] = {"items": [EMAIL_ACCOUNT]} |
| 30 | + |
27 | 31 | GET_USER_CALENDAR_ACCOUNTS_RESPONSE: Dict[str, Any] = { |
28 | 32 | "items": [ |
29 | 33 | { |
|
43 | 47 | ], |
44 | 48 | } |
45 | 49 |
|
| 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 | + |
46 | 74 |
|
47 | 75 | async def test_get_email_accounts( |
48 | 76 | httpx_mock: HTTPXMock, |
@@ -72,3 +100,86 @@ async def test_get_calendar_accounts( |
72 | 100 |
|
73 | 101 | response = await settings.get_calendar_accounts() |
74 | 102 | 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