chore: ci fixups and poetry update

This commit is contained in:
Andrew Herrington
2024-05-05 12:20:49 -05:00
parent cb862fa2c5
commit d0b986025e
24 changed files with 829 additions and 1026 deletions

View File

@@ -15,9 +15,7 @@ from healthchecks_io.client.exceptions import HCAPIError
@pytest.mark.asyncio
@pytest.mark.respx
async def test_acreate_check_200_context_manager(
fake_check_api_result, respx_mock, test_async_client
):
async def test_acreate_check_200_context_manager(fake_check_api_result, respx_mock, test_async_client):
checks_url = urljoin(test_async_client._api_url, "checks/")
respx_mock.post(checks_url).mock(
return_value=Response(
@@ -43,9 +41,7 @@ async def test_acreate_check_200_context_manager(
)
)
async with test_async_client as test_client:
check = await test_client.create_check(
CheckCreate(name="test", tags="test", desc="test")
)
check = await test_client.create_check(CheckCreate(name="test", tags="test", desc="test"))
assert check.name == "Backups"
@@ -76,9 +72,7 @@ async def test_acreate_check_200(fake_check_api_result, respx_mock, test_async_c
},
)
)
check = await test_async_client.create_check(
CheckCreate(name="test", tags="test", desc="test")
)
check = await test_async_client.create_check(CheckCreate(name="test", tags="test", desc="test"))
assert check.name == "Backups"
@@ -109,9 +103,7 @@ async def test_aupdate_check_200(fake_check_api_result, respx_mock, test_async_c
},
)
)
check = await test_async_client.update_check(
"test", CheckUpdate(name="test", desc="test")
)
check = await test_async_client.update_check("test", CheckUpdate(name="test", desc="test"))
assert check.name == "Backups"
@@ -120,9 +112,7 @@ async def test_aupdate_check_200(fake_check_api_result, respx_mock, test_async_c
async def test_aget_checks_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/")
respx_mock.get(checks_url).mock(
return_value=Response(status_code=200, json={"checks": [fake_check_api_result]})
)
respx_mock.get(checks_url).mock(return_value=Response(status_code=200, json={"checks": [fake_check_api_result]}))
checks = await test_async_client.get_checks()
assert len(checks) == 1
assert checks[0].name == fake_check_api_result["name"]
@@ -132,13 +122,9 @@ async def test_aget_checks_200(fake_check_api_result, respx_mock, test_async_cli
@pytest.mark.respx
async def test_aget_checks_pass_in_client(fake_check_api_result, respx_mock):
httpx_client = HTTPXAsyncClient()
test_async_client = AsyncClient(
api_key="test", api_url="http://localhost/api/", client=httpx_client
)
test_async_client = AsyncClient(api_key="test", api_url="http://localhost/api/", client=httpx_client)
checks_url = urljoin(test_async_client._api_url, "checks/")
respx_mock.get(checks_url).mock(
return_value=Response(status_code=200, json={"checks": [fake_check_api_result]})
)
respx_mock.get(checks_url).mock(return_value=Response(status_code=200, json={"checks": [fake_check_api_result]}))
checks = await test_async_client.get_checks()
assert len(checks) == 1
assert checks[0].name == fake_check_api_result["name"]
@@ -146,9 +132,7 @@ async def test_aget_checks_pass_in_client(fake_check_api_result, respx_mock):
@pytest.mark.asyncio
@pytest.mark.respx
async def test_aget_checks_exceptions(
fake_check_api_result, respx_mock, test_async_client
):
async def test_aget_checks_exceptions(fake_check_api_result, respx_mock, test_async_client):
checks_url = urljoin(test_async_client._api_url, "checks/")
# test exceptions
respx_mock.get(checks_url).mock(return_value=Response(status_code=401))
@@ -186,9 +170,7 @@ def test_finalizer_closes(test_async_client):
async def test_aget_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.get(checks_url).mock(
return_value=Response(status_code=200, json=fake_check_api_result)
)
respx_mock.get(checks_url).mock(return_value=Response(status_code=200, json=fake_check_api_result))
check = await test_async_client.get_check(check_id="test")
assert check.name == fake_check_api_result["name"]
@@ -207,9 +189,7 @@ async def test_acheck_get_404(respx_mock, test_async_client):
@pytest.mark.respx
async def test_pause_check_200(fake_check_api_result, respx_mock, test_async_client):
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)
)
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"]
@@ -229,9 +209,7 @@ async def test_acheck_pause_404(respx_mock, test_async_client):
async def test_adelete_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)
)
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"]
@@ -247,15 +225,9 @@ async def test_adelete_pause404(respx_mock, test_async_client):
@pytest.mark.asyncio
@pytest.mark.respx
async def test_aget_check_pings_200(
fake_check_pings_api_result, respx_mock, test_async_client
):
async def test_aget_check_pings_200(fake_check_pings_api_result, respx_mock, test_async_client):
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}
)
)
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"]
@@ -263,13 +235,9 @@ async def test_aget_check_pings_200(
@pytest.mark.asyncio
@pytest.mark.respx
async def test_aget_check_flips_200(
fake_check_flips_api_result, respx_mock, test_async_client
):
async def test_aget_check_flips_200(fake_check_flips_api_result, respx_mock, test_async_client):
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)
)
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"]
@@ -277,15 +245,9 @@ async def test_aget_check_flips_200(
@pytest.mark.asyncio
@pytest.mark.respx
async def test_get_check_flips_params_200(
fake_check_flips_api_result, respx_mock, test_async_client
):
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)
)
async def test_get_check_flips_params_200(fake_check_flips_api_result, respx_mock, test_async_client):
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"]
@@ -293,9 +255,7 @@ async def test_get_check_flips_params_200(
@pytest.mark.asyncio
@pytest.mark.respx
async def test_aget_check_flips_400(
fake_check_flips_api_result, respx_mock, test_async_client
):
async def test_aget_check_flips_400(fake_check_flips_api_result, respx_mock, test_async_client):
flips_url = urljoin(test_async_client._api_url, "checks/test/flips/")
respx_mock.get(flips_url).mock(return_value=Response(status_code=400))
with pytest.raises(BadAPIRequestError):
@@ -304,13 +264,9 @@ async def test_aget_check_flips_400(
@pytest.mark.asyncio
@pytest.mark.respx
async def test_aget_integrations(
fake_integrations_api_result, respx_mock, test_async_client
):
async def test_aget_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)
)
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"]
@@ -320,9 +276,7 @@ async def test_aget_integrations(
@pytest.mark.respx
async def test_aget_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)
)
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()
@@ -389,14 +343,10 @@ ping_test_parameters = [
@pytest.mark.asyncio
@pytest.mark.respx
@pytest.mark.parametrize(
"respx_mocker, tc, url, ping_method, method_kwargs", ping_test_parameters
)
@pytest.mark.parametrize("respx_mocker, tc, url, ping_method, method_kwargs", ping_test_parameters)
async def test_asuccess_ping(respx_mocker, tc, url, ping_method, method_kwargs):
channels_url = urljoin(tc._ping_url, url)
respx_mocker.post(channels_url).mock(
return_value=Response(status_code=200, text="OK")
)
respx_mocker.post(channels_url).mock(return_value=Response(status_code=200, text="OK"))
ping_method = getattr(tc, ping_method)
result = await ping_method(**method_kwargs)
assert result[0] is True