mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-24 17:28:08 +00:00
Upgrade dependencies and fix user group tests
This commit is contained in:
parent
66047b3431
commit
8aa9d1aae6
@ -196,6 +196,11 @@ async def add_member_to_group(
|
|||||||
if not user:
|
if not user:
|
||||||
raise ControllerNotFoundError(f"User '{user_id}' not found")
|
raise ControllerNotFoundError(f"User '{user_id}' not found")
|
||||||
|
|
||||||
|
user_groups = await users_repo.get_user_memberships(user_id)
|
||||||
|
for group in user_groups:
|
||||||
|
if group.user_group_id == user_group_id:
|
||||||
|
raise ControllerBadRequestError(f"Username '{user.username}' is already member of group '{group.name}'")
|
||||||
|
|
||||||
user_group = await users_repo.add_member_to_user_group(user_group_id, user)
|
user_group = await users_repo.add_member_to_user_group(user_group_id, user)
|
||||||
if not user_group:
|
if not user_group:
|
||||||
raise ControllerNotFoundError(f"User group '{user_group_id}' not found")
|
raise ControllerNotFoundError(f"User group '{user_group_id}' not found")
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
uvicorn==0.22.0 # v0.22.0 is the last to support Python 3.7
|
uvicorn==0.22.0 # v0.22.0 is the last to support Python 3.7
|
||||||
fastapi==0.103.0
|
fastapi==0.103.1
|
||||||
python-multipart==0.0.6
|
python-multipart==0.0.6
|
||||||
websockets==11.0.3
|
websockets==11.0.3
|
||||||
aiohttp>=3.8.5,<3.9
|
aiohttp>=3.8.5,<3.9
|
||||||
@ -10,7 +10,7 @@ sentry-sdk==1.30.0,<1.31
|
|||||||
psutil==5.9.5
|
psutil==5.9.5
|
||||||
distro>=1.8.0
|
distro>=1.8.0
|
||||||
py-cpuinfo==9.0.0
|
py-cpuinfo==9.0.0
|
||||||
sqlalchemy==2.0.18
|
sqlalchemy==2.0.20
|
||||||
aiosqlite==0.19.0
|
aiosqlite==0.19.0
|
||||||
alembic==1.12.0
|
alembic==1.12.0
|
||||||
passlib[bcrypt]==1.7.4
|
passlib[bcrypt]==1.7.4
|
||||||
|
@ -22,7 +22,7 @@ from httpx import AsyncClient
|
|||||||
|
|
||||||
from sqlalchemy.ext.asyncio import AsyncSession
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
from gns3server.db.repositories.users import UsersRepository
|
from gns3server.db.repositories.users import UsersRepository
|
||||||
from gns3server.schemas.controller.users import User
|
from gns3server.schemas.controller.users import User, UserGroupCreate
|
||||||
|
|
||||||
pytestmark = pytest.mark.asyncio
|
pytestmark = pytest.mark.asyncio
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ class TestGroupRoutes:
|
|||||||
|
|
||||||
class TestGroupMembersRoutes:
|
class TestGroupMembersRoutes:
|
||||||
|
|
||||||
async def test_add_member_to_group(
|
async def test_add_to_group_already_member(
|
||||||
self,
|
self,
|
||||||
app: FastAPI,
|
app: FastAPI,
|
||||||
client: AsyncClient,
|
client: AsyncClient,
|
||||||
@ -123,6 +123,28 @@ class TestGroupMembersRoutes:
|
|||||||
user_id=str(test_user.user_id)
|
user_id=str(test_user.user_id)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
assert response.status_code == status.HTTP_400_BAD_REQUEST
|
||||||
|
|
||||||
|
async def test_add_member_to_group(
|
||||||
|
self,
|
||||||
|
app: FastAPI,
|
||||||
|
client: AsyncClient,
|
||||||
|
test_user: User,
|
||||||
|
db_session: AsyncSession
|
||||||
|
) -> None:
|
||||||
|
|
||||||
|
user_repo = UsersRepository(db_session)
|
||||||
|
new_user_group = UserGroupCreate(
|
||||||
|
name="test_group",
|
||||||
|
)
|
||||||
|
group_in_db = await user_repo.create_user_group(new_user_group)
|
||||||
|
response = await client.put(
|
||||||
|
app.url_path_for(
|
||||||
|
"add_member_to_group",
|
||||||
|
user_group_id=group_in_db.user_group_id,
|
||||||
|
user_id=str(test_user.user_id)
|
||||||
|
)
|
||||||
|
)
|
||||||
assert response.status_code == status.HTTP_204_NO_CONTENT
|
assert response.status_code == status.HTTP_204_NO_CONTENT
|
||||||
members = await user_repo.get_user_group_members(group_in_db.user_group_id)
|
members = await user_repo.get_user_group_members(group_in_db.user_group_id)
|
||||||
assert len(members) == 1
|
assert len(members) == 1
|
||||||
@ -136,7 +158,7 @@ class TestGroupMembersRoutes:
|
|||||||
) -> None:
|
) -> None:
|
||||||
|
|
||||||
user_repo = UsersRepository(db_session)
|
user_repo = UsersRepository(db_session)
|
||||||
group_in_db = await user_repo.get_user_group_by_name("Users")
|
group_in_db = await user_repo.get_user_group_by_name("test_group")
|
||||||
response = await client.get(
|
response = await client.get(
|
||||||
app.url_path_for(
|
app.url_path_for(
|
||||||
"get_user_group_members",
|
"get_user_group_members",
|
||||||
@ -154,7 +176,7 @@ class TestGroupMembersRoutes:
|
|||||||
) -> None:
|
) -> None:
|
||||||
|
|
||||||
user_repo = UsersRepository(db_session)
|
user_repo = UsersRepository(db_session)
|
||||||
group_in_db = await user_repo.get_user_group_by_name("Users")
|
group_in_db = await user_repo.get_user_group_by_name("test_group")
|
||||||
|
|
||||||
response = await client.delete(
|
response = await client.delete(
|
||||||
app.url_path_for(
|
app.url_path_for(
|
||||||
|
Loading…
Reference in New Issue
Block a user