-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow
identity
, ensure dimensions
is returned, & use pre-commit.ci (
#103) Update tests with valid entity using 'identity'. Ensure "identity" is respected everywhere. Ensure "dimensions" is always returned. Pre-commit is now run through pre-commit.ci.
- Loading branch information
Showing
15 changed files
with
344 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
"""Utility functions for the service.""" | ||
|
||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
from entities_service.service.backend import get_backend | ||
from entities_service.service.config import CONFIG | ||
|
||
if TYPE_CHECKING: # pragma: no cover | ||
from typing import Any | ||
|
||
|
||
async def _add_dimensions(entity: dict[str, Any] | list[dict[str, Any]]) -> None: | ||
"""Utility function for the endpoints to add dimensions to an entity.""" | ||
if isinstance(entity, list): | ||
for entity_ in entity: | ||
await _add_dimensions(entity_) | ||
return | ||
|
||
if "dimensions" not in entity: | ||
# SOFT5 | ||
if isinstance(entity["properties"], list): | ||
entity["dimensions"] = [] | ||
|
||
# SOFT7 | ||
elif isinstance(entity["properties"], dict): | ||
entity["dimensions"] = {} | ||
|
||
else: | ||
raise ValueError(f"Invalid entity: uri={entity['uri']}") | ||
|
||
|
||
async def _get_entity(version: str, name: str, db: str | None = None) -> dict[str, Any]: | ||
"""Utility function for the endpoints to retrieve an entity.""" | ||
uri = f"{str(CONFIG.base_url).rstrip('/')}" | ||
|
||
if db: | ||
uri += f"/{db}" | ||
|
||
uri += f"/{version}/{name}" | ||
|
||
entity = get_backend(db=db).read(uri) | ||
|
||
if entity is None: | ||
raise ValueError(f"Could not find entity: uri={uri}") | ||
|
||
await _add_dimensions(entity) | ||
|
||
return entity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.