diff --git a/databasez/core.py b/databasez/core.py index 89f76c4..a7f6519 100644 --- a/databasez/core.py +++ b/databasez/core.py @@ -569,7 +569,8 @@ def __init__(self, url: typing.Union[str, "DatabaseURL"]): f"Invalid type for DatabaseURL. Expected str or DatabaseURL, got {type(url)}" ) - def _sanitize_password(self, url: URL) -> URL: + @classmethod + def _sanitize_password(cls, url: URL) -> URL: """ Making sure all the passwords are allowed. """ @@ -585,7 +586,7 @@ def _sanitize_password(self, url: URL) -> URL: def components(self) -> SplitResult: if not hasattr(self, "_components"): raw_url = make_url(self._url) - url = self._sanitize_password(raw_url) + url = DatabaseURL._sanitize_password(raw_url) self._components = urlsplit(url.render_as_string(hide_password=False)) return self._components diff --git a/docker-compose.yml b/docker-compose.yml index 347d10a..b4edef2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,7 +6,7 @@ services: environment: POSTGRES_HOST_AUTH_METHOD: trust POSTGRES_USER: "postgres" - POSTGRES_PASSWORD: "password*1123456879#" + POSTGRES_PASSWORD: "passwsss*1348394#" POSTGRES_DB: "testsuite" expose: - "5432" @@ -19,8 +19,8 @@ services: environment: MYSQL_USER: "mysql" MYSQL_PASSWORD: "mysql" - MYSQL_DATABASE: "testsuite" - MYSQL_ROOT_PASSWORD: "password*1123456879#" + MYSQL_DATABASE: "passwsss*1348394#" + MYSQL_ROOT_PASSWORD: "password" expose: - "3306" ports: diff --git a/tests/test_databases.py b/tests/test_databases.py index 23c6b61..128175d 100644 --- a/tests/test_databases.py +++ b/tests/test_databases.py @@ -10,6 +10,7 @@ import pytest import sqlalchemy +from sqlalchemy.engine import URL, make_url from databasez import Database, DatabaseURL @@ -17,9 +18,12 @@ DATABASE_URLS = [url.strip() for url in os.environ["TEST_DATABASE_URLS"].split(",")] + DATABASE_CONFIG_URLS = [] for value in DATABASE_URLS: - spliter = urlsplit(value) + raw_url = make_url(value) + url: URL = DatabaseURL._sanitize_password(raw_url) + spliter = urlsplit(url.render_as_string(hide_password=False)) DATABASE_CONFIG_URLS.append( { "connection": { @@ -39,7 +43,7 @@ class AsyncMock(MagicMock): async def __call__(self, *args, **kwargs): - return super(AsyncMock, self).__call__(*args, **kwargs) + return super().__call__(*args, **kwargs) class MyEpochType(sqlalchemy.types.TypeDecorator):