mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-12 19:38:57 +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:
|
||||
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)
|
||||
if not user_group:
|
||||
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
|
||||
fastapi==0.103.0
|
||||
fastapi==0.103.1
|
||||
python-multipart==0.0.6
|
||||
websockets==11.0.3
|
||||
aiohttp>=3.8.5,<3.9
|
||||
@ -10,7 +10,7 @@ sentry-sdk==1.30.0,<1.31
|
||||
psutil==5.9.5
|
||||
distro>=1.8.0
|
||||
py-cpuinfo==9.0.0
|
||||
sqlalchemy==2.0.18
|
||||
sqlalchemy==2.0.20
|
||||
aiosqlite==0.19.0
|
||||
alembic==1.12.0
|
||||
passlib[bcrypt]==1.7.4
|
||||
|
@ -22,7 +22,7 @@ from httpx import AsyncClient
|
||||
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
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
|
||||
|
||||
@ -106,7 +106,7 @@ class TestGroupRoutes:
|
||||
|
||||
class TestGroupMembersRoutes:
|
||||
|
||||
async def test_add_member_to_group(
|
||||
async def test_add_to_group_already_member(
|
||||
self,
|
||||
app: FastAPI,
|
||||
client: AsyncClient,
|
||||
@ -123,6 +123,28 @@ class TestGroupMembersRoutes:
|
||||
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
|
||||
members = await user_repo.get_user_group_members(group_in_db.user_group_id)
|
||||
assert len(members) == 1
|
||||
@ -136,7 +158,7 @@ class TestGroupMembersRoutes:
|
||||
) -> None:
|
||||
|
||||
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(
|
||||
app.url_path_for(
|
||||
"get_user_group_members",
|
||||
@ -154,7 +176,7 @@ class TestGroupMembersRoutes:
|
||||
) -> None:
|
||||
|
||||
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(
|
||||
app.url_path_for(
|
||||
|
Loading…
Reference in New Issue
Block a user