-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_errors.py
More file actions
28 lines (23 loc) · 830 Bytes
/
test_errors.py
File metadata and controls
28 lines (23 loc) · 830 Bytes
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
import pytest
import httpx
from geocodio.exceptions import (
InvalidRequestError, AuthenticationError, GeocodioServerError
)
def _add_err(httpx_mock, status_code):
# this should actually make the request and see and error response
# but we are mocking it here for testing purposes
httpx_mock.add_response(
url=httpx.URL("https://api.test/v1.10/geocode", params={"q": "bad input"}),
match_headers={"Authorization": "Bearer TEST_KEY"},
json={"error": "boom"},
status_code=status_code,
)
@pytest.mark.parametrize("code,exc", [
(422, InvalidRequestError),
(403, AuthenticationError),
(500, GeocodioServerError),
])
def test_error_mapping(client, httpx_mock, code, exc):
_add_err(httpx_mock, code)
with pytest.raises(exc):
client.geocode("bad input")