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
|
import pytest
from pyairnow import WebServiceAPI
from pyairnow.errors import AirNowError, EmptyResponseError, \
InvalidJsonError, InvalidKeyError
from .mock_api import MOCK_API_KEY
@pytest.mark.asyncio
async def test_api_not_authenticated(mock_airnowapi):
client = WebServiceAPI('')
with pytest.raises(InvalidKeyError) as exc_info:
await client.forecast.zipCode(90001)
assert 'not authenticated' in str(exc_info.value)
@pytest.mark.asyncio
async def test_api_invalid_key(mock_airnowapi):
client = WebServiceAPI('123ABC')
with pytest.raises(InvalidKeyError) as exc_info:
await client.forecast.zipCode(90001)
assert 'Invalid API key' in str(exc_info.value)
@pytest.mark.asyncio
async def test_api_bad_json(mock_airnowapi):
client = WebServiceAPI(MOCK_API_KEY)
with pytest.raises(InvalidJsonError):
await client.forecast.zipCode('bad_json')
@pytest.mark.asyncio
async def test_api_bad_json_2(mock_airnowapi):
client = WebServiceAPI(MOCK_API_KEY)
with pytest.raises(InvalidJsonError):
await client.forecast.zipCode('dict')
@pytest.mark.asyncio
async def test_api_empty_response(mock_airnowapi):
client = WebServiceAPI(MOCK_API_KEY)
with pytest.raises(EmptyResponseError):
await client.forecast.zipCode('empty')
@pytest.mark.asyncio
async def test_api_unexpected_error(mock_airnowapi):
client = WebServiceAPI(MOCK_API_KEY)
with pytest.raises(AirNowError) as exc_info:
await client.forecast.zipCode('error')
assert 'Client Error' in str(exc_info.value)
@pytest.mark.asyncio
async def test_api_unexpected_error_1(mock_airnowapi):
client = WebServiceAPI(MOCK_API_KEY)
with pytest.raises(AirNowError) as exc_info:
await client.forecast.zipCode('error1')
assert 'Internal Server Error' in str(exc_info.value)
@pytest.mark.asyncio
async def test_api_unexpected_error_2(mock_airnowapi):
client = WebServiceAPI(MOCK_API_KEY)
with pytest.raises(AirNowError) as exc_info:
await client.forecast.zipCode('error2')
assert 'Internal Server Error' in str(exc_info.value)
|