mirror of
https://github.com/andrewthetechie/py-healthchecks.io.git
synced 2025-12-11 03:51:26 +01:00
100% test coverage
This commit is contained in:
@@ -103,7 +103,6 @@ async def test_check_get_404(respx_mock, test_async_client):
|
|||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@pytest.mark.respx
|
@pytest.mark.respx
|
||||||
async def test_pause_check_200(fake_check_api_result, respx_mock, test_async_client):
|
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")
|
checks_url = urljoin(test_async_client._api_url, "checks/test/pause")
|
||||||
respx_mock.post(checks_url).mock(
|
respx_mock.post(checks_url).mock(
|
||||||
return_value=Response(status_code=200, json=fake_check_api_result)
|
return_value=Response(status_code=200, json=fake_check_api_result)
|
||||||
@@ -137,7 +136,6 @@ async def test_delete_check_200(fake_check_api_result, respx_mock, test_async_cl
|
|||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@pytest.mark.respx
|
@pytest.mark.respx
|
||||||
async def test_delete_pause404(respx_mock, test_async_client):
|
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")
|
checks_url = urljoin(test_async_client._api_url, "checks/test")
|
||||||
respx_mock.delete(checks_url).mock(return_value=Response(status_code=404))
|
respx_mock.delete(checks_url).mock(return_value=Response(status_code=404))
|
||||||
with pytest.raises(CheckNotFoundError):
|
with pytest.raises(CheckNotFoundError):
|
||||||
@@ -149,7 +147,6 @@ async def test_delete_pause404(respx_mock, test_async_client):
|
|||||||
async def test_get_check_pings_200(
|
async def test_get_check_pings_200(
|
||||||
fake_check_pings_api_result, respx_mock, test_async_client
|
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/")
|
checks_url = urljoin(test_async_client._api_url, "checks/test/pings/")
|
||||||
respx_mock.get(checks_url).mock(
|
respx_mock.get(checks_url).mock(
|
||||||
return_value=Response(
|
return_value=Response(
|
||||||
@@ -166,7 +163,6 @@ async def test_get_check_pings_200(
|
|||||||
async def test_get_check_flips_200(
|
async def test_get_check_flips_200(
|
||||||
fake_check_flips_api_result, respx_mock, test_async_client
|
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/")
|
checks_url = urljoin(test_async_client._api_url, "checks/test/flips/")
|
||||||
respx_mock.get(checks_url).mock(
|
respx_mock.get(checks_url).mock(
|
||||||
return_value=Response(status_code=200, json=fake_check_flips_api_result)
|
return_value=Response(status_code=200, json=fake_check_flips_api_result)
|
||||||
@@ -181,7 +177,6 @@ async def test_get_check_flips_200(
|
|||||||
async def test_get_check_flips_params_200(
|
async def test_get_check_flips_params_200(
|
||||||
fake_check_flips_api_result, respx_mock, test_async_client
|
fake_check_flips_api_result, respx_mock, test_async_client
|
||||||
):
|
):
|
||||||
assert test_async_client._client is not None
|
|
||||||
checks_url = urljoin(
|
checks_url = urljoin(
|
||||||
test_async_client._api_url, "checks/test/flips/?seconds=1&start=1&end=1"
|
test_async_client._api_url, "checks/test/flips/?seconds=1&start=1&end=1"
|
||||||
)
|
)
|
||||||
@@ -198,8 +193,32 @@ async def test_get_check_flips_params_200(
|
|||||||
async def test_get_check_flips_400(
|
async def test_get_check_flips_400(
|
||||||
fake_check_flips_api_result, respx_mock, test_async_client
|
fake_check_flips_api_result, respx_mock, test_async_client
|
||||||
):
|
):
|
||||||
assert test_async_client._client is not None
|
flips_url = urljoin(test_async_client._api_url, "checks/test/flips/")
|
||||||
checks_url = urljoin(test_async_client._api_url, "checks/test/flips/")
|
respx_mock.get(flips_url).mock(return_value=Response(status_code=400))
|
||||||
respx_mock.get(checks_url).mock(return_value=Response(status_code=400))
|
|
||||||
with pytest.raises(BadAPIRequestError):
|
with pytest.raises(BadAPIRequestError):
|
||||||
await test_async_client.get_check_flips("test")
|
await test_async_client.get_check_flips("test")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
@pytest.mark.respx
|
||||||
|
async def test_get_integrations(
|
||||||
|
fake_integrations_api_result, respx_mock, test_async_client
|
||||||
|
):
|
||||||
|
channels_url = urljoin(test_async_client._api_url, "channels/")
|
||||||
|
respx_mock.get(channels_url).mock(
|
||||||
|
return_value=Response(status_code=200, json=fake_integrations_api_result)
|
||||||
|
)
|
||||||
|
integrations = await test_async_client.get_integrations()
|
||||||
|
assert len(integrations) == len(fake_integrations_api_result["channels"])
|
||||||
|
assert integrations[0].id == fake_integrations_api_result["channels"][0]["id"]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
@pytest.mark.respx
|
||||||
|
async def test_get_badges(fake_badges_api_result, respx_mock, test_async_client):
|
||||||
|
channels_url = urljoin(test_async_client._api_url, "badges/")
|
||||||
|
respx_mock.get(channels_url).mock(
|
||||||
|
return_value=Response(status_code=200, json=fake_badges_api_result)
|
||||||
|
)
|
||||||
|
integrations = await test_async_client.get_badges()
|
||||||
|
assert integrations.keys() == fake_badges_api_result["badges"].keys()
|
||||||
|
|||||||
@@ -84,13 +84,12 @@ def fake_ro_check(fake_check: checks.Check):
|
|||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def test_async_client():
|
def test_async_client():
|
||||||
"""An AsyncClient for testing, set to a nonsense url so we aren't pinging healtchecks."""
|
"""An AsyncClient for testing, set to a nonsense url so we aren't pinging healtchecks."""
|
||||||
|
|
||||||
yield AsyncClient(api_key="test", api_url="https://localhost/api")
|
yield AsyncClient(api_key="test", api_url="https://localhost/api")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def fake_check_pings_api_result():
|
def fake_check_pings_api_result():
|
||||||
return [
|
yield [
|
||||||
{
|
{
|
||||||
"type": "success",
|
"type": "success",
|
||||||
"date": "2020-06-09T14:51:06.113073+00:00",
|
"date": "2020-06-09T14:51:06.113073+00:00",
|
||||||
@@ -134,8 +133,66 @@ def fake_check_pings_api_result():
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def fake_check_flips_api_result():
|
def fake_check_flips_api_result():
|
||||||
return [
|
yield [
|
||||||
{"timestamp": "2020-03-23T10:18:23+00:00", "up": 1},
|
{"timestamp": "2020-03-23T10:18:23+00:00", "up": 1},
|
||||||
{"timestamp": "2020-03-23T10:17:15+00:00", "up": 0},
|
{"timestamp": "2020-03-23T10:17:15+00:00", "up": 0},
|
||||||
{"timestamp": "2020-03-23T10:16:18+00:00", "up": 1},
|
{"timestamp": "2020-03-23T10:16:18+00:00", "up": 1},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def fake_integrations_api_result():
|
||||||
|
yield {
|
||||||
|
"channels": [
|
||||||
|
{
|
||||||
|
"id": "4ec5a071-2d08-4baa-898a-eb4eb3cd6941",
|
||||||
|
"name": "My Work Email",
|
||||||
|
"kind": "email",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "746a083e-f542-4554-be1a-707ce16d3acc",
|
||||||
|
"name": "My Phone",
|
||||||
|
"kind": "sms",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def fake_badges_api_result():
|
||||||
|
yield {
|
||||||
|
"badges": {
|
||||||
|
"backup": {
|
||||||
|
"svg": "https://healthchecks.io/badge/67541b37-8b9c-4d17-b952-690eae/LOegDs5M-2/backup.svg",
|
||||||
|
"svg3": "https://healthchecks.io/badge/67541b37-8b9c-4d17-b952-690eae/LOegDs5M/backup.svg",
|
||||||
|
"json": "https://healthchecks.io/badge/67541b37-8b9c-4d17-b952-690eae/LOegDs5M-2/backup.json",
|
||||||
|
"json3": "https://healthchecks.io/badge/67541b37-8b9c-4d17-b952-690eae/LOegDs5M/backup.json",
|
||||||
|
"shields": "https://healthchecks.io/badge/67541b37-8b9c-4d17-b952-690eae/LOegDs5M-2/backup.shields",
|
||||||
|
"shields3": "https://healthchecks.io/badge/67541b37-8b9c-4d17-b952-690eae/LOegDs5M/backup.shields",
|
||||||
|
},
|
||||||
|
"db": {
|
||||||
|
"svg": "https://healthchecks.io/badge/67541b37-8b9c-4d17-b952-690eae/99MuQaKm-2/db.svg",
|
||||||
|
"svg3": "https://healthchecks.io/badge/67541b37-8b9c-4d17-b952-690eae/99MuQaKm/db.svg",
|
||||||
|
"json": "https://healthchecks.io/badge/67541b37-8b9c-4d17-b952-690eae/99MuQaKm-2/db.json",
|
||||||
|
"json3": "https://healthchecks.io/badge/67541b37-8b9c-4d17-b952-690eae/99MuQaKm/db.json",
|
||||||
|
"shields": "https://healthchecks.io/badge/67541b37-8b9c-4d17-b952-690eae/99MuQaKm-2/db.shields",
|
||||||
|
"shields3": "https://healthchecks.io/badge/67541b37-8b9c-4d17-b952-690eae/99MuQaKm/db.shields",
|
||||||
|
},
|
||||||
|
"prod": {
|
||||||
|
"svg": "https://healthchecks.io/badge/67541b37-8b9c-4d17-b952-690eae/1TEhqie8-2/prod.svg",
|
||||||
|
"svg3": "https://healthchecks.io/badge/67541b37-8b9c-4d17-b952-690eae/1TEhqie8/prod.svg",
|
||||||
|
"json": "https://healthchecks.io/badge/67541b37-8b9c-4d17-b952-690eae/1TEhqie8-2/prod.json",
|
||||||
|
"json3": "https://healthchecks.io/badge/67541b37-8b9c-4d17-b952-690eae/1TEhqie8/prod.json",
|
||||||
|
"shields": "https://healthchecks.io/badge/67541b37-8b9c-4d17-b952-690eae/1TEhqie8-2/prod.shields",
|
||||||
|
"shields3": "https://healthchecks.io/badge/67541b37-8b9c-4d17-b952-690eae/1TEhqie8/prod.shields",
|
||||||
|
},
|
||||||
|
"*": {
|
||||||
|
"svg": "https://healthchecks.io/badge/67541b37-8b9c-4d17-b952-690eae/9X7kcZoe-2.svg",
|
||||||
|
"svg3": "https://healthchecks.io/badge/67541b37-8b9c-4d17-b952-690eae/9X7kcZoe.svg",
|
||||||
|
"json": "https://healthchecks.io/badge/67541b37-8b9c-4d17-b952-690eae/9X7kcZoe-2.json",
|
||||||
|
"json3": "https://healthchecks.io/badge/67541b37-8b9c-4d17-b952-690eae/9X7kcZoe.json",
|
||||||
|
"shields": "https://healthchecks.io/badge/67541b37-8b9c-4d17-b952-690eae/9X7kcZoe-2.shields",
|
||||||
|
"shields3": "https://healthchecks.io/badge/67541b37-8b9c-4d17-b952-690eae/9X7kcZoe.shields",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user