Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sverhoeven committed Jan 10, 2024
1 parent d532117 commit 2e08ec9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/bartender/web/api/applications/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,17 @@ async def upload_job( # noqa: WPS211
Raises:
IndexError: When job could not created inside database or when config
file was not found.
KeyError: Application is invalid.
HTTPException: Application is invalid.
Returns:
redirect response.
"""
if application not in context.applications:
valid = context.applications.keys()
raise KeyError(f"Invalid application. Valid applications: {valid}")
raise HTTPException(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
detail=f"Invalid application. Valid applications: {valid}",
)
_check_role(application, submitter, context)
job_id = await job_dao.create_job(upload.filename, application, submitter.username)
if job_id is None:
Expand Down
16 changes: 16 additions & 0 deletions tests/web/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@ async def test_upload_with_no_role_granted(
assert "Missing role" in response.text


@pytest.mark.anyio
async def test_upload_invalid_application(
fastapi_app: FastAPI,
client: AsyncClient,
tmp_path: Path,
auth_headers: Dict[str, str],
) -> None:
"""Test upload of a job archive."""
url = fastapi_app.url_path_for("upload_job", application="appzzzzzzzz")
with prepare_form_data(tmp_path) as files:
response = await client.put(url, files=files, headers=auth_headers)

assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
assert "Invalid application" in response.text


def assert_job_dir( # noqa: WPS218
job_root_dir: Path,
job_id: str,
Expand Down

0 comments on commit 2e08ec9

Please sign in to comment.