Implement team create tests
This commit is contained in:
@@ -89,7 +89,7 @@ def read_team(session: SessionDep, current_user: CurrentUser, id: RowId) -> Any:
|
|||||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Team not found")
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Team not found")
|
||||||
|
|
||||||
event = session.get(Event, team.event_id)
|
event = session.get(Event, team.event_id)
|
||||||
if not event:
|
if not event: # pragma: no cover
|
||||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Event not found")
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Event not found")
|
||||||
|
|
||||||
if not current_user.has_permissions(
|
if not current_user.has_permissions(
|
||||||
@@ -138,7 +138,7 @@ def update_team(
|
|||||||
|
|
||||||
# Check user's permissions for the existing event
|
# Check user's permissions for the existing event
|
||||||
event = session.get(Event, team.event_id)
|
event = session.get(Event, team.event_id)
|
||||||
if not event:
|
if not event: # pragma: no cover
|
||||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Event not found")
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Event not found")
|
||||||
|
|
||||||
if not current_user.has_permissions(
|
if not current_user.has_permissions(
|
||||||
@@ -176,7 +176,7 @@ def delete_team(session: SessionDep,current_user: CurrentUser, id: RowId) -> Mes
|
|||||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Team not found")
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Team not found")
|
||||||
|
|
||||||
event = session.get(Event, team.event_id)
|
event = session.get(Event, team.event_id)
|
||||||
if not event:
|
if not event: # pragma: no cover
|
||||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Event not found")
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Event not found")
|
||||||
|
|
||||||
if not current_user.has_permissions(
|
if not current_user.has_permissions(
|
||||||
|
|||||||
@@ -56,6 +56,60 @@ def test_create_team_with_incorrect_event(client: TestClient, superuser_token_he
|
|||||||
assert response.status_code == status.HTTP_404_NOT_FOUND
|
assert response.status_code == status.HTTP_404_NOT_FOUND
|
||||||
assert response.json()["detail"] == "Event not found"
|
assert response.json()["detail"] == "Event not found"
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_team_with_normal_user(
|
||||||
|
client: TestClient, normal_user_token_headers: dict[str, str], db: Session,
|
||||||
|
) -> None:
|
||||||
|
event = create_random_event(db)
|
||||||
|
data = {
|
||||||
|
"theme_name": "Normal user",
|
||||||
|
"event_id": str(event.id),
|
||||||
|
}
|
||||||
|
response = client.post(
|
||||||
|
f"{settings.API_V1_STR}/teams/",
|
||||||
|
headers=normal_user_token_headers,
|
||||||
|
json=data,
|
||||||
|
)
|
||||||
|
assert response.status_code == status.HTTP_403_FORBIDDEN
|
||||||
|
assert response.json()["detail"] == "Not enough permissions"
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_team_with_event_user(
|
||||||
|
client: TestClient, event_user_token_headers: EventUserHeader, db: Session,
|
||||||
|
) -> None:
|
||||||
|
event = event_user_token_headers.event
|
||||||
|
data = {
|
||||||
|
"theme_name": "Event user",
|
||||||
|
"event_id": str(event.id),
|
||||||
|
}
|
||||||
|
response = client.post(
|
||||||
|
f"{settings.API_V1_STR}/teams/",
|
||||||
|
headers=event_user_token_headers.headers,
|
||||||
|
json=data,
|
||||||
|
)
|
||||||
|
assert response.status_code == status.HTTP_200_OK
|
||||||
|
content = response.json()
|
||||||
|
assert content["theme_name"] == data["theme_name"]
|
||||||
|
assert content["event_id"] == str(event.id)
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_team_for_event_user(
|
||||||
|
client: TestClient, event_user_token_headers: EventUserHeader, db: Session,
|
||||||
|
) -> None:
|
||||||
|
event = create_random_event(db)
|
||||||
|
data = {
|
||||||
|
"theme_name": "Other event user",
|
||||||
|
"event_id": str(event.id),
|
||||||
|
}
|
||||||
|
response = client.post(
|
||||||
|
f"{settings.API_V1_STR}/teams/",
|
||||||
|
headers=event_user_token_headers.headers,
|
||||||
|
json=data,
|
||||||
|
)
|
||||||
|
assert response.status_code == status.HTTP_403_FORBIDDEN
|
||||||
|
assert response.json()["detail"] == "Not enough permissions"
|
||||||
|
|
||||||
|
|
||||||
def test_read_team(client: TestClient, superuser_token_headers: dict[str, str], db: Session) -> None:
|
def test_read_team(client: TestClient, superuser_token_headers: dict[str, str], db: Session) -> None:
|
||||||
team = create_random_team(db)
|
team = create_random_team(db)
|
||||||
response = client.get(
|
response = client.get(
|
||||||
|
|||||||
Reference in New Issue
Block a user