77
88
99import functools
10+ from collections .abc import Iterator
1011from copy import deepcopy
1112from http import HTTPStatus
1213from typing import Any
1314from unittest .mock import patch
1415
1516import pytest
17+ import sqlalchemy as sa
1618from aiohttp .test_utils import TestClient
1719from aiopg .sa .connection import SAConnection
1820from common_library .users_enums import UserRole
2224from psycopg2 import OperationalError
2325from pytest_simcore .helpers .assert_checks import assert_status
2426from pytest_simcore .helpers .monkeypatch_envs import EnvVarsDict , setenvs_from_dict
27+ from pytest_simcore .helpers .postgres_tools import sync_insert_and_get_row_lifespan
2528from pytest_simcore .helpers .webserver_users import UserInfoDict
2629from servicelib .aiohttp import status
2730from servicelib .rest_constants import RESPONSE_MODEL_POLICY
@@ -47,6 +50,41 @@ def app_environment(
4750 )
4851
4952
53+ @pytest .fixture (scope = "module" )
54+ def support_group (
55+ postgres_db : sa .engine .Engine ,
56+ product_name : str ,
57+ ) -> Iterator [dict [str , Any ]]:
58+ """Creates a standard support group and assigns it to the current product"""
59+ from simcore_postgres_database .models .groups import groups
60+ from simcore_postgres_database .models .products import products
61+
62+ # Create support group using direct database insertion
63+ group_values = {
64+ "name" : "Support Group" ,
65+ "description" : "Support group for product" ,
66+ "type" : "STANDARD" ,
67+ }
68+
69+ with sync_insert_and_get_row_lifespan (
70+ postgres_db ,
71+ table = groups ,
72+ values = group_values ,
73+ pk_col = groups .c .gid ,
74+ ) as group_row :
75+ group_id = group_row ["gid" ]
76+
77+ # Update product to set support_standard_group_id
78+ with postgres_db .begin () as conn :
79+ conn .execute (
80+ sa .update (products )
81+ .where (products .c .name == product_name )
82+ .values (support_standard_group_id = group_id )
83+ )
84+
85+ yield group_row
86+
87+
5088@pytest .mark .parametrize (
5189 "user_role,expected" ,
5290 [
@@ -100,6 +138,7 @@ async def test_get_profile(
100138 primary_group : dict [str , Any ],
101139 standard_groups : list [dict [str , Any ]],
102140 all_group : dict [str , str ],
141+ support_group : dict [str , Any ],
103142):
104143 assert client .app
105144
@@ -130,13 +169,25 @@ async def test_get_profile(
130169 "thumbnail" : None ,
131170 }
132171
133- assert got_profile_groups ["support" ] is None
172+ # support group exists
173+ assert got_profile_groups ["support" ]
174+ support_group_id = got_profile_groups ["support" ]["gid" ]
134175
176+ assert support_group_id == support_group ["gid" ]
177+ assert got_profile_groups ["support" ]["description" ] == support_group ["description" ]
178+ assert "accessRights" not in got_profile_groups ["support" ]
179+
180+ # standard groups with at least read access
135181 sorted_by_group_id = functools .partial (sorted , key = lambda d : d ["gid" ])
136182 assert sorted_by_group_id (
137183 got_profile_groups ["organizations" ]
138184 ) == sorted_by_group_id (standard_groups )
139185
186+ # user is NOT part of the support group
187+ all_standard_groups_ids = {g ["gid" ] for g in standard_groups }
188+ assert support_group_id not in all_standard_groups_ids
189+
190+ # preferences
140191 assert profile .preferences == await get_frontend_user_preferences_aggregation (
141192 client .app , user_id = logged_user ["id" ], product_name = "osparc"
142193 )
0 commit comments