Skip to content

Commit

Permalink
Reuse MissingRecordError rather than using EntityNotFoundError
Browse files Browse the repository at this point in the history
  • Loading branch information
joelvdavies committed Oct 19, 2023
1 parent 6e3d925 commit eba5aff
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 14 deletions.
4 changes: 2 additions & 2 deletions inventory_management_system_api/core/breadcrumbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from inventory_management_system_api.core.consts import BREADCRUMBS_TRAIL_MAX_LENGTH
from inventory_management_system_api.core.custom_object_id import CustomObjectId
from inventory_management_system_api.core.exceptions import DatabaseIntegrityError, EntityNotFoundError
from inventory_management_system_api.core.exceptions import DatabaseIntegrityError, MissingRecordError
from inventory_management_system_api.schemas.breadcrumbs import BreadcrumbsGetSchema

logger = logging.getLogger()
Expand Down Expand Up @@ -67,7 +67,7 @@ def query_breadcrumbs(entity_id: str, entity_collection: Collection, graph_looku
)
)[0]["result"]
if len(result) == 0:
raise EntityNotFoundError(f"Entity with the ID {entity_id} was not found in the collection {graph_lookup_from}")
raise MissingRecordError(f"Entity with the ID {entity_id} was not found in the collection {graph_lookup_from}")
for element in result:
trail.append((str(element["_id"]), element["name"]))
full_trail = result[0]["parent_id"] is None
Expand Down
6 changes: 0 additions & 6 deletions inventory_management_system_api/core/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,3 @@ class DatabaseIntegrityError(DatabaseError):
"""
Exception raised when something is found in the database that shouldn't have been
"""


class EntityNotFoundError(Exception):
"""
An entity with a given ID was not found
"""
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
ChildrenElementsExistError,
DatabaseIntegrityError,
DuplicateRecordError,
EntityNotFoundError,
InvalidObjectIdError,
LeafCategoryError,
MissingRecordError,
Expand Down Expand Up @@ -76,7 +75,7 @@ def get_catalogue_category_breadcrumbs(
# pylint: disable=missing-function-docstring
try:
return catalogue_category_service.get_breadcrumbs(catalogue_category_id)
except (InvalidObjectIdError, EntityNotFoundError) as exc:
except (MissingRecordError, InvalidObjectIdError) as exc:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND, detail="Catalogue category with such ID was not found"
) from exc
Expand Down
3 changes: 1 addition & 2 deletions inventory_management_system_api/routers/v1/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
ChildrenElementsExistError,
DatabaseIntegrityError,
DuplicateRecordError,
EntityNotFoundError,
InvalidObjectIdError,
MissingRecordError,
)
Expand Down Expand Up @@ -69,7 +68,7 @@ def get_system_breadcrumbs(
# pylint: disable=duplicate-code
try:
return system_service.get_breadcrumbs(system_id)
except (InvalidObjectIdError, EntityNotFoundError) as exc:
except (MissingRecordError, InvalidObjectIdError) as exc:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="System with such ID was not found") from exc
except DatabaseIntegrityError as exc:
raise HTTPException(
Expand Down
4 changes: 2 additions & 2 deletions test/unit/core/test_breacrumbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from inventory_management_system_api.core.custom_object_id import CustomObjectId
from inventory_management_system_api.core.exceptions import (
DatabaseIntegrityError,
EntityNotFoundError,
InvalidObjectIdError,
MissingRecordError,
)

MOCK_AGGREGATE_RESPONSE_LESS_THAN_MAX_LENGTH = [
Expand Down Expand Up @@ -138,7 +138,7 @@ def test_query_breadcrumbs_when_entity_not_found(self):

mock_entity_collection.aggregate.return_value = MOCK_AGGREGATE_RESPONSE_NON_EXISTENT_ID

with pytest.raises(EntityNotFoundError) as exc:
with pytest.raises(MissingRecordError) as exc:
breadcrumbs.query_breadcrumbs(
entity_id=entity_id, entity_collection=mock_entity_collection, graph_lookup_from=graph_lookup_from
)
Expand Down

0 comments on commit eba5aff

Please sign in to comment.