diff --git a/app/controllers/aaManager.py b/app/controllers/aaManager.py index 97a3531..0fc1756 100644 --- a/app/controllers/aaManager.py +++ b/app/controllers/aaManager.py @@ -1,4 +1,4 @@ -from fastapi import APIRouter, Depends, HTTPException +from fastapi import APIRouter, Depends, HTTPException, status from sqlmodel import Session, select from sqlalchemy.orm import selectinload from typing import List @@ -44,7 +44,7 @@ def assign_accessauth(*, db: Session = Depends(get_session), group_id: int, aa_i if db_aa is None: raise HTTPException(status_code=404, detail="AA not found") if db_aa in db_group.accessauths: - raise HTTPException(status_code=200, detail="AA already assigned to group") + raise HTTPException(status_code=status.HTTP_409_CONFLICT, detail="AA already assigned to group") db_group.accessauths.append(db_aa) return add_and_refresh(db, db_group) diff --git a/test/test_services/test_aa_manager.py b/test/test_services/test_aa_manager.py index 5f5566d..292397f 100644 --- a/test/test_services/test_aa_manager.py +++ b/test/test_services/test_aa_manager.py @@ -75,8 +75,9 @@ def test_assign_already_assigned_access_auth(client, auth_headers, test_group, t f"/aa/assign/{test_group.id}/{test_aa.id}", headers=auth_headers ) - # According to the code, this returns 200 with "already assigned" message - assert response.status_code == 200 + # According to the code, this returns 409 with "already assigned" message + assert response.status_code == 409 + assert "already assigned" in response.json()["detail"].lower() def test_unassign_access_auth_from_group(client, auth_headers, test_group, test_aa):