Skip to content

Commit d283cc4

Browse files
committed
renames aiopg_engine
1 parent 1e7fc8a commit d283cc4

12 files changed

+65
-64
lines changed

packages/postgres-database/tests/conftest.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -166,26 +166,26 @@ def pg_sa_engine(
166166

167167

168168
@pytest.fixture
169-
async def pg_engine(
169+
async def aiopg_engine(
170170
pg_sa_engine: sa.engine.Engine, make_engine: Callable
171171
) -> AsyncIterator[Engine]:
172172
"""
173173
Return an aiopg.sa engine connected to a responsive and migrated pg database
174174
"""
175-
async_engine = await make_engine(is_async=True)
175+
aiopg_sa_engine = await make_engine(is_async=True)
176176

177-
yield async_engine
177+
yield aiopg_sa_engine
178178

179179
# closes async-engine connections and terminates
180-
async_engine.close()
181-
await async_engine.wait_closed()
182-
async_engine.terminate()
180+
aiopg_sa_engine.close()
181+
await aiopg_sa_engine.wait_closed()
182+
aiopg_sa_engine.terminate()
183183

184184

185185
@pytest.fixture
186-
async def connection(pg_engine: Engine) -> AsyncIterator[SAConnection]:
186+
async def connection(aiopg_engine: Engine) -> AsyncIterator[SAConnection]:
187187
"""Returns an aiopg.sa connection from an engine to a fully furnished and ready pg database"""
188-
async with pg_engine.acquire() as _conn:
188+
async with aiopg_engine.acquire() as _conn:
189189
yield _conn
190190

191191

@@ -264,7 +264,7 @@ async def _creator(conn, group: RowProxy | None = None, **overrides) -> RowProxy
264264

265265
@pytest.fixture
266266
async def create_fake_cluster(
267-
pg_engine: Engine, faker: Faker
267+
aiopg_engine: Engine, faker: Faker
268268
) -> AsyncIterator[Callable[..., Awaitable[int]]]:
269269
cluster_ids = []
270270
assert cluster_to_groups is not None
@@ -278,7 +278,7 @@ async def _creator(**overrides) -> int:
278278
"authentication": faker.pydict(value_types=[str]),
279279
}
280280
insert_values.update(overrides)
281-
async with pg_engine.acquire() as conn:
281+
async with aiopg_engine.acquire() as conn:
282282
cluster_id = await conn.scalar(
283283
clusters.insert().values(**insert_values).returning(clusters.c.id)
284284
)
@@ -289,13 +289,13 @@ async def _creator(**overrides) -> int:
289289
yield _creator
290290

291291
# cleanup
292-
async with pg_engine.acquire() as conn:
292+
async with aiopg_engine.acquire() as conn:
293293
await conn.execute(clusters.delete().where(clusters.c.id.in_(cluster_ids)))
294294

295295

296296
@pytest.fixture
297297
async def create_fake_project(
298-
pg_engine: Engine,
298+
aiopg_engine: Engine,
299299
) -> AsyncIterator[Callable[..., Awaitable[RowProxy]]]:
300300
created_project_uuids = []
301301

@@ -312,7 +312,7 @@ async def _creator(conn, user: RowProxy, **overrides) -> RowProxy:
312312

313313
yield _creator
314314

315-
async with pg_engine.acquire() as conn:
315+
async with aiopg_engine.acquire() as conn:
316316
await conn.execute(
317317
projects.delete().where(projects.c.uuid.in_(created_project_uuids))
318318
)

packages/postgres-database/tests/products/test_models_products.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@
2626

2727

2828
async def test_load_products(
29-
pg_engine: Engine, make_products_table: Callable, products_regex: dict
29+
aiopg_engine: Engine, make_products_table: Callable, products_regex: dict
3030
):
3131
exclude = {
3232
products.c.created,
3333
products.c.modified,
3434
}
3535

36-
async with pg_engine.acquire() as conn:
36+
async with aiopg_engine.acquire() as conn:
3737
await make_products_table(conn)
3838

3939
stmt = sa.select(*[c for c in products.columns if c not in exclude])
@@ -49,14 +49,14 @@ async def test_load_products(
4949

5050

5151
async def test_jinja2_templates_table(
52-
pg_engine: Engine, osparc_simcore_services_dir: Path
52+
aiopg_engine: Engine, osparc_simcore_services_dir: Path
5353
):
5454
templates_common_dir = (
5555
osparc_simcore_services_dir
5656
/ "web/server/src/simcore_service_webserver/templates/common"
5757
)
5858

59-
async with pg_engine.acquire() as conn:
59+
async with aiopg_engine.acquire() as conn:
6060
templates = []
6161
# templates table
6262
for p in templates_common_dir.glob("*.jinja2"):
@@ -135,7 +135,7 @@ async def test_jinja2_templates_table(
135135

136136

137137
async def test_insert_select_product(
138-
pg_engine: Engine,
138+
aiopg_engine: Engine,
139139
):
140140
osparc_product = {
141141
"name": "osparc",
@@ -174,7 +174,7 @@ async def test_insert_select_product(
174174

175175
print(json.dumps(osparc_product))
176176

177-
async with pg_engine.acquire() as conn:
177+
async with aiopg_engine.acquire() as conn:
178178
# writes
179179
stmt = (
180180
pg_insert(products)

packages/postgres-database/tests/products/test_utils_products.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,24 @@
1919
)
2020

2121

22-
async def test_default_product(pg_engine: Engine, make_products_table: Callable):
23-
async with pg_engine.acquire() as conn:
22+
async def test_default_product(aiopg_engine: Engine, make_products_table: Callable):
23+
async with aiopg_engine.acquire() as conn:
2424
await make_products_table(conn)
2525
default_product = await get_default_product_name(conn)
2626
assert default_product == "s4l"
2727

2828

2929
@pytest.mark.parametrize("pg_sa_engine", ["sqlModels"], indirect=True)
30-
async def test_default_product_undefined(pg_engine: Engine):
31-
async with pg_engine.acquire() as conn:
30+
async def test_default_product_undefined(aiopg_engine: Engine):
31+
async with aiopg_engine.acquire() as conn:
3232
with pytest.raises(ValueError):
3333
await get_default_product_name(conn)
3434

3535

3636
async def test_get_or_create_group_product(
37-
pg_engine: Engine, make_products_table: Callable
37+
aiopg_engine: Engine, make_products_table: Callable
3838
):
39-
async with pg_engine.acquire() as conn:
39+
async with aiopg_engine.acquire() as conn:
4040
await make_products_table(conn)
4141

4242
async for product_row in await conn.execute(
@@ -105,13 +105,13 @@ async def test_get_or_create_group_product(
105105
reason="Not relevant. Will review in https://github.com/ITISFoundation/osparc-simcore/issues/3754"
106106
)
107107
async def test_get_or_create_group_product_concurrent(
108-
pg_engine: Engine, make_products_table: Callable
108+
aiopg_engine: Engine, make_products_table: Callable
109109
):
110-
async with pg_engine.acquire() as conn:
110+
async with aiopg_engine.acquire() as conn:
111111
await make_products_table(conn)
112112

113113
async def _auto_create_products_groups():
114-
async with pg_engine.acquire() as conn:
114+
async with aiopg_engine.acquire() as conn:
115115
async for product_row in await conn.execute(
116116
sa.select(products.c.name, products.c.group_id).order_by(
117117
products.c.priority

packages/postgres-database/tests/projects/conftest.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616

1717

1818
@pytest.fixture
19-
async def user(pg_engine: Engine) -> RowProxy:
19+
async def user(aiopg_engine: Engine) -> RowProxy:
2020
_USERNAME = f"{__name__}.me"
2121
# some user
22-
async with pg_engine.acquire() as conn:
22+
async with aiopg_engine.acquire() as conn:
2323
result: ResultProxy | None = await conn.execute(
2424
users.insert().values(**random_user(name=_USERNAME)).returning(users)
2525
)
@@ -32,10 +32,10 @@ async def user(pg_engine: Engine) -> RowProxy:
3232

3333

3434
@pytest.fixture
35-
async def project(pg_engine: Engine, user: RowProxy) -> RowProxy:
35+
async def project(aiopg_engine: Engine, user: RowProxy) -> RowProxy:
3636
_PARENT_PROJECT_NAME = f"{__name__}.parent"
3737
# a user's project
38-
async with pg_engine.acquire() as conn:
38+
async with aiopg_engine.acquire() as conn:
3939
result: ResultProxy | None = await conn.execute(
4040
projects.insert()
4141
.values(**random_project(prj_owner=user.id, name=_PARENT_PROJECT_NAME))
@@ -50,6 +50,6 @@ async def project(pg_engine: Engine, user: RowProxy) -> RowProxy:
5050

5151

5252
@pytest.fixture
53-
async def conn(pg_engine: Engine) -> AsyncIterable[SAConnection]:
54-
async with pg_engine.acquire() as conn:
53+
async def conn(aiopg_engine: Engine) -> AsyncIterable[SAConnection]:
54+
async with aiopg_engine.acquire() as conn:
5555
yield conn

packages/postgres-database/tests/test_classifiers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ def classifiers_bundle(web_client_resource_folder: Path) -> dict:
3838

3939

4040
async def test_operations_on_group_classifiers(
41-
pg_engine: Engine, classifiers_bundle: dict
41+
aiopg_engine: Engine, classifiers_bundle: dict
4242
):
4343
# NOTE: mostly for TDD
44-
async with pg_engine.acquire() as conn:
44+
async with aiopg_engine.acquire() as conn:
4545
# creates a group
4646
stmt = (
4747
groups.insert()

packages/postgres-database/tests/test_clusters.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@
1616

1717

1818
@pytest.fixture
19-
async def user_id(pg_engine: Engine) -> AsyncIterable[int]:
20-
async with pg_engine.acquire() as conn:
19+
async def user_id(aiopg_engine: Engine) -> AsyncIterable[int]:
20+
async with aiopg_engine.acquire() as conn:
2121
# a 'me' user
2222
uid = await conn.scalar(
2323
users.insert().values(**(random_user())).returning(users.c.id)
2424
)
2525
assert uid is not None
2626
yield uid
2727
# cleanup
28-
async with pg_engine.acquire() as conn:
28+
async with aiopg_engine.acquire() as conn:
2929
# a 'me' user
3030
uid = await conn.execute(users.delete().where(users.c.id == uid))
3131

3232

3333
@pytest.fixture
34-
async def user_group_id(pg_engine: Engine, user_id: int) -> int:
35-
async with pg_engine.acquire() as conn:
34+
async def user_group_id(aiopg_engine: Engine, user_id: int) -> int:
35+
async with aiopg_engine.acquire() as conn:
3636
primary_gid = await conn.scalar(
3737
sa.select(users.c.primary_gid).where(users.c.id == user_id)
3838
)
@@ -64,34 +64,34 @@ async def test_can_create_cluster_with_owner(
6464

6565

6666
async def test_cannot_remove_owner_that_owns_cluster(
67-
pg_engine: Engine,
67+
aiopg_engine: Engine,
6868
user_id: int,
6969
user_group_id: int,
7070
create_fake_cluster: Callable[..., Awaitable[int]],
7171
):
7272
cluster_id = await create_fake_cluster(owner=user_group_id)
7373
# now try removing the user
74-
async with pg_engine.acquire() as conn:
74+
async with aiopg_engine.acquire() as conn:
7575
with pytest.raises(ForeignKeyViolation):
7676
await conn.execute(users.delete().where(users.c.id == user_id))
7777

7878
# now remove the cluster
79-
async with pg_engine.acquire() as conn:
79+
async with aiopg_engine.acquire() as conn:
8080
await conn.execute(clusters.delete().where(clusters.c.id == cluster_id))
8181

8282
# removing the user should work now
83-
async with pg_engine.acquire() as conn:
83+
async with aiopg_engine.acquire() as conn:
8484
await conn.execute(users.delete().where(users.c.id == user_id))
8585

8686

8787
async def test_cluster_owner_has_all_rights(
88-
pg_engine: Engine,
88+
aiopg_engine: Engine,
8989
user_group_id: int,
9090
create_fake_cluster: Callable[..., Awaitable[int]],
9191
):
9292
cluster_id = await create_fake_cluster(owner=user_group_id)
9393

94-
async with pg_engine.acquire() as conn:
94+
async with aiopg_engine.acquire() as conn:
9595
result: ResultProxy = await conn.execute(
9696
cluster_to_groups.select().where(
9797
cluster_to_groups.c.cluster_id == cluster_id

packages/postgres-database/tests/test_comp_tasks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020

2121
@pytest.fixture()
22-
async def db_connection(pg_engine: Engine) -> SAConnection:
23-
async with pg_engine.acquire() as conn:
22+
async def db_connection(aiopg_engine: Engine) -> SAConnection:
23+
async with aiopg_engine.acquire() as conn:
2424
yield conn
2525

2626

packages/postgres-database/tests/test_delete_projects_and_users.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616

1717
@pytest.fixture
18-
async def engine(pg_engine: Engine):
19-
async with pg_engine.acquire() as conn:
18+
async def engine(aiopg_engine: Engine):
19+
async with aiopg_engine.acquire() as conn:
2020
await conn.execute(users.insert().values(**random_user(name="A")))
2121
await conn.execute(users.insert().values(**random_user()))
2222
await conn.execute(users.insert().values(**random_user()))
@@ -27,7 +27,7 @@ async def engine(pg_engine: Engine):
2727
with pytest.raises(ForeignKeyViolation):
2828
await conn.execute(projects.insert().values(**random_project(prj_owner=4)))
2929

30-
return pg_engine
30+
return aiopg_engine
3131

3232

3333
@pytest.mark.skip(reason="sandbox for dev purposes")

packages/postgres-database/tests/test_services_consume_filetypes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ async def _make(connection: SAConnection):
5959

6060
@pytest.fixture
6161
async def connection(
62-
pg_engine: sa.engine.Engine, connection: SAConnection, make_table: Callable
62+
aiopg_engine: sa.engine.Engine, connection: SAConnection, make_table: Callable
6363
):
64-
assert pg_engine
64+
assert aiopg_engine
6565
# NOTE: do not remove th pg_engine, or the test will fail as pytest
6666
# cannot set the parameters in the fixture
6767

packages/postgres-database/tests/test_utils_aiopg_orm.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616

1717

1818
@pytest.fixture
19-
async def fake_scicrunch_ids(pg_engine: Engine) -> list[str]:
19+
async def fake_scicrunch_ids(aiopg_engine: Engine) -> list[str]:
2020
row1 = {"rrid": "RRID:foo", "name": "foo", "description": "fooing"}
2121
row2 = {"rrid": "RRID:bar", "name": "bar", "description": "barring"}
2222

2323
row_ids = []
24-
async with pg_engine.acquire() as conn:
24+
async with aiopg_engine.acquire() as conn:
2525
for row in (row1, row2):
2626
row_id = await conn.scalar(
2727
scicrunch_resources.insert()
@@ -35,7 +35,7 @@ async def fake_scicrunch_ids(pg_engine: Engine) -> list[str]:
3535

3636

3737
@pytest.fixture()
38-
async def scicrunch_orm(pg_engine: Engine) -> Iterator[BaseOrm[str]]:
38+
async def scicrunch_orm(aiopg_engine: Engine) -> Iterator[BaseOrm[str]]:
3939
# This is a table without dependencies and therefore easy to use as fixture
4040
class ScicrunchOrm(BaseOrm[str]):
4141
def __init__(self, connection: SAConnection):
@@ -46,7 +46,7 @@ def __init__(self, connection: SAConnection):
4646
writeonce={"rrid"},
4747
)
4848

49-
async with pg_engine.acquire() as conn:
49+
async with aiopg_engine.acquire() as conn:
5050
orm_obj = ScicrunchOrm(conn)
5151
yield orm_obj
5252

0 commit comments

Comments
 (0)