Skip to content

Commit

Permalink
Allow Namespace pydantic model to have a null metadata_ entry
Browse files Browse the repository at this point in the history
  • Loading branch information
soapy1 committed Jan 29, 2025
1 parent 5adaa52 commit e9ad110
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion conda-store-server/conda_store_server/_internal/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def from_list(cls, lst):
class Namespace(BaseModel):
id: int
name: Annotated[str, StringConstraints(pattern=f"^[{ALLOWED_CHARACTERS}]+$")] # noqa: F722
metadata_: Dict[str, Any] = None
metadata_: Optional[Dict[str, Any]] = None
role_mappings: List[NamespaceRoleMapping] = []
model_config = ConfigDict(from_attributes=True)

Expand Down
10 changes: 10 additions & 0 deletions conda-store-server/tests/_internal/server/views/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,16 @@ def test_api_list_namespace_auth(testclient, seed_conda_store, authenticate):
assert sorted([_.name for _ in r.data]) == ["default", "namespace1", "namespace2"]


def test_api_list_namespace_including_missing_metadata_(testclient, seed_namespace_with_edge_cases, authenticate):
response = testclient.get("api/v1/namespace")
response.raise_for_status()

r = schema.APIListNamespace.model_validate(response.json())
assert r.status == schema.APIStatus.OK
namespaces = [_.name for _ in r.data]
assert "namespace_missing_meta" in namespaces


def test_api_get_namespace_unauth(testclient, seed_conda_store):
response = testclient.get("api/v1/namespace/default")
response.raise_for_status()
Expand Down
12 changes: 12 additions & 0 deletions conda-store-server/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,18 @@ def alembic_config(conda_store):
return {"file": ini_file}


@pytest.fixture
def seed_namespace_with_edge_cases(db: Session, conda_store):
namespaces = [
orm.Namespace(name="normal_namespace"),
orm.Namespace(name="namespace_missing_meta", metadata_=None)
]

for namespace in namespaces:
db.add(namespace)
db.commit()


def _seed_conda_store(
db: Session,
conda_store,
Expand Down

0 comments on commit e9ad110

Please sign in to comment.