Skip to content

Commit

Permalink
use quote_plus instead of quote (#122)
Browse files Browse the repository at this point in the history
* use quote_plus instead of quote

`asyncpg` doesn't work well for all US-ASCII characters, we need to use `quote_plus` instead

MagicStack/asyncpg#1159

* make it fail

* fix test

* one more quote

---------

Co-authored-by: ranchodeluxe <[email protected]>
Co-authored-by: vincentsarago <[email protected]>
  • Loading branch information
3 people committed Jun 27, 2024
1 parent 60b046f commit 8b61a87
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion stac_fastapi/pgstac/config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Postgres API configuration."""

from typing import List, Type
from urllib.parse import quote
from urllib.parse import quote_plus as quote

from pydantic import BaseModel
from pydantic_settings import SettingsConfigDict
Expand Down
2 changes: 1 addition & 1 deletion tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ async def test_no_extension(
hydrate, validation, load_test_data, database, pgstac
) -> None:
"""test PgSTAC with no extension."""
connection = f"postgresql://{database.user}:{database.password}@{database.host}:{database.port}/{database.dbname}"
connection = f"postgresql://{database.user}:{quote_plus(database.password)}@{database.host}:{database.port}/{database.dbname}"
with PgstacDB(dsn=connection) as db:
loader = Loader(db=db)
loader.load_collections(os.path.join(DATA_DIR, "test_collection.json"))
Expand Down
10 changes: 4 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import time
from typing import Callable, Dict
from urllib.parse import quote_plus as quote
from urllib.parse import urljoin

import asyncpg
Expand Down Expand Up @@ -53,11 +54,9 @@ def database(postgresql_proc):
port=postgresql_proc.port,
dbname="pgstactestdb",
version=postgresql_proc.version,
password="secret",
password="a2Vw:yk=)CdSis[fek]tW=/o",
) as jan:
connection = (
f"postgresql://{jan.user}:{jan.password}@{jan.host}:{jan.port}/{jan.dbname}"
)
connection = f"postgresql://{jan.user}:{quote(jan.password)}@{jan.host}:{jan.port}/{jan.dbname}"
with PgstacDB(dsn=connection) as db:
migrator = Migrate(db)
version = migrator.run_migration()
Expand All @@ -68,7 +67,7 @@ def database(postgresql_proc):

@pytest.fixture(autouse=True)
async def pgstac(database):
connection = f"postgresql://{database.user}:{database.password}@{database.host}:{database.port}/{database.dbname}"
connection = f"postgresql://{database.user}:{quote(database.password)}@{database.host}:{database.port}/{database.dbname}"
yield
conn = await asyncpg.connect(dsn=connection)
await conn.execute(
Expand Down Expand Up @@ -99,7 +98,6 @@ async def pgstac(database):
)
def api_client(request, database):
hydrate, prefix, response_model = request.param

api_settings = Settings(
postgres_user=database.user,
postgres_pass=database.password,
Expand Down

0 comments on commit 8b61a87

Please sign in to comment.