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

@@ -13,10 +13,7 @@ from healthchecks_io import NonUniqueSlugError
def test_abstract_add_url_params(test_abstract_client):
url = test_abstract_client._add_url_params(
"http://test.com/?test=test", {"test": "test2"}
)
url = test_abstract_client._add_url_params("http://test.com/?test=test", {"test": "test2"})
assert url == "http://test.com/?test=test2"

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

View File

@@ -76,7 +76,6 @@ async def test_check_trap_async_exception(respx_mock, test_async_client):
@pytest.mark.asyncio
async def test_check_trap_wrong_client_error(test_client, test_async_client):
with pytest.raises(WrongClientError):
async with CheckTrap(test_client, uuid="test"):
pass

View File

@@ -14,9 +14,7 @@ from healthchecks_io.client.exceptions import HCAPIError
@pytest.mark.respx
def test_create_check_200_context_manager(
fake_check_api_result, respx_mock, test_client
):
def test_create_check_200_context_manager(fake_check_api_result, respx_mock, test_client):
checks_url = urljoin(test_client._api_url, "checks/")
respx_mock.post(checks_url).mock(
return_value=Response(
@@ -110,9 +108,7 @@ def test_update_check_200(fake_check_api_result, respx_mock, test_client):
def test_get_checks_200(fake_check_api_result, respx_mock, test_client):
assert test_client._client is not None
checks_url = urljoin(test_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 = test_client.get_checks()
assert len(checks) == 1
assert checks[0].name == fake_check_api_result["name"]
@@ -121,13 +117,9 @@ def test_get_checks_200(fake_check_api_result, respx_mock, test_client):
@pytest.mark.respx
def test_get_checks_pass_in_client(fake_check_api_result, respx_mock):
httpx_client = HTTPXClient()
test_client = Client(
api_key="test", api_url="http://localhost/api/", client=httpx_client
)
test_client = Client(api_key="test", api_url="http://localhost/api/", client=httpx_client)
checks_url = urljoin(test_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 = test_client.get_checks()
assert len(checks) == 1
assert checks[0].name == fake_check_api_result["name"]
@@ -169,9 +161,7 @@ def test_finalizer_closes(test_client):
def test_get_check_200(fake_check_api_result, respx_mock, test_client):
assert test_client._client is not None
checks_url = urljoin(test_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 = test_client.get_check(check_id="test")
assert check.name == fake_check_api_result["name"]
@@ -188,9 +178,7 @@ def test_check_get_404(respx_mock, test_client):
@pytest.mark.respx
def test_pause_check_200(fake_check_api_result, respx_mock, test_client):
checks_url = urljoin(test_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 = test_client.pause_check(check_id="test")
assert check.name == fake_check_api_result["name"]
@@ -208,9 +196,7 @@ def test_check_pause_404(respx_mock, test_client):
def test_delete_check_200(fake_check_api_result, respx_mock, test_client):
assert test_client._client is not None
checks_url = urljoin(test_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 = test_client.delete_check(check_id="test")
assert check.name == fake_check_api_result["name"]
@@ -226,11 +212,7 @@ def test_delete_pause404(respx_mock, test_client):
@pytest.mark.respx
def test_get_check_pings_200(fake_check_pings_api_result, respx_mock, test_client):
checks_url = urljoin(test_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 = test_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"]
@@ -239,24 +221,16 @@ def test_get_check_pings_200(fake_check_pings_api_result, respx_mock, test_clien
@pytest.mark.respx
def test_get_check_flips_200(fake_check_flips_api_result, respx_mock, test_client):
checks_url = urljoin(test_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 = test_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.respx
def test_get_check_flips_params_200(
fake_check_flips_api_result, respx_mock, test_client
):
checks_url = urljoin(
test_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)
)
def test_get_check_flips_params_200(fake_check_flips_api_result, respx_mock, test_client):
checks_url = urljoin(test_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 = test_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"]
@@ -273,9 +247,7 @@ def test_get_check_flips_400(fake_check_flips_api_result, respx_mock, test_clien
@pytest.mark.respx
def test_get_integrations(fake_integrations_api_result, respx_mock, test_client):
channels_url = urljoin(test_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 = test_client.get_integrations()
assert len(integrations) == len(fake_integrations_api_result["channels"])
assert integrations[0].id == fake_integrations_api_result["channels"][0]["id"]
@@ -284,9 +256,7 @@ def test_get_integrations(fake_integrations_api_result, respx_mock, test_client)
@pytest.mark.respx
def test_get_badges(fake_badges_api_result, respx_mock, test_client):
channels_url = urljoin(test_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 = test_client.get_badges()
assert integrations.keys() == fake_badges_api_result["badges"].keys()
@@ -352,14 +322,10 @@ ping_test_parameters = [
@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)
def test_success_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, text = ping_method(**method_kwargs)
assert result is True

View File

@@ -1,6 +1,4 @@
from datetime import datetime
from typing import Dict
from typing import Union
import pytest
@@ -11,7 +9,7 @@ from healthchecks_io.schemas import checks
@pytest.fixture
def fake_check_api_result() -> Dict[str, Union[str, int]]:
def fake_check_api_result() -> dict[str, str | int]:
yield {
"name": "Test Check",
"slug": "Test Check",
@@ -33,7 +31,7 @@ def fake_check_api_result() -> Dict[str, Union[str, int]]:
@pytest.fixture
def fake_check_ro_api_result() -> Dict[str, Union[str, int]]:
def fake_check_ro_api_result() -> dict[str, str | int]:
yield {
"name": "Test Check",
"slug": "Test Check",

View File

@@ -37,27 +37,19 @@ def test_check_create_validators():
# test validate_schedule
with pytest.raises(ValidationError):
check_create = checks.CheckCreate(
name="Test", tags="", desc="Test", schedule="no good"
)
check_create = checks.CheckCreate(name="Test", tags="", desc="Test", schedule="no good")
# test validate_tz
with pytest.raises(ValidationError):
check_create = checks.CheckCreate(
name="Test", tags="", desc="Test", tz="no good"
)
check_create = checks.CheckCreate(name="Test", tags="", desc="Test", tz="no good")
# test validate_methods
with pytest.raises(ValidationError):
check_create = checks.CheckCreate(
name="Test", tags="", desc="Test", methods="no good"
)
check_create = checks.CheckCreate(name="Test", tags="", desc="Test", methods="no good")
# test validate_unique
with pytest.raises(ValidationError):
check_create = checks.CheckCreate(
name="Test", tags="", desc="Test", unique=["no good"]
)
check_create = checks.CheckCreate(name="Test", tags="", desc="Test", unique=["no good"])
def test_check_pings_from_api():