This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import pytest
|
||||
|
||||
from zhixing_server.bootstrap.config import sqlalchemy_database_url
|
||||
|
||||
|
||||
def test_sqlalchemy_url_adds_psycopg_driver_and_preserves_query() -> None:
|
||||
database_url = (
|
||||
"postgresql://zhixing-system@1Panel-postgresql-5Fc7:5432/zhixing-system"
|
||||
"?sslmode=require&connect_timeout=5"
|
||||
)
|
||||
|
||||
assert sqlalchemy_database_url(database_url) == (
|
||||
"postgresql+psycopg://zhixing-system@1Panel-postgresql-5Fc7:5432/zhixing-system"
|
||||
"?sslmode=require&connect_timeout=5"
|
||||
)
|
||||
|
||||
|
||||
def test_sqlalchemy_url_does_not_duplicate_psycopg_driver() -> None:
|
||||
database_url = "postgresql+psycopg://user@localhost:5432/db?sslmode=disable"
|
||||
|
||||
assert sqlalchemy_database_url(database_url) == database_url
|
||||
|
||||
|
||||
def test_sqlalchemy_url_rejects_non_postgresql_scheme() -> None:
|
||||
with pytest.raises(ValueError, match="postgresql"):
|
||||
sqlalchemy_database_url("mysql://user@localhost/db")
|
||||
Reference in New Issue
Block a user