Skip to content

Commit

Permalink
More tests + min length 1
Browse files Browse the repository at this point in the history
  • Loading branch information
sverhoeven committed Feb 1, 2024
1 parent 2b28e44 commit 3a24869
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/bartender/web/api/job/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ async def rename_job_name(
jobid: int,
job_dao: CurrentJobDAO,
user: CurrentUser,
name: Annotated[str, Body(max_length=MAX_LENGTH_NAME)],
name: Annotated[str, Body(max_length=MAX_LENGTH_NAME, min_length=1)],
) -> None:
"""Rename the name of a job.
Expand Down
43 changes: 43 additions & 0 deletions tests/web/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,3 +790,46 @@ async def test_rename_job_name(

renamed_job = response2.json()
assert renamed_job["name"] == "newname"


@pytest.mark.anyio
async def test_rename_job_name_too_short(
fastapi_app: FastAPI,
client: AsyncClient,
auth_headers: Dict[str, str],
mock_ok_job: int,
) -> None:
jobid = str(mock_ok_job)
name = ""
url = fastapi_app.url_path_for("rename_job_name", jobid=jobid)
response = await client.post(url, headers=auth_headers, json=name)

assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
expected = {
"detail": [
{
"ctx": {"limit_value": 1},
"loc": ["body"],
"msg": "ensure this value has at least 1 characters",
"type": "value_error.any_str.min_length",
},
],
}
assert response.json() == expected


@pytest.mark.anyio
async def test_rename_job_name_wrong_user(
fastapi_app: FastAPI,
client: AsyncClient,
second_user_token: str,
mock_ok_job: int,
) -> None:
jobid = str(mock_ok_job)
name = "newname"
url = fastapi_app.url_path_for("rename_job_name", jobid=jobid)
headers = {"Authorization": f"Bearer {second_user_token}"}
response = await client.post(url, headers=headers, json=name)

assert response.status_code == status.HTTP_404_NOT_FOUND
assert response.json() == {"detail": "Job not found"}

0 comments on commit 3a24869

Please sign in to comment.