|
7 | 7 | from mailtrap.config import GENERAL_HOST |
8 | 8 | from mailtrap.exceptions import APIError |
9 | 9 | from mailtrap.http import HttpClient |
| 10 | +from mailtrap.models.common import DeletedObject |
10 | 11 | from mailtrap.models.organizations import CreateSubAccountParams |
11 | 12 | from mailtrap.models.organizations import SubAccount |
12 | 13 | from tests import conftest |
@@ -152,3 +153,59 @@ def test_create_should_return_sub_account_and_wrap_body_under_account_key( |
152 | 153 | responses.calls[0].request.body |
153 | 154 | == b'{"account": {"name": "New Team Account"}}' |
154 | 155 | ) |
| 156 | + |
| 157 | + @pytest.mark.parametrize( |
| 158 | + "status_code,response_json,expected_error_message", |
| 159 | + [ |
| 160 | + ( |
| 161 | + conftest.UNAUTHORIZED_STATUS_CODE, |
| 162 | + conftest.UNAUTHORIZED_RESPONSE, |
| 163 | + conftest.UNAUTHORIZED_ERROR_MESSAGE, |
| 164 | + ), |
| 165 | + ( |
| 166 | + conftest.FORBIDDEN_STATUS_CODE, |
| 167 | + conftest.FORBIDDEN_RESPONSE, |
| 168 | + conftest.FORBIDDEN_ERROR_MESSAGE, |
| 169 | + ), |
| 170 | + ( |
| 171 | + conftest.NOT_FOUND_STATUS_CODE, |
| 172 | + conftest.NOT_FOUND_RESPONSE, |
| 173 | + conftest.NOT_FOUND_ERROR_MESSAGE, |
| 174 | + ), |
| 175 | + ( |
| 176 | + conftest.RATE_LIMIT_ERROR_STATUS_CODE, |
| 177 | + conftest.RATE_LIMIT_ERROR_RESPONSE, |
| 178 | + conftest.RATE_LIMIT_ERROR_MESSAGE, |
| 179 | + ), |
| 180 | + ], |
| 181 | + ) |
| 182 | + @responses.activate |
| 183 | + def test_delete_should_raise_api_errors( |
| 184 | + self, |
| 185 | + client: SubAccountsApi, |
| 186 | + status_code: int, |
| 187 | + response_json: dict, |
| 188 | + expected_error_message: str, |
| 189 | + ) -> None: |
| 190 | + responses.delete( |
| 191 | + f"{BASE_SUB_ACCOUNTS_URL}/{SUB_ACCOUNT_ID}", |
| 192 | + status=status_code, |
| 193 | + json=response_json, |
| 194 | + ) |
| 195 | + |
| 196 | + with pytest.raises(APIError) as exc_info: |
| 197 | + client.delete(SUB_ACCOUNT_ID) |
| 198 | + |
| 199 | + assert expected_error_message in str(exc_info.value) |
| 200 | + |
| 201 | + @responses.activate |
| 202 | + def test_delete_should_return_deleted_object(self, client: SubAccountsApi) -> None: |
| 203 | + responses.delete( |
| 204 | + f"{BASE_SUB_ACCOUNTS_URL}/{SUB_ACCOUNT_ID}", |
| 205 | + status=204, |
| 206 | + ) |
| 207 | + |
| 208 | + result = client.delete(SUB_ACCOUNT_ID) |
| 209 | + |
| 210 | + assert isinstance(result, DeletedObject) |
| 211 | + assert result.id == SUB_ACCOUNT_ID |
0 commit comments