Skip to content

Commit 299e946

Browse files
committed
refactor: improve code readability by restructuring class inheritance and renaming variables
1 parent f7678e1 commit 299e946

File tree

4 files changed

+30
-15
lines changed

4 files changed

+30
-15
lines changed

packages/models-library/src/models_library/api_schemas_webserver/users.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,16 +241,14 @@ def from_domain_model(cls, data):
241241

242242

243243
class UsersForAdminListFilter(Filters):
244-
# TODO: create a filter for two views that OM needs
245-
#
246244
# 1. States of an Account Resquest: PENDING, REJECTED, APPROVED
247245
# 2. If APPROVED AND user uses the invitation link, then it can be in any of these states:
248246
# CONFIRMATION_PENDING, ACTIVE, EXPIRED, BANNED, DELETED
249247
#
250248
status: Literal["PENDING"] | None = None
251249

252250

253-
class UsersForAdminListQueryParams(PageQueryParameters, UsersForAdminListFilter): ...
251+
class UsersForAdminListQueryParams(UsersForAdminListFilter, PageQueryParameters): ...
254252

255253

256254
class UserApprove(InputSchema):

packages/postgres-database/src/simcore_postgres_database/utils_users.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,14 @@ async def link_and_update_user_from_pre_registration(
138138
users_pre_registration_details.c.pre_email == new_user_email
139139
)
140140
)
141-
if details := result.first():
141+
if pre_registration_details_data := result.first():
142+
# NOTE: could have many products! which to use?
142143
await conn.execute(
143144
users.update()
144145
.where(users.c.id == new_user_id)
145146
.values(
146-
first_name=details.pre_first_name, # type: ignore[union-attr]
147-
last_name=details.pre_last_name, # type: ignore[union-attr]
147+
first_name=pre_registration_details_data.pre_first_name, # type: ignore[union-attr]
148+
last_name=pre_registration_details_data.pre_last_name, # type: ignore[union-attr]
148149
)
149150
)
150151

packages/postgres-database/tests/test_users_details.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@
1010
import pytest
1111
import sqlalchemy as sa
1212
from aiopg.sa.result import RowProxy
13+
from common_library.groups_enums import GroupType
1314
from faker import Faker
1415
from pytest_simcore.helpers.faker_factories import (
16+
random_group,
1517
random_pre_registration_details,
1618
random_product,
1719
random_user,
1820
)
1921
from pytest_simcore.helpers.postgres_tools import (
2022
insert_and_get_row_lifespan,
2123
)
24+
from simcore_postgres_database.models.groups import groups
2225
from simcore_postgres_database.models.products import products
2326
from simcore_postgres_database.models.users import UserRole, UserStatus, users
2427
from simcore_postgres_database.models.users_details import (
@@ -33,17 +36,25 @@
3336

3437

3538
@pytest.fixture
36-
async def product_name(
39+
async def product(
3740
faker: Faker,
3841
asyncpg_engine: AsyncEngine,
39-
) -> AsyncIterable[str]:
40-
async with insert_and_get_row_lifespan( # pylint:disable=contextmanager-generator-missing-cleanup
42+
) -> AsyncIterable[dict[str, Any]]:
43+
async with insert_and_get_row_lifespan( # pylint:disable=contextmanager-generator-missing-cleanup # noqa: SIM117
4144
asyncpg_engine,
42-
table=products,
43-
values=random_product(fake=faker, name="s4l"),
45+
table=groups,
46+
values=random_group(faker=faker, type=GroupType.STANDARD.name),
4447
pk_col=products.c.name,
45-
) as row:
46-
yield row["name"]
48+
) as product_group:
49+
async with insert_and_get_row_lifespan( # pylint:disable=contextmanager-generator-missing-cleanup
50+
asyncpg_engine,
51+
table=products,
52+
values=random_product(
53+
fake=faker, name="s4l", group_id=product_group["gid"]
54+
),
55+
pk_col=products.c.name,
56+
) as row:
57+
yield row
4758

4859

4960
@pytest.fixture
@@ -67,8 +78,10 @@ async def test_user_creation_workflow(
6778
asyncpg_engine: AsyncEngine,
6879
faker: Faker,
6980
po_user: dict[str, Any],
70-
product_name: str,
81+
product: dict[str, Any],
7182
):
83+
product_name = product["name"]
84+
7285
# a PO creates an invitation
7386
fake_pre_registration_data = random_pre_registration_details(
7487
faker, created_by=po_user["id"], product_name=product_name

services/web/server/src/simcore_service_webserver/login/_controller/rest/preregistration.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ def _get_ipinfo(request: web.Request) -> dict[str, Any]:
5757
}
5858

5959

60-
@routes.post(f"/{API_VTAG}/auth/request-account", name="request_product_account")
60+
@routes.post(
61+
f"/{API_VTAG}/auth/request-account",
62+
name="request_product_account",
63+
)
6164
@global_rate_limit_route(number_of_requests=30, interval_seconds=MINUTE)
6265
async def request_product_account(request: web.Request):
6366
product = products_web.get_current_product(request)

0 commit comments

Comments
 (0)