Skip to content

Commit 85524fc

Browse files
fix(checks): fixed __slots__ in RabbitMQHealthCheck, renamed check_pydantinc_installed -> check_pydantic_installed, from_dsn for MongoHealthCheck and parse_dsn for BasePostgreSQLHealthCheck more stable
1 parent 5e544fc commit 85524fc

10 files changed

Lines changed: 26 additions & 20 deletions

File tree

fast_healthchecks/checks/_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def from_dsn(
4646
raise NotImplementedError
4747

4848
@classmethod
49-
def check_pydantinc_installed(cls) -> None:
49+
def check_pydantic_installed(cls) -> None:
5050
"""Check if Pydantic is installed."""
5151
if not PYDANTIC_INSTALLED:
5252
msg = "Pydantic is not installed"

fast_healthchecks/checks/mongo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def __init__( # noqa: PLR0913
9797
9898
Args:
9999
hosts: The MongoDB host or list of hosts.
100-
port: The MongoDB port (используется, если host — строка).
100+
port: The MongoDB port (used when hosts is a single string).
101101
user: The MongoDB user.
102102
password: The MongoDB password.
103103
database: The MongoDB database to use.
@@ -126,7 +126,7 @@ def parse_dsn(cls, dsn: str) -> ParseDSNResult:
126126
"""
127127
parse_result: ParseResult = urlparse(dsn)
128128
query = (
129-
{k: unquote(v) for k, v in (q.split("=") for q in parse_result.query.split("&"))}
129+
{k: unquote(v) for k, v in (q.split("=", 1) for q in parse_result.query.split("&"))}
130130
if parse_result.query
131131
else {}
132132
)
@@ -156,7 +156,7 @@ def from_dsn(
156156
hosts: str | list[str]
157157
port: int | None
158158
if "," in parse_result.netloc:
159-
hosts = parse_result.netloc.split("@")[1].split(",")
159+
hosts = parse_result.netloc.split("@")[-1].split(",")
160160
port = None
161161
else:
162162
hosts = parse_result.hostname or "localhost"

fast_healthchecks/checks/postgresql/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def parse_dsn(cls, dsn: str) -> ParseDSNResult:
125125
"""
126126
parse_result: ParseResult = urlparse(dsn)
127127
query = (
128-
{k: unquote(v) for k, v in (q.split("=") for q in parse_result.query.split("&"))}
128+
{k: unquote(v) for k, v in (q.split("=", 1) for q in parse_result.query.split("&"))}
129129
if parse_result.query
130130
else {}
131131
)

fast_healthchecks/checks/rabbitmq.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class RabbitMQHealthCheck(HealthCheckDSN[HealthCheckResult]):
5959
_vhost: The RabbitMQ virtual host.
6060
"""
6161

62-
__slots__ = ("_host", "_name", "_password", "_port", "_secure", "_timeout", "_user")
62+
__slots__ = ("_host", "_name", "_password", "_port", "_secure", "_timeout", "_user", "_vhost")
6363

6464
_host: str
6565
_port: int

fast_healthchecks/checks/types.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@
3232
from fast_healthchecks.checks.rabbitmq import RabbitMQHealthCheck
3333
except ImportError:
3434
RabbitMQHealthCheck = Any # ty: ignore[invalid-assignment]
35-
try:
36-
from fast_healthchecks.checks.rabbitmq import RabbitMQHealthCheck
37-
except ImportError:
38-
RabbitMQHealthCheck = Any # ty: ignore[invalid-assignment]
3935
try:
4036
from fast_healthchecks.checks.redis import RedisHealthCheck
4137
except ImportError:

fast_healthchecks/integrations/base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from fast_healthchecks.checks.types import Check
1212
from fast_healthchecks.models import HealthcheckReport, HealthCheckResult
1313

14-
HandlerType: TypeAlias = Callable[["ProbeAsgiResponse"], Awaitable[dict[str, str]]]
14+
HandlerType: TypeAlias = Callable[["ProbeAsgiResponse"], Awaitable[dict[str, Any]]]
1515

1616

1717
class Probe(NamedTuple):
@@ -48,11 +48,11 @@ class ProbeAsgiResponse(NamedTuple):
4848
"""A response from an ASGI probe.
4949
5050
Args:
51-
body: The body of the response.
52-
status_code: The status code of the response.
51+
data: The response data (healthcheck results).
52+
healthy: Whether all healthchecks passed.
5353
"""
5454

55-
data: dict[str, str]
55+
data: dict[str, Any]
5656
healthy: bool
5757

5858

tests/unit/checks/postgresql/test_asyncpg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ def test_from_dsn(
674674
exception: type[BaseException] | None,
675675
) -> None:
676676
parse_result: ParseResult = urlparse(args[0])
677-
query = {k: unquote(v) for k, v in (q.split("=") for q in parse_result.query.split("&"))}
677+
query = {k: unquote(v) for k, v in (q.split("=", 1) for q in parse_result.query.split("&"))}
678678
files = [y for x, y in query.items() if x in {"sslcert", "sslkey", "sslrootcert"}]
679679

680680
if exception is not None and isinstance(expected, str):

tests/unit/checks/postgresql/test_psycopg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,7 @@ def test_from_dsn(
11421142
exception: type[BaseException] | None,
11431143
) -> None:
11441144
parse_result: ParseResult = urlparse(args[0])
1145-
query = {k: unquote(v) for k, v in (q.split("=") for q in parse_result.query.split("&"))}
1145+
query = {k: unquote(v) for k, v in (q.split("=", 1) for q in parse_result.query.split("&"))}
11461146
files = [y for x, y in query.items() if x in {"sslcert", "sslkey", "sslrootcert"}]
11471147

11481148
if exception is not None and isinstance(expected, str):

tests/unit/checks/test__base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ async def __call__(self) -> HealthCheckResult:
1515
return HealthCheckResult(name="dummy", healthy=True)
1616

1717

18-
def test_check_pydantinc_installed() -> None:
19-
assert DummyCheck.check_pydantinc_installed() is None
18+
def test_check_pydantic_installed() -> None:
19+
assert DummyCheck.check_pydantic_installed() is None
2020

2121
with (
2222
patch("fast_healthchecks.checks._base.PYDANTIC_INSTALLED", new=False),
2323
pytest.raises(RuntimeError, match="Pydantic is not installed"),
2424
):
25-
DummyCheck.check_pydantinc_installed()
25+
DummyCheck.check_pydantic_installed()
2626

2727

2828
@pytest.mark.parametrize(

uv.lock

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)