Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
4adab17
uninstall aiopg
sanderegg Mar 21, 2025
667df10
removed aiopg telemetry
sanderegg Mar 21, 2025
ee92d98
migrated to asyncpg
sanderegg Mar 21, 2025
c4754e5
simcore-sdk migrated
sanderegg Mar 21, 2025
f080b56
simcore-sdk migrated
sanderegg Mar 21, 2025
4e65d9f
simcore-sdk migrated
sanderegg Mar 21, 2025
9620a8a
simcore-sdk migrated
sanderegg Mar 21, 2025
b587fb3
have both asyncpg and aiopg
sanderegg Mar 27, 2025
36a8f1b
removing aiopg
sanderegg Mar 27, 2025
8aca487
fixed tests
sanderegg Apr 3, 2025
24f4c44
typo
sanderegg Apr 3, 2025
99a743e
refactor: update database connection and improve assertions in unit t…
sanderegg Apr 3, 2025
a3a8d60
connect with asyncpg
sanderegg Apr 3, 2025
ff95278
fix fixture and test
sanderegg Apr 4, 2025
20f783a
use asyncpg
sanderegg Apr 4, 2025
a199d93
models-library is not included
sanderegg Apr 4, 2025
f28741d
fix
sanderegg Apr 4, 2025
542c2c5
refactor: update database dependency to use asyncpg engine
sanderegg Apr 4, 2025
db78520
fix: ensure asyncpg_engine is asserted during app startup and use the…
sanderegg Apr 4, 2025
5d5a99c
fix some tests
sanderegg Apr 4, 2025
f35c542
expanded time for postgres-db
sanderegg Apr 8, 2025
7e6c72c
renamed
sanderegg Apr 9, 2025
a5135d5
revert
sanderegg Apr 9, 2025
b3bb9b5
fixed usage
sanderegg Apr 9, 2025
9efc74a
aiopg is gone
sanderegg Apr 10, 2025
01588eb
fixed test. removed aiopg
sanderegg Apr 22, 2025
907afcb
fixed test
sanderegg Apr 22, 2025
917118d
ensure this runs
sanderegg Apr 22, 2025
9bb973d
ensure we have postgres services
sanderegg Apr 22, 2025
18683e1
cleanup
sanderegg Apr 22, 2025
e09da78
fixed setup of db
sanderegg Apr 22, 2025
083ea28
cleanup
sanderegg Apr 22, 2025
59a50f7
fixed test
sanderegg Apr 22, 2025
9a9083a
add dependencies
sanderegg Apr 22, 2025
90f398d
fix init of asyncpg
sanderegg Apr 22, 2025
5157e6d
fixed tests dependencies
sanderegg Apr 23, 2025
41dd5a3
fixed test
sanderegg Apr 23, 2025
411c808
fixed test
sanderegg Apr 23, 2025
08b4e3f
fixed connection to db
sanderegg Apr 23, 2025
44d0df0
renamed again
sanderegg Apr 23, 2025
674b27c
moved to utils
sanderegg Apr 23, 2025
1a84c33
removed confusion
sanderegg Apr 23, 2025
3bdb2ae
fixed test
sanderegg Apr 23, 2025
b6cda45
reverted
sanderegg Apr 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
from typing import Any

import sqlalchemy as sa
from aiopg.sa.connection import SAConnection
from sqlalchemy.dialects.postgresql import insert as pg_insert
from sqlalchemy.ext.asyncio import AsyncConnection

from .models.user_preferences import (
user_preferences_frontend,
user_preferences_user_service,
)


class CouldNotCreateOrUpdateUserPreferenceError(Exception):
...
class CouldNotCreateOrUpdateUserPreferenceError(Exception): ...


class BasePreferencesRepo:
Expand All @@ -20,7 +19,7 @@ class BasePreferencesRepo:
@classmethod
async def save(
cls,
conn: SAConnection,
conn: AsyncConnection,
*,
user_id: int,
product_name: str,
Expand Down Expand Up @@ -49,7 +48,7 @@ async def save(
@classmethod
async def load(
cls,
conn: SAConnection,
conn: AsyncConnection,
*,
user_id: int,
product_name: str,
Expand Down
35 changes: 22 additions & 13 deletions packages/postgres-database/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
user_to_groups,
users,
)
from sqlalchemy.engine.row import Row
from sqlalchemy.ext.asyncio import AsyncEngine, create_async_engine

pytest_plugins = [
Expand Down Expand Up @@ -324,18 +325,26 @@ async def _creator(project_uuid: uuid.UUID) -> ProjectNode:


@pytest.fixture
def create_fake_product(
connection: aiopg.sa.connection.SAConnection,
) -> Callable[..., Awaitable[RowProxy]]:
async def _creator(product_name: str) -> RowProxy:
result = await connection.execute(
sa.insert(products)
.values(name=product_name, host_regex=".*")
.returning(sa.literal_column("*"))
)
assert result
row = await result.first()
assert row
async def create_fake_product(
asyncpg_engine: AsyncEngine,
) -> AsyncIterator[Callable[[str], Awaitable[Row]]]:
created_product_names = set()

async def _creator(product_name: str) -> Row:
async with asyncpg_engine.begin() as connection:
result = await connection.execute(
sa.insert(products)
.values(name=product_name, host_regex=".*")
.returning(sa.literal_column("*"))
)
assert result
row = result.one()
created_product_names.add(row.name)
return row

return _creator
yield _creator

async with asyncpg_engine.begin() as conn:
await conn.execute(
products.delete().where(products.c.name.in_(created_product_names))
)
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
GroupExtraPropertiesRepo,
)
from sqlalchemy import literal_column
from sqlalchemy.engine.row import Row
from sqlalchemy.ext.asyncio import AsyncEngine


Expand Down Expand Up @@ -84,7 +85,7 @@ async def test_get(
connection: aiopg.sa.connection.SAConnection,
registered_user: RowProxy,
product_name: str,
create_fake_product: Callable[..., Awaitable[RowProxy]],
create_fake_product: Callable[[str], Awaitable[Row]],
create_fake_group_extra_properties: Callable[..., Awaitable[GroupExtraProperties]],
):
with pytest.raises(GroupExtraPropertiesNotFoundError):
Expand All @@ -106,7 +107,7 @@ async def test_get_v2(
asyncpg_engine: AsyncEngine,
registered_user: RowProxy,
product_name: str,
create_fake_product: Callable[..., Awaitable[RowProxy]],
create_fake_product: Callable[[str], Awaitable[Row]],
create_fake_group_extra_properties: Callable[..., Awaitable[GroupExtraProperties]],
):
with pytest.raises(GroupExtraPropertiesNotFoundError):
Expand Down Expand Up @@ -157,7 +158,7 @@ async def test_get_aggregated_properties_for_user_returns_properties_in_expected
connection: aiopg.sa.connection.SAConnection,
product_name: str,
registered_user: RowProxy,
create_fake_product: Callable[..., Awaitable[RowProxy]],
create_fake_product: Callable[[str], Awaitable[Row]],
create_fake_group: Callable[..., Awaitable[RowProxy]],
create_fake_group_extra_properties: Callable[..., Awaitable[GroupExtraProperties]],
everyone_group_id: int,
Expand Down Expand Up @@ -227,7 +228,7 @@ async def test_get_aggregated_properties_for_user_returns_properties_in_expected
connection: aiopg.sa.connection.SAConnection,
product_name: str,
registered_user: RowProxy,
create_fake_product: Callable[..., Awaitable[RowProxy]],
create_fake_product: Callable[[str], Awaitable[Row]],
create_fake_group: Callable[..., Awaitable[RowProxy]],
create_fake_group_extra_properties: Callable[..., Awaitable[GroupExtraProperties]],
everyone_group_id: int,
Expand Down Expand Up @@ -274,7 +275,7 @@ async def test_get_aggregated_properties_for_user_returns_property_values_as_tru
connection: aiopg.sa.connection.SAConnection,
product_name: str,
registered_user: RowProxy,
create_fake_product: Callable[..., Awaitable[RowProxy]],
create_fake_product: Callable[[str], Awaitable[Row]],
create_fake_group: Callable[..., Awaitable[RowProxy]],
create_fake_group_extra_properties: Callable[..., Awaitable[GroupExtraProperties]],
everyone_group_id: int,
Expand Down Expand Up @@ -385,7 +386,7 @@ async def test_get_aggregated_properties_for_user_returns_property_values_as_tru
connection: aiopg.sa.connection.SAConnection,
product_name: str,
registered_user: RowProxy,
create_fake_product: Callable[..., Awaitable[RowProxy]],
create_fake_product: Callable[[str], Awaitable[Row]],
create_fake_group: Callable[..., Awaitable[RowProxy]],
create_fake_group_extra_properties: Callable[..., Awaitable[GroupExtraProperties]],
everyone_group_id: int,
Expand Down
Loading
Loading