Skip to content

Commit

Permalink
fixing test
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov committed Dec 13, 2024
1 parent a0b47ec commit 1503da4
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
delete_user_without_projects,
get_guest_user_ids_and_names,
get_user,
get_user_primary_group_id,
get_user_role,
)
from ..users.exceptions import UserNotFoundError
Expand All @@ -45,6 +46,9 @@ async def _delete_all_projects_for_user(app: web.Application, user_id: int) -> N
"""
# recover user's primary_gid
try:
project_owner_primary_gid = await get_user_primary_group_id(
app=app, user_id=user_id
)
project_owner: dict = await get_user(app=app, user_id=user_id)
except exceptions.UserNotFoundError:
_logger.warning(
Expand Down Expand Up @@ -170,6 +174,7 @@ async def remove_guest_user_with_all_its_resources(
ProjectNotFoundError,
UserNotFoundError,
ProjectDeleteError,
Exception,
) as error:
_logger.warning(
"Failed to delete guest user %s and its resources: %s",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def setup_garbage_collector(app: web.Application) -> None:
# - project needs access to socketio via notify_project_state_update
setup_socketio(app)
# - project needs access to user-api that is connected to login plugin
# TODO: dont need this anymore!?
setup_login_storage(app)

settings = get_plugin_settings(app)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@ async def get_user_or_raise(
return user


async def get_user_primary_group_id(
engine: AsyncEngine, connection: AsyncConnection | None = None, *, user_id: UserID
) -> GroupID:
async with pass_or_acquire_connection(engine, connection) as conn:
primary_gid: GroupID | None = await conn.scalar(
sa.select(
users.c.primary_gid,
).where(users.c.id == user_id)
)
if primary_gid is None:
raise UserNotFoundError(uid=user_id)
return primary_gid


async def get_users_ids_in_group(
engine: AsyncEngine,
connection: AsyncConnection | None = None,
Expand Down Expand Up @@ -147,7 +161,8 @@ async def get_user_role(app: web.Application, *, user_id: UserID) -> UserRole:
)
if user_role is None:
raise UserNotFoundError(uid=user_id)
return UserRole(user_role)
assert isinstance(user_role, UserRole) # nosec
return user_role


async def list_user_permissions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ async def get_user(app: web.Application, user_id: UserID) -> dict[str, Any]:
)


async def get_user_primary_group_id(app: web.Application, user_id: UserID) -> GroupID:
return await _users_repository.get_user_primary_group_id(
engine=get_asyncpg_engine(app), user_id=user_id
)


async def get_user_id_from_gid(app: web.Application, primary_gid: GroupID) -> UserID:
return await _users_repository.get_user_id_from_pgid(app, primary_gid)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
get_user_id_from_gid,
get_user_invoice_address,
get_user_name_and_email,
get_user_primary_group_id,
get_user_role,
get_users_in_group,
set_user_as_deleted,
Expand All @@ -20,14 +21,15 @@
__all__: tuple[str, ...] = (
"delete_user_without_projects",
"get_guest_user_ids_and_names",
"get_user",
"get_user_credentials",
"get_user_display_and_id_names",
"get_user_fullname",
"get_user_id_from_gid",
"get_user_invoice_address",
"get_user_name_and_email",
"get_user_primary_group_id",
"get_user_role",
"get_user",
"get_users_in_group",
"set_user_as_deleted",
"update_expired_users",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from simcore_service_webserver.db.plugin import setup_db
from simcore_service_webserver.director_v2.plugin import setup_director_v2
from simcore_service_webserver.garbage_collector import _core as gc_core
from simcore_service_webserver.garbage_collector._tasks_core import _GC_TASK_NAME
from simcore_service_webserver.garbage_collector.plugin import setup_garbage_collector
from simcore_service_webserver.groups._groups_api import create_standard_group
from simcore_service_webserver.groups.api import add_user_in_group
Expand Down Expand Up @@ -1019,6 +1020,12 @@ async def test_t10_owner_and_all_shared_users_marked_as_guests(
USER "u1", "u2" and "u3" are manually marked as "GUEST";
EXPECTED: the project and all the users are removed
"""

gc_task: asyncio.Task = next(
task for task in asyncio.all_tasks() if task.get_name() == _GC_TASK_NAME
)
assert not gc_task.done()

u1 = await login_user(client)
u2 = await login_user(client)
u3 = await login_user(client)
Expand Down

0 comments on commit 1503da4

Please sign in to comment.