-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #273 from lsst-sqre/tickets/DM-45281
DM-45281: Allow create_database_engine to take a Url
- Loading branch information
Showing
4 changed files
with
18 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
### New features | ||
|
||
- `safir.database.create_database_engine` now accepts the database URL as a Pydantic `Url` as well as a `str`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
import pytest | ||
import structlog | ||
from pydantic import BaseModel, SecretStr | ||
from pydantic_core import Url | ||
from sqlalchemy import Column, MetaData, String, Table | ||
from sqlalchemy.exc import OperationalError, ProgrammingError | ||
from sqlalchemy.future import select | ||
|
@@ -83,6 +84,12 @@ def test_build_database_url(database_url: str) -> None: | |
) | ||
assert url == "postgresql+asyncpg://foo:[email protected]:5433/foo" | ||
|
||
pydantic_url = Url.build( | ||
scheme="postgresql", username="user", host="localhost", path="foo" | ||
) | ||
url = _build_database_url(pydantic_url, "password") | ||
assert url == "postgresql+asyncpg://user:password@localhost/foo" | ||
|
||
# Test that the username and password are quoted properly. | ||
url = _build_database_url( | ||
"postgresql://foo%[email protected]:4444/foo", | ||
|