more api methods

This commit is contained in:
Andrew Herrington
2021-12-10 22:42:03 -06:00
parent 15d1d41340
commit 7c3f263b5a
6 changed files with 284 additions and 8 deletions

View File

@@ -7,7 +7,7 @@ from httpx import Response
from healthchecks_io.client import AsyncClient
from healthchecks_io.client.exceptions import HCAPIAuthError
from healthchecks_io.client.exceptions import HCAPIError, CheckNotFoundError
from healthchecks_io.client.exceptions import HCAPIError, CheckNotFoundError, BadAPIRequestError
@pytest.mark.asyncio
@@ -98,3 +98,101 @@ async def test_check_get_404(respx_mock, test_async_client):
)
with pytest.raises(CheckNotFoundError):
await test_async_client.get_check("test")
@pytest.mark.asyncio
@pytest.mark.respx
async def test_pause_check_200(fake_check_api_result, respx_mock, test_async_client):
assert test_async_client._client is not None
checks_url = urljoin(test_async_client._api_url, "checks/test/pause")
respx_mock.post(checks_url).mock(
return_value=Response(status_code=200, json=fake_check_api_result)
)
check = await test_async_client.pause_check(check_id="test")
assert check.name == fake_check_api_result["name"]
@pytest.mark.asyncio
@pytest.mark.respx
async def test_check_pause_404(respx_mock, test_async_client):
assert test_async_client._client is not None
checks_url = urljoin(test_async_client._api_url, "checks/test/pause")
respx_mock.post(checks_url).mock(
return_value=Response(status_code=404)
)
with pytest.raises(CheckNotFoundError):
await test_async_client.pause_check("test")
@pytest.mark.asyncio
@pytest.mark.respx
async def test_delete_check_200(fake_check_api_result, respx_mock, test_async_client):
assert test_async_client._client is not None
checks_url = urljoin(test_async_client._api_url, "checks/test")
respx_mock.delete(checks_url).mock(
return_value=Response(status_code=200, json=fake_check_api_result)
)
check = await test_async_client.delete_check(check_id="test")
assert check.name == fake_check_api_result["name"]
@pytest.mark.asyncio
@pytest.mark.respx
async def test_delete_pause404(respx_mock, test_async_client):
assert test_async_client._client is not None
checks_url = urljoin(test_async_client._api_url, "checks/test")
respx_mock.delete(checks_url).mock(
return_value=Response(status_code=404)
)
with pytest.raises(CheckNotFoundError):
await test_async_client.delete_check("test")
@pytest.mark.asyncio
@pytest.mark.respx
async def test_get_check_pings_200(fake_check_pings_api_result, respx_mock, test_async_client):
assert test_async_client._client is not None
checks_url = urljoin(test_async_client._api_url, "checks/test/pings/")
respx_mock.get(checks_url).mock(
return_value=Response(status_code=200, json={"pings": fake_check_pings_api_result})
)
pings = await test_async_client.get_check_pings("test")
assert len(pings) == len(fake_check_pings_api_result)
assert pings[0].type == fake_check_pings_api_result[0]['type']
@pytest.mark.asyncio
@pytest.mark.respx
async def test_get_check_flips_200(fake_check_flips_api_result, respx_mock, test_async_client):
assert test_async_client._client is not None
checks_url = urljoin(test_async_client._api_url, "checks/test/flips/")
respx_mock.get(checks_url).mock(
return_value=Response(status_code=200, json=fake_check_flips_api_result)
)
flips = await test_async_client.get_check_flips("test")
assert len(flips) == len(fake_check_flips_api_result)
assert flips[0].up == fake_check_flips_api_result[0]['up']
@pytest.mark.asyncio
@pytest.mark.respx
async def test_get_check_flips_params_200(fake_check_flips_api_result, respx_mock, test_async_client):
assert test_async_client._client is not None
checks_url = urljoin(test_async_client._api_url, "checks/test/flips/?seconds=1&start=1&end=1")
respx_mock.get(checks_url).mock(
return_value=Response(status_code=200, json=fake_check_flips_api_result)
)
flips = await test_async_client.get_check_flips("test", seconds=1, start=1, end=1)
assert len(flips) == len(fake_check_flips_api_result)
assert flips[0].up == fake_check_flips_api_result[0]['up']
@pytest.mark.asyncio
@pytest.mark.respx
async def test_get_check_flips_400(fake_check_flips_api_result, respx_mock, test_async_client):
assert test_async_client._client is not None
checks_url = urljoin(test_async_client._api_url, "checks/test/flips/")
respx_mock.get(checks_url).mock(
return_value=Response(status_code=400)
)
with pytest.raises(BadAPIRequestError):
await test_async_client.get_check_flips("test")