Skip to content

Commit b0e3e8c

Browse files
committed
rename GroupTyoe
1 parent 5d8866f commit b0e3e8c

File tree

23 files changed

+68
-86
lines changed

23 files changed

+68
-86
lines changed

packages/common-library/src/common_library/groups_enums.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import enum
22

33

4-
class GroupTypeEnum(enum.Enum):
4+
class GroupType(enum.Enum):
55
"""
66
standard: standard group, e.g. any group that is not a primary group or special group such as the everyone group
77
primary: primary group, e.g. the primary group is the user own defined group that typically only contain the user (same as in linux)

packages/models-library/src/models_library/groups.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Annotated, Final, NamedTuple, TypeAlias
22

33
from common_library.basic_types import DEFAULT_FACTORY
4-
from common_library.groups_enums import GroupTypeEnum as GroupTypeEnum
4+
from common_library.groups_enums import GroupType as GroupType
55
from pydantic import BaseModel, ConfigDict, EmailStr, Field, field_validator
66
from pydantic.types import PositiveInt
77
from typing_extensions import TypedDict
@@ -14,14 +14,14 @@
1414

1515
GroupID: TypeAlias = PositiveInt
1616

17-
__all__: tuple[str, ...] = ("GroupTypeEnum",)
17+
__all__: tuple[str, ...] = ("GroupType",)
1818

1919

2020
class Group(BaseModel):
2121
gid: PositiveInt
2222
name: str
2323
description: str
24-
group_type: Annotated[GroupTypeEnum, Field(alias="type")]
24+
group_type: Annotated[GroupType, Field(alias="type")]
2525
thumbnail: str | None
2626

2727
inclusion_rules: Annotated[
@@ -32,7 +32,7 @@ class Group(BaseModel):
3232
] = DEFAULT_FACTORY
3333

3434
_from_equivalent_enums = field_validator("group_type", mode="before")(
35-
create_enums_pre_validator(GroupTypeEnum)
35+
create_enums_pre_validator(GroupType)
3636
)
3737

3838
model_config = ConfigDict(populate_by_name=True)

packages/postgres-database/src/simcore_postgres_database/models/groups.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
import sqlalchemy as sa
9-
from common_library.groups_enums import GroupTypeEnum
9+
from common_library.groups_enums import GroupType
1010
from sqlalchemy.dialects.postgresql import JSONB
1111
from sqlalchemy.sql import func
1212

@@ -27,7 +27,7 @@
2727
sa.Column("description", sa.String, nullable=False, doc="Short description"),
2828
sa.Column(
2929
"type",
30-
sa.Enum(GroupTypeEnum),
30+
sa.Enum(GroupType),
3131
nullable=False,
3232
server_default="STANDARD",
3333
doc="Classification of the group based on GroupType enum",

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from aiopg.sa.connection import SAConnection
88
from aiopg.sa.result import RowProxy
99

10-
from .models.groups import GroupTypeEnum, groups, user_to_groups
10+
from .models.groups import GroupType, groups, user_to_groups
1111
from .models.groups_extra_properties import groups_extra_properties
1212
from .utils_models import FromRowMixin
1313

@@ -44,9 +44,9 @@ async def _list_table_entries_ordered_by_group_type(
4444
groups.c.type,
4545
sa.case(
4646
# NOTE: the ordering is important for the aggregation afterwards
47-
(groups.c.type == GroupTypeEnum.EVERYONE, sa.literal(3)),
48-
(groups.c.type == GroupTypeEnum.STANDARD, sa.literal(2)),
49-
(groups.c.type == GroupTypeEnum.PRIMARY, sa.literal(1)),
47+
(groups.c.type == GroupType.EVERYONE, sa.literal(3)),
48+
(groups.c.type == GroupType.STANDARD, sa.literal(2)),
49+
(groups.c.type == GroupType.PRIMARY, sa.literal(1)),
5050
else_=sa.literal(4),
5151
).label("type_order"),
5252
)
@@ -124,10 +124,10 @@ async def get_aggregated_properties_for_user(
124124
for row in rows:
125125
group_extra_properties = GroupExtraProperties.from_row(row)
126126
match row.type:
127-
case GroupTypeEnum.PRIMARY:
127+
case GroupType.PRIMARY:
128128
# this always has highest priority
129129
return group_extra_properties
130-
case GroupTypeEnum.STANDARD:
130+
case GroupType.STANDARD:
131131
if merged_standard_extra_properties:
132132
merged_standard_extra_properties = (
133133
_merge_extra_properties_booleans(
@@ -137,7 +137,7 @@ async def get_aggregated_properties_for_user(
137137
)
138138
else:
139139
merged_standard_extra_properties = group_extra_properties
140-
case GroupTypeEnum.EVERYONE:
140+
case GroupType.EVERYONE:
141141
# if there are standard properties, they take precedence
142142
return (
143143
merged_standard_extra_properties

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import sqlalchemy as sa
88

99
from ._protocols import AiopgConnection, DBConnection
10-
from .models.groups import GroupTypeEnum, groups
10+
from .models.groups import GroupType, groups
1111
from .models.products import products
1212

1313
# NOTE: outside this module, use instead packages/models-library/src/models_library/users.py
@@ -57,7 +57,7 @@ async def execute_get_or_create_product_group(conn, product_name: str) -> int:
5757
.values(
5858
name=product_name,
5959
description=f"{product_name} product group",
60-
type=GroupTypeEnum.STANDARD,
60+
type=GroupType.STANDARD,
6161
)
6262
.returning(groups.c.gid)
6363
)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from .models.comp_pipeline import StateType, comp_pipeline
1010
from .models.comp_tasks import DB_CHANNEL_NAME, NodeClass, comp_tasks
1111
from .models.confirmations import ConfirmationAction, confirmations
12-
from .models.groups import GroupTypeEnum, groups, user_to_groups
12+
from .models.groups import GroupType, groups, user_to_groups
1313
from .models.products import products
1414
from .models.projects import ProjectType, projects
1515
from .models.projects_tags import projects_tags
@@ -28,7 +28,7 @@
2828
"DB_CHANNEL_NAME",
2929
"group_classifiers",
3030
"groups",
31-
"GroupTypeEnum",
31+
"GroupType",
3232
"NodeClass",
3333
"products",
3434
"projects",

packages/postgres-database/tests/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
ProjectNodesRepo,
3434
)
3535
from simcore_postgres_database.webserver_models import (
36-
GroupTypeEnum,
36+
GroupType,
3737
groups,
3838
user_to_groups,
3939
users,
@@ -237,7 +237,7 @@ def create_fake_group(
237237

238238
async def _creator(conn: SAConnection, **overrides) -> RowProxy:
239239
if "type" not in overrides:
240-
overrides["type"] = GroupTypeEnum.STANDARD
240+
overrides["type"] = GroupType.STANDARD
241241
result: ResultProxy = await conn.execute(
242242
groups.insert()
243243
.values(**random_group(**overrides))
@@ -281,7 +281,7 @@ async def _creator(conn, group: RowProxy | None = None, **overrides) -> RowProxy
281281
created_ids.append(user.id)
282282

283283
if group:
284-
assert group.type == GroupTypeEnum.STANDARD.name
284+
assert group.type == GroupType.STANDARD.name
285285
result = await conn.execute(
286286
user_to_groups.insert().values(uid=user.id, gid=group.gid)
287287
)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import pytest
1111
import sqlalchemy as sa
1212
from aiopg.sa.engine import Engine
13-
from simcore_postgres_database.models.groups import GroupTypeEnum, groups
13+
from simcore_postgres_database.models.groups import GroupType, groups
1414
from simcore_postgres_database.models.products import products
1515
from simcore_postgres_database.utils_products import (
1616
get_default_product_name,
@@ -61,7 +61,7 @@ async def test_get_or_create_group_product(
6161
product_group = await result.first()
6262

6363
# check product's group
64-
assert product_group.type == GroupTypeEnum.STANDARD
64+
assert product_group.type == GroupType.STANDARD
6565
assert product_group.name == product_row.name
6666
assert product_group.description == f"{product_row.name} product group"
6767

packages/postgres-database/tests/test_models_groups.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from pytest_simcore.helpers.faker_factories import random_user
1717
from simcore_postgres_database.models.base import metadata
1818
from simcore_postgres_database.webserver_models import (
19-
GroupTypeEnum,
19+
GroupType,
2020
groups,
2121
user_to_groups,
2222
users,
@@ -74,7 +74,7 @@ async def test_all_group(
7474
assert groups_count == 1
7575

7676
result = await connection.execute(
77-
groups.select().where(groups.c.type == GroupTypeEnum.EVERYONE)
77+
groups.select().where(groups.c.type == GroupType.EVERYONE)
7878
)
7979
all_group_gid = (await result.fetchone()).gid
8080
assert all_group_gid == 1 # it's the first group so it gets a 1
@@ -108,7 +108,7 @@ async def test_all_group(
108108
groups_count = await connection.scalar(select(func.count()).select_from(groups))
109109
assert groups_count == 1
110110
result = await connection.execute(
111-
groups.select().where(groups.c.type == GroupTypeEnum.EVERYONE)
111+
groups.select().where(groups.c.type == GroupType.EVERYONE)
112112
)
113113
all_group_gid = (await result.fetchone()).gid
114114
assert all_group_gid == 1 # it's the first group so it gets a 1
@@ -130,7 +130,7 @@ async def test_own_group(
130130

131131
# now check there is a primary group
132132
result = await connection.execute(
133-
groups.select().where(groups.c.type == GroupTypeEnum.PRIMARY)
133+
groups.select().where(groups.c.type == GroupType.PRIMARY)
134134
)
135135
primary_group: RowProxy = await result.fetchone()
136136
assert primary_group.gid == user.primary_gid

packages/postgres-database/tests/test_utils_groups_extra_properties.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@
1111
import sqlalchemy
1212
from aiopg.sa.result import RowProxy
1313
from faker import Faker
14-
from simcore_postgres_database.models.groups import (
15-
GroupTypeEnum,
16-
groups,
17-
user_to_groups,
18-
)
14+
from simcore_postgres_database.models.groups import GroupType, groups, user_to_groups
1915
from simcore_postgres_database.models.groups_extra_properties import (
2016
groups_extra_properties,
2117
)
@@ -108,7 +104,7 @@ async def test_get(
108104
@pytest.fixture
109105
async def everyone_group_id(connection: aiopg.sa.connection.SAConnection) -> int:
110106
result = await connection.scalar(
111-
sqlalchemy.select(groups.c.gid).where(groups.c.type == GroupTypeEnum.EVERYONE)
107+
sqlalchemy.select(groups.c.gid).where(groups.c.type == GroupType.EVERYONE)
112108
)
113109
assert result
114110
return result

0 commit comments

Comments
 (0)