Skip to content

Commit

Permalink
fix a bunch of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
paulineribeyre committed Nov 4, 2024
1 parent baed9c8 commit ba8e043
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 25 deletions.
13 changes: 12 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ bleach = ">=3.3.1"
tenacity = ">=8.0.0"
pydash = "^5.1.0"
pathvalidate = "^3.2.0"
python-multipart = "<1"

[tool.poetry.dev-dependencies]
pytest = "^5.3"
Expand Down
8 changes: 4 additions & 4 deletions src/mds/agg_mds/query.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from fastapi import HTTPException, Query, APIRouter, Request
from fastapi import HTTPException, Path, Query, APIRouter, Request
from starlette.status import HTTP_404_NOT_FOUND
from mds import config
from mds.agg_mds import datastore
Expand Down Expand Up @@ -143,9 +143,9 @@ async def get_aggregate_metadata(

@mod.get("/aggregate/metadata/{name}")
async def get_aggregate_metadata_for_commons(
name: str = Query(
False, description="Return the results without grouping items by commons."
)
name: str = Path(
description="Return the results without grouping items by commons."
),
):
"""et all metadata records from a commons by name
Expand Down
15 changes: 4 additions & 11 deletions src/mds/aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,23 @@
to point to the same blob, aliases allow that without duplicating the
actual blob.
"""
import json
import re
from typing import Union

from asyncpg import UniqueViolationError, ForeignKeyViolationError
from fastapi import HTTPException, APIRouter, Depends
from pydantic import BaseModel
from sqlalchemy import bindparam
from sqlalchemy.dialects.postgresql import insert
from starlette.requests import Request
from starlette.responses import JSONResponse
from starlette.status import (
HTTP_200_OK,
HTTP_201_CREATED,
HTTP_204_NO_CONTENT,
HTTP_400_BAD_REQUEST,
HTTP_404_NOT_FOUND,
HTTP_409_CONFLICT,
)
import urllib.parse

from .admin_login import admin_required
from .models import db, MetadataAlias, Metadata
from . import config, logger
from .objects import FORBIDDEN_IDS
from .models import MetadataAlias
from . import logger

mod = APIRouter()

Expand All @@ -43,7 +36,7 @@ class AliasObjInput(BaseModel):
specified
"""

aliases: list = None
aliases: list[str] = None


@mod.post("/metadata/{guid:path}/aliases")
Expand Down
3 changes: 1 addition & 2 deletions src/mds/maintain.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import json
import re

from asyncpg import UniqueViolationError
from fastapi import HTTPException, APIRouter, Depends
Expand All @@ -24,7 +23,7 @@

@mod.post("/metadata")
async def batch_create_metadata(
request: Request, data_list: list, overwrite: bool = True
request: Request, data_list: list[dict], overwrite: bool = True
):
"""Create metadata in batch."""
request.scope.get("add_close_watcher", lambda: None)()
Expand Down
20 changes: 13 additions & 7 deletions tests/test_aliases.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import gino
import httpx
import pytest
import urllib.parse

Expand Down Expand Up @@ -28,14 +28,20 @@ def test_create_read_delete_new_aliases(guid, aliases, client, is_post):
client.post(f"/metadata/{guid}", json=data).raise_for_status()

if is_post:
client.post(
f"/metadata/{guid}/aliases", json={"aliases": aliases}
).raise_for_status()
res = client.post(f"/metadata/{guid}/aliases", json={"aliases": aliases})
if aliases is None:
with pytest.raises(httpx.HTTPStatusError, match="422 Unprocessable Entity"):
res.raise_for_status()
else:
res.raise_for_status()
else:
# use PUT instead of POST, should result in same behavior for new aliases
client.put(
f"/metadata/{guid}/aliases", json={"aliases": aliases}
).raise_for_status()
res = client.put(f"/metadata/{guid}/aliases", json={"aliases": aliases})
if aliases is None:
with pytest.raises(httpx.HTTPStatusError, match="422 Unprocessable Entity"):
res.raise_for_status()
else:
res.raise_for_status()

# convert None to empty list for comparison of output
# because we always expect the output to be a list, even if the input is not
Expand Down

0 comments on commit ba8e043

Please sign in to comment.