diff --git a/inventory_management_system_api/routers/v1/catalogue_category.py b/inventory_management_system_api/routers/v1/catalogue_category.py index 30073d8f..a829287e 100644 --- a/inventory_management_system_api/routers/v1/catalogue_category.py +++ b/inventory_management_system_api/routers/v1/catalogue_category.py @@ -20,10 +20,10 @@ ) from inventory_management_system_api.schemas.breadcrumbs import BreadcrumbsGetSchema from inventory_management_system_api.schemas.catalogue_category import ( - CatalogueCategoryPatchRequestSchema, - CatalogueCategoryPostRequestSchema, - CatalogueCategoryPropertyPatchRequestSchema, - CatalogueCategoryPropertyPostRequestSchema, + CatalogueCategoryPatchSchema, + CatalogueCategoryPostSchema, + CatalogueCategoryPropertyPatchSchema, + CatalogueCategoryPropertyPostSchema, CatalogueCategoryPropertySchema, CatalogueCategorySchema, ) @@ -115,7 +115,7 @@ def get_catalogue_category_breadcrumbs( status_code=status.HTTP_201_CREATED, ) def create_catalogue_category( - catalogue_category: CatalogueCategoryPostRequestSchema, catalogue_category_service: CatalogueCategoryServiceDep + catalogue_category: CatalogueCategoryPostSchema, catalogue_category_service: CatalogueCategoryServiceDep ) -> CatalogueCategorySchema: # pylint: disable=missing-function-docstring logger.info("Creating a new catalogue category") @@ -154,7 +154,7 @@ def create_catalogue_category( response_description="Catalogue category updated successfully", ) def partial_update_catalogue_category( - catalogue_category: CatalogueCategoryPatchRequestSchema, + catalogue_category: CatalogueCategoryPatchSchema, catalogue_category_id: Annotated[str, Path(description="The ID of the catalogue category to update")], catalogue_category_service: CatalogueCategoryServiceDep, ) -> CatalogueCategorySchema: @@ -236,7 +236,7 @@ def delete_catalogue_category( status_code=status.HTTP_201_CREATED, ) def create_property( - catalogue_category_property: CatalogueCategoryPropertyPostRequestSchema, + catalogue_category_property: CatalogueCategoryPropertyPostSchema, catalogue_category_id: Annotated[str, Path(description="The ID of the catalogue category to add a property to")], catalogue_category_property_service: CatalogueCategoryPropertyServiceDep, ) -> CatalogueCategoryPropertySchema: @@ -277,7 +277,7 @@ def create_property( response_description="The updated property as defined at the catalogue category level", ) def partial_update_property( - catalogue_category_property: CatalogueCategoryPropertyPatchRequestSchema, + catalogue_category_property: CatalogueCategoryPropertyPatchSchema, catalogue_category_id: Annotated[ str, Path(description="The ID of the catalogue category containing the property to patch") ], diff --git a/inventory_management_system_api/routers/v1/catalogue_item.py b/inventory_management_system_api/routers/v1/catalogue_item.py index defc39d5..624b54de 100644 --- a/inventory_management_system_api/routers/v1/catalogue_item.py +++ b/inventory_management_system_api/routers/v1/catalogue_item.py @@ -11,15 +11,15 @@ from inventory_management_system_api.core.exceptions import ( ChildElementsExistError, InvalidActionError, - InvalidPropertyTypeError, InvalidObjectIdError, + InvalidPropertyTypeError, MissingMandatoryProperty, MissingRecordError, NonLeafCatalogueCategoryError, ) from inventory_management_system_api.schemas.catalogue_item import ( - CatalogueItemPatchRequestSchema, - CatalogueItemPostRequestSchema, + CatalogueItemPatchSchema, + CatalogueItemPostSchema, CatalogueItemSchema, ) from inventory_management_system_api.services.catalogue_item import CatalogueItemService @@ -78,7 +78,7 @@ def get_catalogue_item( status_code=status.HTTP_201_CREATED, ) def create_catalogue_item( - catalogue_item: CatalogueItemPostRequestSchema, catalogue_item_service: CatalogueItemServiceDep + catalogue_item: CatalogueItemPostSchema, catalogue_item_service: CatalogueItemServiceDep ) -> CatalogueItemSchema: # pylint: disable=missing-function-docstring logger.info("Creating a new catalogue item") @@ -114,7 +114,7 @@ def create_catalogue_item( response_description="Catalogue item updated successfully", ) def partial_update_catalogue_item( - catalogue_item: CatalogueItemPatchRequestSchema, + catalogue_item: CatalogueItemPatchSchema, catalogue_item_id: Annotated[str, Path(description="The ID of the catalogue item to update")], catalogue_item_service: CatalogueItemServiceDep, ) -> CatalogueItemSchema: diff --git a/inventory_management_system_api/routers/v1/item.py b/inventory_management_system_api/routers/v1/item.py index 304b82a0..e806d402 100644 --- a/inventory_management_system_api/routers/v1/item.py +++ b/inventory_management_system_api/routers/v1/item.py @@ -5,17 +5,17 @@ import logging from typing import Annotated, List, Optional -from fastapi import APIRouter, Query, status, HTTPException, Depends, Path +from fastapi import APIRouter, Depends, HTTPException, Path, Query, status from inventory_management_system_api.core.exceptions import ( + DatabaseIntegrityError, InvalidActionError, InvalidObjectIdError, + InvalidPropertyTypeError, MissingMandatoryProperty, MissingRecordError, - DatabaseIntegrityError, - InvalidPropertyTypeError, ) -from inventory_management_system_api.schemas.item import ItemPatchRequestSchema, ItemPostRequestSchema, ItemSchema +from inventory_management_system_api.schemas.item import ItemPatchSchema, ItemPostSchema, ItemSchema from inventory_management_system_api.services.item import ItemService logger = logging.getLogger() @@ -31,7 +31,7 @@ response_description="The created item", status_code=status.HTTP_201_CREATED, ) -def create_item(item: ItemPostRequestSchema, item_service: ItemServiceDep) -> ItemSchema: +def create_item(item: ItemPostSchema, item_service: ItemServiceDep) -> ItemSchema: # pylint: disable=missing-function-docstring logger.info("Creating a new item") logger.debug("Item data: %s", item) @@ -128,7 +128,7 @@ def get_item( response_description="Item updated successfully", ) def partial_update_item( - item: ItemPatchRequestSchema, + item: ItemPatchSchema, item_id: Annotated[str, Path(description="The ID of the item to update")], item_service: ItemServiceDep, ) -> ItemSchema: diff --git a/inventory_management_system_api/routers/v1/manufacturer.py b/inventory_management_system_api/routers/v1/manufacturer.py index 0c5f87bf..cb84689c 100644 --- a/inventory_management_system_api/routers/v1/manufacturer.py +++ b/inventory_management_system_api/routers/v1/manufacturer.py @@ -5,22 +5,22 @@ import logging from typing import Annotated, List -from fastapi import APIRouter, status, Depends, HTTPException, Path + +from fastapi import APIRouter, Depends, HTTPException, Path, status + from inventory_management_system_api.core.exceptions import ( DuplicateRecordError, InvalidObjectIdError, MissingRecordError, PartOfCatalogueItemError, ) - from inventory_management_system_api.schemas.manufacturer import ( - ManufacturerPatchRequestSchema, - ManufacturerPostRequestSchema, + ManufacturerPatchSchema, + ManufacturerPostSchema, ManufacturerSchema, ) from inventory_management_system_api.services.manufacturer import ManufacturerService - logger = logging.getLogger() router = APIRouter(prefix="/v1/manufacturers", tags=["manufacturers"]) @@ -35,7 +35,7 @@ status_code=status.HTTP_201_CREATED, ) def create_manufacturer( - manufacturer: ManufacturerPostRequestSchema, manufacturer_service: ManufacturerServiceDep + manufacturer: ManufacturerPostSchema, manufacturer_service: ManufacturerServiceDep ) -> ManufacturerSchema: # pylint: disable=missing-function-docstring logger.info("Creating a new manufacturer") @@ -93,7 +93,7 @@ def get_one_manufacturer( response_description="Manufacturer updated successfully", ) def edit_manufacturer( - manufacturer: ManufacturerPatchRequestSchema, + manufacturer: ManufacturerPatchSchema, manufacturer_id: Annotated[str, Path(description="The ID of the manufacturer that is to be updated")], manufacturer_service: ManufacturerServiceDep, ) -> ManufacturerSchema: diff --git a/inventory_management_system_api/routers/v1/unit.py b/inventory_management_system_api/routers/v1/unit.py index a69fa5cd..f4aaab63 100644 --- a/inventory_management_system_api/routers/v1/unit.py +++ b/inventory_management_system_api/routers/v1/unit.py @@ -6,7 +6,7 @@ import logging from typing import Annotated -from fastapi import APIRouter, Depends, status, HTTPException, Path +from fastapi import APIRouter, Depends, HTTPException, Path, status from inventory_management_system_api.core.exceptions import ( DuplicateRecordError, @@ -14,7 +14,7 @@ MissingRecordError, PartOfCatalogueCategoryError, ) -from inventory_management_system_api.schemas.unit import UnitPostRequestSchema, UnitSchema +from inventory_management_system_api.schemas.unit import UnitPostSchema, UnitSchema from inventory_management_system_api.services.unit import UnitService logger = logging.getLogger() @@ -30,7 +30,7 @@ response_description="The created unit", status_code=status.HTTP_201_CREATED, ) -def create_unit(unit: UnitPostRequestSchema, unit_service: UnitServiceDep) -> UnitSchema: +def create_unit(unit: UnitPostSchema, unit_service: UnitServiceDep) -> UnitSchema: # pylint: disable=missing-function-docstring logger.info("Creating a new unit") logger.debug("Unit data: %s", unit) diff --git a/inventory_management_system_api/routers/v1/usage_status.py b/inventory_management_system_api/routers/v1/usage_status.py index baed472f..c6c556d4 100644 --- a/inventory_management_system_api/routers/v1/usage_status.py +++ b/inventory_management_system_api/routers/v1/usage_status.py @@ -6,7 +6,7 @@ import logging from typing import Annotated -from fastapi import APIRouter, Depends, status, HTTPException, Path +from fastapi import APIRouter, Depends, HTTPException, Path, status from inventory_management_system_api.core.exceptions import ( DuplicateRecordError, @@ -14,7 +14,7 @@ MissingRecordError, PartOfItemError, ) -from inventory_management_system_api.schemas.usage_status import UsageStatusPostRequestSchema, UsageStatusSchema +from inventory_management_system_api.schemas.usage_status import UsageStatusPostSchema, UsageStatusSchema from inventory_management_system_api.services.usage_status import UsageStatusService logger = logging.getLogger() @@ -31,7 +31,7 @@ status_code=status.HTTP_201_CREATED, ) def create_usage_status( - usage_status: UsageStatusPostRequestSchema, usage_status_service: UsageStatusServiceDep + usage_status: UsageStatusPostSchema, usage_status_service: UsageStatusServiceDep ) -> UsageStatusSchema: # pylint: disable=missing-function-docstring logger.info("Creating a new usage status") diff --git a/inventory_management_system_api/schemas/catalogue_category.py b/inventory_management_system_api/schemas/catalogue_category.py index bf870925..ff08c0bd 100644 --- a/inventory_management_system_api/schemas/catalogue_category.py +++ b/inventory_management_system_api/schemas/catalogue_category.py @@ -35,7 +35,7 @@ class AllowedValuesListSchema(BaseModel): AllowedValuesSchema = Annotated[AllowedValuesListSchema, Field(discriminator="type")] -class CatalogueCategoryPostRequestPropertySchema(BaseModel): +class CatalogueCategoryPostPropertySchema(BaseModel): """ Schema model for a property within a catalogue category creation request. """ @@ -117,7 +117,7 @@ def check_valid_allowed_values( for allowed_value in allowed_values.values: # Ensure the value is the correct type - if not CatalogueCategoryPostRequestPropertySchema.is_valid_property_type( + if not CatalogueCategoryPostPropertySchema.is_valid_property_type( expected_property_type=property_data["type"], property_value=allowed_value ): raise ValueError( @@ -150,12 +150,12 @@ def validate_allowed_values( :return: The value of the `allowed_values` field. """ - CatalogueCategoryPostRequestPropertySchema.check_valid_allowed_values(allowed_values, info.data) + CatalogueCategoryPostPropertySchema.check_valid_allowed_values(allowed_values, info.data) return allowed_values -class CatalogueCategoryPropertySchema(CatalogueCategoryPostRequestPropertySchema): +class CatalogueCategoryPropertySchema(CatalogueCategoryPostPropertySchema): """ Schema model representing a property defined within a catalogue category """ @@ -164,7 +164,7 @@ class CatalogueCategoryPropertySchema(CatalogueCategoryPostRequestPropertySchema unit: Optional[str] = Field(default=None, description="The unit of the property such as 'nm', 'mm', 'cm' etc") -class CatalogueCategoryPostRequestSchema(BaseModel): +class CatalogueCategoryPostSchema(BaseModel): """ Schema model for a catalogue category creation request. """ @@ -175,7 +175,7 @@ class CatalogueCategoryPostRequestSchema(BaseModel): "elements but if it is not then it can only have catalogue categories as child elements." ) parent_id: Optional[str] = Field(default=None, description="The ID of the parent catalogue category") - properties: Optional[List[CatalogueCategoryPostRequestPropertySchema]] = Field( + properties: Optional[List[CatalogueCategoryPostPropertySchema]] = Field( default=None, description="The properties that the catalogue items in this category could/should have" ) @@ -184,7 +184,7 @@ class CatalogueCategoryPostRequestSchema(BaseModel): CATALOGUE_CATEGORY_WITH_CHILD_NON_EDITABLE_FIELDS = ["is_leaf", "properties"] -class CatalogueCategoryPatchRequestSchema(CatalogueCategoryPostRequestSchema): +class CatalogueCategoryPatchSchema(CatalogueCategoryPostSchema): """ Schema model for a catalogue category update request. """ @@ -197,7 +197,7 @@ class CatalogueCategoryPatchRequestSchema(CatalogueCategoryPostRequestSchema): ) -class CatalogueCategorySchema(CreatedModifiedSchemaMixin, CatalogueCategoryPostRequestSchema): +class CatalogueCategorySchema(CreatedModifiedSchemaMixin, CatalogueCategoryPostSchema): """ Schema model for a catalogue category response. """ @@ -209,7 +209,7 @@ class CatalogueCategorySchema(CreatedModifiedSchemaMixin, CatalogueCategoryPostR ) -class CatalogueCategoryPropertyPostRequestSchema(CatalogueCategoryPostRequestPropertySchema): +class CatalogueCategoryPropertyPostSchema(CatalogueCategoryPostPropertySchema): """ Schema model for a property creation request on a catalogue category """ @@ -234,7 +234,7 @@ def validate_default_value(cls, default_value: Any, info: ValidationInfo) -> Any :return: The value of the `allowed_values` field. """ if default_value is not None: - if not CatalogueCategoryPostRequestPropertySchema.is_valid_property_type( + if not CatalogueCategoryPostPropertySchema.is_valid_property_type( expected_property_type=info.data["type"], property_value=default_value ): raise ValueError("default_value must be the same type as the property itself") @@ -251,7 +251,7 @@ def validate_default_value(cls, default_value: Any, info: ValidationInfo) -> Any return default_value -class CatalogueCategoryPropertyPatchRequestSchema(BaseModel): +class CatalogueCategoryPropertyPatchSchema(BaseModel): """ Schema model for a property patch request on a catalogue category """ diff --git a/inventory_management_system_api/schemas/catalogue_item.py b/inventory_management_system_api/schemas/catalogue_item.py index 7318a474..af556797 100644 --- a/inventory_management_system_api/schemas/catalogue_item.py +++ b/inventory_management_system_api/schemas/catalogue_item.py @@ -9,7 +9,7 @@ from inventory_management_system_api.schemas.mixins import CreatedModifiedSchemaMixin -class PropertyPostRequestSchema(BaseModel): +class PropertyPostSchema(BaseModel): """ Schema model for a property creation request. """ @@ -18,7 +18,7 @@ class PropertyPostRequestSchema(BaseModel): value: Any = Field(default=None, description="The value of the property") -class PropertySchema(PropertyPostRequestSchema): +class PropertySchema(PropertyPostSchema): """ Schema model for a property response. """ @@ -28,7 +28,7 @@ class PropertySchema(PropertyPostRequestSchema): unit: Optional[str] = Field(default=None, description="The unit of the property such as 'nm', 'mm', 'cm' etc") -class CatalogueItemPostRequestSchema(BaseModel): +class CatalogueItemPostSchema(BaseModel): """ Schema model for a catalogue item creation request. """ @@ -54,7 +54,7 @@ class CatalogueItemPostRequestSchema(BaseModel): default=None, description="The ID of the catalogue item that replaces this catalogue item if obsolete" ) notes: Optional[str] = Field(default=None, description="Any notes about the catalogue item") - properties: Optional[List[PropertyPostRequestSchema]] = Field( + properties: Optional[List[PropertyPostSchema]] = Field( default=None, description="The properties specific to this catalogue item as defined in the corresponding " "catalogue category", @@ -65,7 +65,7 @@ class CatalogueItemPostRequestSchema(BaseModel): CATALOGUE_ITEM_WITH_CHILD_NON_EDITABLE_FIELDS = ["manufacturer_id", "properties"] -class CatalogueItemPatchRequestSchema(CatalogueItemPostRequestSchema): +class CatalogueItemPatchSchema(CatalogueItemPostSchema): """ Schema model for a catalogue item update request. """ @@ -82,7 +82,7 @@ class CatalogueItemPatchRequestSchema(CatalogueItemPostRequestSchema): is_obsolete: Optional[bool] = Field(default=None, description="Whether the catalogue item is obsolete or not") -class CatalogueItemSchema(CreatedModifiedSchemaMixin, CatalogueItemPostRequestSchema): +class CatalogueItemSchema(CreatedModifiedSchemaMixin, CatalogueItemPostSchema): """ Schema model for a catalogue item response. """ diff --git a/inventory_management_system_api/schemas/item.py b/inventory_management_system_api/schemas/item.py index eb9dd4d0..2f46c904 100644 --- a/inventory_management_system_api/schemas/item.py +++ b/inventory_management_system_api/schemas/item.py @@ -6,11 +6,11 @@ from pydantic import BaseModel, Field, AwareDatetime -from inventory_management_system_api.schemas.catalogue_item import PropertyPostRequestSchema, PropertySchema +from inventory_management_system_api.schemas.catalogue_item import PropertyPostSchema, PropertySchema from inventory_management_system_api.schemas.mixins import CreatedModifiedSchemaMixin -class ItemPostRequestSchema(BaseModel): +class ItemPostSchema(BaseModel): """ Schema model for an item creation request. """ @@ -25,14 +25,14 @@ class ItemPostRequestSchema(BaseModel): serial_number: Optional[str] = Field(default=None, description="The serial number of the item") delivered_date: Optional[AwareDatetime] = Field(default=None, description="The date the item was delivered") notes: Optional[str] = Field(default=None, description="Any notes about the item") - properties: Optional[List[PropertyPostRequestSchema]] = Field( + properties: Optional[List[PropertyPostSchema]] = Field( default=None, description="The properties specific to this item as defined in the corresponding catalogue category. All " "properties found in the catalogue item will be inherited if not explicitly provided.", ) -class ItemPatchRequestSchema(ItemPostRequestSchema): +class ItemPatchSchema(ItemPostSchema): """ Schema model for an item update request. """ @@ -46,14 +46,14 @@ class ItemPatchRequestSchema(ItemPostRequestSchema): default=None, description="The ID of the usage status of the item.", ) - properties: Optional[List[PropertyPostRequestSchema]] = Field( + properties: Optional[List[PropertyPostSchema]] = Field( default=None, description="The properties specific to this item. Any properties not declared will be overwritten by " "the inherited properties from the catalogue item.", ) -class ItemSchema(CreatedModifiedSchemaMixin, ItemPostRequestSchema): +class ItemSchema(CreatedModifiedSchemaMixin, ItemPostSchema): """ Schema model for an item response. """ diff --git a/inventory_management_system_api/schemas/manufacturer.py b/inventory_management_system_api/schemas/manufacturer.py index 2b6863c8..a6ab4f53 100644 --- a/inventory_management_system_api/schemas/manufacturer.py +++ b/inventory_management_system_api/schemas/manufacturer.py @@ -18,7 +18,7 @@ class AddressSchema(BaseModel): postcode: str = Field(description="Post Code/Zip of manufacturer") -class AddressPatchRequestSchema(AddressSchema): +class AddressPatchSchema(AddressSchema): """Schema used for editing address, so that it allows to edit individual fields""" address_line: Optional[str] = Field(default=None, description="The address line of the manufacturer") @@ -26,7 +26,7 @@ class AddressPatchRequestSchema(AddressSchema): country: Optional[str] = Field(default=None, description="Country of the manufacturer") -class ManufacturerPostRequestSchema(BaseModel): +class ManufacturerPostSchema(BaseModel): """Schema model for manufacturer creation request""" name: str = Field(description="Name of manufacturer") @@ -35,14 +35,14 @@ class ManufacturerPostRequestSchema(BaseModel): telephone: Optional[str] = Field(default=None, description="Phone number of manufacturer") -class ManufacturerPatchRequestSchema(ManufacturerPostRequestSchema): +class ManufacturerPatchSchema(ManufacturerPostSchema): """Schema model for editing a manufacturer""" name: Optional[str] = None - address: Optional[AddressPatchRequestSchema] = None + address: Optional[AddressPatchSchema] = None -class ManufacturerSchema(CreatedModifiedSchemaMixin, ManufacturerPostRequestSchema): +class ManufacturerSchema(CreatedModifiedSchemaMixin, ManufacturerPostSchema): """Schema model for manufacturer response""" id: str = Field(description="The ID of manufacturer") diff --git a/inventory_management_system_api/schemas/unit.py b/inventory_management_system_api/schemas/unit.py index 757be02d..f85a9756 100644 --- a/inventory_management_system_api/schemas/unit.py +++ b/inventory_management_system_api/schemas/unit.py @@ -7,7 +7,7 @@ from inventory_management_system_api.schemas.mixins import CreatedModifiedSchemaMixin -class UnitPostRequestSchema(BaseModel): +class UnitPostSchema(BaseModel): """ Schema model for a Unit post request """ @@ -15,7 +15,7 @@ class UnitPostRequestSchema(BaseModel): value: str = Field(description="Value of the Unit") -class UnitSchema(CreatedModifiedSchemaMixin, UnitPostRequestSchema): +class UnitSchema(CreatedModifiedSchemaMixin, UnitPostSchema): """ Schema model for a Unit get request response """ diff --git a/inventory_management_system_api/schemas/usage_status.py b/inventory_management_system_api/schemas/usage_status.py index db680812..8de3471c 100644 --- a/inventory_management_system_api/schemas/usage_status.py +++ b/inventory_management_system_api/schemas/usage_status.py @@ -7,7 +7,7 @@ from inventory_management_system_api.schemas.mixins import CreatedModifiedSchemaMixin -class UsageStatusPostRequestSchema(BaseModel): +class UsageStatusPostSchema(BaseModel): """ Schema model for a Usage status post request """ @@ -15,7 +15,7 @@ class UsageStatusPostRequestSchema(BaseModel): value: str = Field(description="Value of the Usage status") -class UsageStatusSchema(CreatedModifiedSchemaMixin, UsageStatusPostRequestSchema): +class UsageStatusSchema(CreatedModifiedSchemaMixin, UsageStatusPostSchema): """ Schema model for a Usage status get request response """ diff --git a/inventory_management_system_api/services/catalogue_category.py b/inventory_management_system_api/services/catalogue_category.py index da391ade..b9627c9c 100644 --- a/inventory_management_system_api/services/catalogue_category.py +++ b/inventory_management_system_api/services/catalogue_category.py @@ -19,9 +19,9 @@ from inventory_management_system_api.schemas.breadcrumbs import BreadcrumbsGetSchema from inventory_management_system_api.schemas.catalogue_category import ( CATALOGUE_CATEGORY_WITH_CHILD_NON_EDITABLE_FIELDS, - CatalogueCategoryPatchRequestSchema, - CatalogueCategoryPostRequestPropertySchema, - CatalogueCategoryPostRequestSchema, + CatalogueCategoryPatchSchema, + CatalogueCategoryPostPropertySchema, + CatalogueCategoryPostSchema, ) from inventory_management_system_api.services import utils @@ -47,7 +47,7 @@ def __init__( self._catalogue_category_repository = catalogue_category_repository self._unit_repository = unit_repository - def create(self, catalogue_category: CatalogueCategoryPostRequestSchema) -> CatalogueCategoryOut: + def create(self, catalogue_category: CatalogueCategoryPostSchema) -> CatalogueCategoryOut: """ Create a new catalogue category. @@ -118,7 +118,7 @@ def list(self, parent_id: Optional[str]) -> List[CatalogueCategoryOut]: return self._catalogue_category_repository.list(parent_id) def update( - self, catalogue_category_id: str, catalogue_category: CatalogueCategoryPatchRequestSchema + self, catalogue_category_id: str, catalogue_category: CatalogueCategoryPatchSchema ) -> CatalogueCategoryOut: """ Update a catalogue category by its ID. @@ -170,7 +170,7 @@ def update( def _add_property_unit_values( self, - properties: List[CatalogueCategoryPostRequestPropertySchema], + properties: List[CatalogueCategoryPostPropertySchema], ) -> List[dict[str, Any]]: """ Adds the unit values to the properties based on the provided unit IDs. diff --git a/inventory_management_system_api/services/catalogue_category_property.py b/inventory_management_system_api/services/catalogue_category_property.py index c543113a..0771252e 100644 --- a/inventory_management_system_api/services/catalogue_category_property.py +++ b/inventory_management_system_api/services/catalogue_category_property.py @@ -22,9 +22,9 @@ from inventory_management_system_api.repositories.unit import UnitRepo from inventory_management_system_api.schemas.catalogue_category import ( AllowedValuesSchema, - CatalogueCategoryPostRequestPropertySchema, - CatalogueCategoryPropertyPatchRequestSchema, - CatalogueCategoryPropertyPostRequestSchema, + CatalogueCategoryPostPropertySchema, + CatalogueCategoryPropertyPatchSchema, + CatalogueCategoryPropertyPostSchema, ) from inventory_management_system_api.services import utils @@ -60,7 +60,7 @@ def __init__( def create( self, catalogue_category_id: str, - catalogue_category_property: CatalogueCategoryPropertyPostRequestSchema, + catalogue_category_property: CatalogueCategoryPropertyPostSchema, ) -> CatalogueCategoryPropertyOut: """Create a new property at the catalogue category level @@ -178,7 +178,7 @@ def update( self, catalogue_category_id: str, catalogue_category_property_id: str, - catalogue_category_property: CatalogueCategoryPropertyPatchRequestSchema, + catalogue_category_property: CatalogueCategoryPropertyPatchSchema, ) -> CatalogueCategoryPropertyOut: """ Update a property at the catalogue category level by its id @@ -221,7 +221,7 @@ def update( existing_property_out.allowed_values, catalogue_category_property.allowed_values ) - CatalogueCategoryPostRequestPropertySchema.check_valid_allowed_values( + CatalogueCategoryPostPropertySchema.check_valid_allowed_values( catalogue_category_property.allowed_values, existing_property_out.model_dump() ) diff --git a/inventory_management_system_api/services/catalogue_item.py b/inventory_management_system_api/services/catalogue_item.py index b20b15c3..19c92626 100644 --- a/inventory_management_system_api/services/catalogue_item.py +++ b/inventory_management_system_api/services/catalogue_item.py @@ -21,8 +21,8 @@ from inventory_management_system_api.repositories.manufacturer import ManufacturerRepo from inventory_management_system_api.schemas.catalogue_item import ( CATALOGUE_ITEM_WITH_CHILD_NON_EDITABLE_FIELDS, - CatalogueItemPatchRequestSchema, - CatalogueItemPostRequestSchema, + CatalogueItemPatchSchema, + CatalogueItemPostSchema, ) from inventory_management_system_api.services import utils @@ -52,7 +52,7 @@ def __init__( self._catalogue_category_repository = catalogue_category_repository self._manufacturer_repository = manufacturer_repository - def create(self, catalogue_item: CatalogueItemPostRequestSchema) -> CatalogueItemOut: + def create(self, catalogue_item: CatalogueItemPostSchema) -> CatalogueItemOut: """ Create a new catalogue item. @@ -124,7 +124,7 @@ def list(self, catalogue_category_id: Optional[str]) -> List[CatalogueItemOut]: return self._catalogue_item_repository.list(catalogue_category_id) # pylint:disable=too-many-branches - def update(self, catalogue_item_id: str, catalogue_item: CatalogueItemPatchRequestSchema) -> CatalogueItemOut: + def update(self, catalogue_item_id: str, catalogue_item: CatalogueItemPatchSchema) -> CatalogueItemOut: """ Update a catalogue item by its ID. diff --git a/inventory_management_system_api/services/item.py b/inventory_management_system_api/services/item.py index abbcf4a2..0fc755da 100644 --- a/inventory_management_system_api/services/item.py +++ b/inventory_management_system_api/services/item.py @@ -21,8 +21,8 @@ from inventory_management_system_api.repositories.item import ItemRepo from inventory_management_system_api.repositories.system import SystemRepo from inventory_management_system_api.repositories.usage_status import UsageStatusRepo -from inventory_management_system_api.schemas.catalogue_item import PropertyPostRequestSchema -from inventory_management_system_api.schemas.item import ItemPatchRequestSchema, ItemPostRequestSchema +from inventory_management_system_api.schemas.catalogue_item import PropertyPostSchema +from inventory_management_system_api.schemas.item import ItemPatchSchema, ItemPostSchema from inventory_management_system_api.services import utils logger = logging.getLogger() @@ -58,7 +58,7 @@ def __init__( self._system_repository = system_repository self._usage_status_repository = usage_status_repository - def create(self, item: ItemPostRequestSchema) -> ItemOut: + def create(self, item: ItemPostSchema) -> ItemOut: """ Create a new item. @@ -124,7 +124,7 @@ def get(self, item_id: str) -> Optional[ItemOut]: """ return self._item_repository.get(item_id) - def update(self, item_id: str, item: ItemPatchRequestSchema) -> ItemOut: + def update(self, item_id: str, item: ItemPatchSchema) -> ItemOut: """ Update an item by its ID. @@ -183,8 +183,8 @@ def update(self, item_id: str, item: ItemPatchRequestSchema) -> ItemOut: return self._item_repository.update(item_id, ItemIn(**{**stored_item.model_dump(), **update_data})) def _merge_missing_properties( - self, properties: List[PropertyOut], supplied_properties: List[PropertyPostRequestSchema] - ) -> List[PropertyPostRequestSchema]: + self, properties: List[PropertyOut], supplied_properties: List[PropertyPostSchema] + ) -> List[PropertyPostSchema]: """ Merges the properties defined in a catalogue item with those that should be overriden for an item in the order they are defined in the catalogue item. @@ -196,7 +196,7 @@ def _merge_missing_properties( supplied_properties_dict = { supplied_property.id: supplied_property for supplied_property in supplied_properties } - merged_properties: List[PropertyPostRequestSchema] = [] + merged_properties: List[PropertyPostSchema] = [] # Use the order of properties from the catalogue item, and append either the supplied property or # the catalogue item one where it is not found @@ -205,5 +205,5 @@ def _merge_missing_properties( if supplied_property is not None: merged_properties.append(supplied_property) else: - merged_properties.append(PropertyPostRequestSchema(**prop.model_dump())) + merged_properties.append(PropertyPostSchema(**prop.model_dump())) return merged_properties diff --git a/inventory_management_system_api/services/manufacturer.py b/inventory_management_system_api/services/manufacturer.py index cc837ff4..aba02a08 100644 --- a/inventory_management_system_api/services/manufacturer.py +++ b/inventory_management_system_api/services/manufacturer.py @@ -10,8 +10,8 @@ from inventory_management_system_api.models.manufacturer import ManufacturerIn, ManufacturerOut from inventory_management_system_api.repositories.manufacturer import ManufacturerRepo from inventory_management_system_api.schemas.manufacturer import ( - ManufacturerPatchRequestSchema, - ManufacturerPostRequestSchema, + ManufacturerPatchSchema, + ManufacturerPostSchema, ) from inventory_management_system_api.services import utils @@ -33,7 +33,7 @@ def __init__( self._manufacturer_repository = manufacturer_repository - def create(self, manufacturer: ManufacturerPostRequestSchema) -> ManufacturerOut: + def create(self, manufacturer: ManufacturerPostSchema) -> ManufacturerOut: """ Create a new manufacturer. :param manufacturer: The manufacturer to be created. @@ -66,7 +66,7 @@ def list(self) -> List[ManufacturerOut]: """ return self._manufacturer_repository.list() - def update(self, manufacturer_id: str, manufacturer: ManufacturerPatchRequestSchema) -> ManufacturerOut: + def update(self, manufacturer_id: str, manufacturer: ManufacturerPatchSchema) -> ManufacturerOut: """Update a manufacturer by its ID diff --git a/inventory_management_system_api/services/unit.py b/inventory_management_system_api/services/unit.py index 1107eb3b..dd44d703 100644 --- a/inventory_management_system_api/services/unit.py +++ b/inventory_management_system_api/services/unit.py @@ -6,7 +6,7 @@ from fastapi import Depends from inventory_management_system_api.models.unit import UnitIn, UnitOut from inventory_management_system_api.repositories.unit import UnitRepo -from inventory_management_system_api.schemas.unit import UnitPostRequestSchema +from inventory_management_system_api.schemas.unit import UnitPostSchema from inventory_management_system_api.services import utils @@ -24,7 +24,7 @@ def __init__(self, unit_repository: Annotated[UnitRepo, Depends(UnitRepo)]) -> N """ self._unit_repository = unit_repository - def create(self, unit: UnitPostRequestSchema) -> UnitOut: + def create(self, unit: UnitPostSchema) -> UnitOut: """ Create a new Unit. diff --git a/inventory_management_system_api/services/usage_status.py b/inventory_management_system_api/services/usage_status.py index 12a6188e..603c8f99 100644 --- a/inventory_management_system_api/services/usage_status.py +++ b/inventory_management_system_api/services/usage_status.py @@ -8,7 +8,7 @@ from inventory_management_system_api.models.usage_status import UsageStatusIn, UsageStatusOut from inventory_management_system_api.repositories.usage_status import UsageStatusRepo -from inventory_management_system_api.schemas.usage_status import UsageStatusPostRequestSchema +from inventory_management_system_api.schemas.usage_status import UsageStatusPostSchema from inventory_management_system_api.services import utils @@ -25,7 +25,7 @@ def __init__(self, usage_status_repository: Annotated[UsageStatusRepo, Depends(U """ self._usage_status_repository = usage_status_repository - def create(self, usage_status: UsageStatusPostRequestSchema) -> UsageStatusOut: + def create(self, usage_status: UsageStatusPostSchema) -> UsageStatusOut: """ Create a new usage status. diff --git a/inventory_management_system_api/services/utils.py b/inventory_management_system_api/services/utils.py index 8d3e4421..463e9a7d 100644 --- a/inventory_management_system_api/services/utils.py +++ b/inventory_management_system_api/services/utils.py @@ -12,8 +12,8 @@ MissingMandatoryProperty, ) from inventory_management_system_api.models.catalogue_category import CatalogueCategoryPropertyOut -from inventory_management_system_api.schemas.catalogue_category import CatalogueCategoryPostRequestPropertySchema -from inventory_management_system_api.schemas.catalogue_item import PropertyPostRequestSchema +from inventory_management_system_api.schemas.catalogue_category import CatalogueCategoryPostPropertySchema +from inventory_management_system_api.schemas.catalogue_item import PropertyPostSchema logger = logging.getLogger() @@ -36,7 +36,7 @@ def generate_code(name: str, entity_type: str) -> str: def check_duplicate_property_names( - properties: list[CatalogueCategoryPostRequestPropertySchema | CatalogueCategoryPropertyOut], + properties: list[CatalogueCategoryPostPropertySchema | CatalogueCategoryPropertyOut], ) -> None: """ Go through a list of properties to check for any duplicate names during creation of a catalogue @@ -56,7 +56,7 @@ def check_duplicate_property_names( def process_properties( defined_properties: List[CatalogueCategoryPropertyOut], - supplied_properties: List[PropertyPostRequestSchema], + supplied_properties: List[PropertyPostSchema], ) -> List[Dict]: """ Process and validate supplied properties based on the defined properties. It checks for missing mandatory, filters @@ -87,7 +87,7 @@ def process_properties( def _create_properties_dict( - properties: Union[List[CatalogueCategoryPropertyOut], List[PropertyPostRequestSchema]] + properties: Union[List[CatalogueCategoryPropertyOut], List[PropertyPostSchema]] ) -> Dict[str, Dict]: """ Convert a list of property objects into a dictionary where the keys are the catalogue item @@ -162,7 +162,7 @@ def _validate_property_value(defined_property: Dict, supplied_property: Dict) -> if defined_property_mandatory: raise InvalidPropertyTypeError(f"Mandatory property with ID '{supplied_property_id}' cannot be None.") else: - if not CatalogueCategoryPostRequestPropertySchema.is_valid_property_type( + if not CatalogueCategoryPostPropertySchema.is_valid_property_type( defined_property_type, supplied_property_value ): raise InvalidPropertyTypeError( diff --git a/test/unit/services/test_catalogue_category.py b/test/unit/services/test_catalogue_category.py index 4fb85a26..aaf11ea3 100644 --- a/test/unit/services/test_catalogue_category.py +++ b/test/unit/services/test_catalogue_category.py @@ -23,8 +23,8 @@ ) from inventory_management_system_api.models.unit import UnitOut from inventory_management_system_api.schemas.catalogue_category import ( - CatalogueCategoryPatchRequestSchema, - CatalogueCategoryPostRequestSchema, + CatalogueCategoryPatchSchema, + CatalogueCategoryPostSchema, ) UNIT_A = { @@ -64,7 +64,7 @@ def test_create( test_helpers.mock_create(catalogue_category_repository_mock, catalogue_category) created_catalogue_category = catalogue_category_service.create( - CatalogueCategoryPostRequestSchema( + CatalogueCategoryPostSchema( name=catalogue_category.name, is_leaf=catalogue_category.is_leaf, properties=catalogue_category.properties, @@ -147,7 +147,7 @@ def test_create_with_parent_id( test_helpers.mock_create(catalogue_category_repository_mock, catalogue_category) created_catalogue_category = catalogue_category_service.create( - CatalogueCategoryPostRequestSchema( + CatalogueCategoryPostSchema( name=catalogue_category.name, is_leaf=catalogue_category.is_leaf, parent_id=catalogue_category.parent_id, @@ -216,7 +216,7 @@ def test_create_with_whitespace_name( test_helpers.mock_get(unit_repository_mock, unit) created_catalogue_category = catalogue_category_service.create( - CatalogueCategoryPostRequestSchema( + CatalogueCategoryPostSchema( name=catalogue_category.name, is_leaf=catalogue_category.is_leaf, properties=[prop.model_dump() for prop in catalogue_category.properties], @@ -298,7 +298,7 @@ def test_create_with_leaf_parent_catalogue_category( with pytest.raises(LeafCatalogueCategoryError) as exc: catalogue_category_service.create( - CatalogueCategoryPostRequestSchema( + CatalogueCategoryPostSchema( name=catalogue_category.name, is_leaf=catalogue_category.is_leaf, parent_id=catalogue_category.parent_id, @@ -339,7 +339,7 @@ def test_create_with_duplicate_property_names( with pytest.raises(DuplicateCatalogueCategoryPropertyNameError) as exc: # pylint: disable=duplicate-code catalogue_category_service.create( - CatalogueCategoryPostRequestSchema( + CatalogueCategoryPostSchema( name=catalogue_category.name, is_leaf=catalogue_category.is_leaf, properties=[prop.model_dump() for prop in catalogue_category.properties], @@ -411,7 +411,7 @@ def test_create_properties_with_non_existent_unit_id( with pytest.raises(MissingRecordError) as exc: catalogue_category_service.create( - CatalogueCategoryPostRequestSchema( + CatalogueCategoryPostSchema( name=catalogue_category.name, is_leaf=catalogue_category.is_leaf, parent_id=catalogue_category.parent_id, @@ -547,7 +547,7 @@ def test_update_when_no_child_elements( test_helpers.mock_update(catalogue_category_repository_mock, catalogue_category) updated_catalogue_category = catalogue_category_service.update( - catalogue_category.id, CatalogueCategoryPatchRequestSchema(name=catalogue_category.name) + catalogue_category.id, CatalogueCategoryPatchSchema(name=catalogue_category.name) ) # pylint: disable=duplicate-code @@ -609,7 +609,7 @@ def test_update_when_has_child_elements( test_helpers.mock_update(catalogue_category_repository_mock, catalogue_category) updated_catalogue_category = catalogue_category_service.update( - catalogue_category.id, CatalogueCategoryPatchRequestSchema(name=catalogue_category.name) + catalogue_category.id, CatalogueCategoryPatchSchema(name=catalogue_category.name) ) # pylint: disable=duplicate-code @@ -640,7 +640,7 @@ def test_update_with_non_existent_id(test_helpers, catalogue_category_repository catalogue_category_id = str(ObjectId()) with pytest.raises(MissingRecordError) as exc: - catalogue_category_service.update(catalogue_category_id, CatalogueCategoryPatchRequestSchema(properties=[])) + catalogue_category_service.update(catalogue_category_id, CatalogueCategoryPatchSchema(properties=[])) catalogue_category_repository_mock.update.assert_not_called() assert str(exc.value) == f"No catalogue category found with ID: {catalogue_category_id}" @@ -702,7 +702,7 @@ def test_update_change_parent_id( test_helpers.mock_update(catalogue_category_repository_mock, catalogue_category) updated_catalogue_category = catalogue_category_service.update( - catalogue_category.id, CatalogueCategoryPatchRequestSchema(parent_id=catalogue_category.parent_id) + catalogue_category.id, CatalogueCategoryPatchSchema(parent_id=catalogue_category.parent_id) ) # pylint: disable=duplicate-code @@ -779,7 +779,7 @@ def test_update_change_parent_id_leaf_parent_catalogue_category( with pytest.raises(LeafCatalogueCategoryError) as exc: catalogue_category_service.update( - catalogue_category_b_id, CatalogueCategoryPatchRequestSchema(parent_id=catalogue_category_a_id) + catalogue_category_b_id, CatalogueCategoryPatchSchema(parent_id=catalogue_category_a_id) ) catalogue_category_repository_mock.update.assert_not_called() assert str(exc.value) == "Cannot add catalogue category to a leaf parent catalogue category" @@ -842,7 +842,7 @@ def test_update_change_from_leaf_to_non_leaf_when_no_child_elements( test_helpers.mock_update(catalogue_category_repository_mock, catalogue_category) updated_catalogue_category = catalogue_category_service.update( - catalogue_category.id, CatalogueCategoryPatchRequestSchema(is_leaf=False) + catalogue_category.id, CatalogueCategoryPatchSchema(is_leaf=False) ) catalogue_category_repository_mock.update.assert_called_once_with( @@ -917,7 +917,7 @@ def test_update_change_properties_when_no_child_elements( updated_catalogue_category = catalogue_category_service.update( catalogue_category.id, - CatalogueCategoryPatchRequestSchema(properties=[prop.model_dump() for prop in catalogue_category.properties]), + CatalogueCategoryPatchSchema(properties=[prop.model_dump() for prop in catalogue_category.properties]), ) # To assert with property ids we must compare as dicts and use ANY here as otherwise the ObjectIds will always @@ -994,7 +994,7 @@ def test_update_change_from_leaf_to_non_leaf_when_has_child_elements( test_helpers.mock_update(catalogue_category_repository_mock, catalogue_category) with pytest.raises(ChildElementsExistError) as exc: - catalogue_category_service.update(catalogue_category.id, CatalogueCategoryPatchRequestSchema(is_leaf=False)) + catalogue_category_service.update(catalogue_category.id, CatalogueCategoryPatchSchema(is_leaf=False)) catalogue_category_repository_mock.update.assert_not_called() assert ( str(exc.value) @@ -1055,9 +1055,7 @@ def test_update_change_properties_when_has_child_elements( with pytest.raises(ChildElementsExistError) as exc: catalogue_category_service.update( catalogue_category.id, - CatalogueCategoryPatchRequestSchema( - properties=[prop.model_dump() for prop in catalogue_category.properties] - ), + CatalogueCategoryPatchSchema(properties=[prop.model_dump() for prop in catalogue_category.properties]), ) catalogue_category_repository_mock.update.assert_not_called() assert ( @@ -1119,9 +1117,7 @@ def test_update_properties_to_have_duplicate_names( with pytest.raises(DuplicateCatalogueCategoryPropertyNameError) as exc: catalogue_category_service.update( catalogue_category.id, - CatalogueCategoryPatchRequestSchema( - properties=[prop.model_dump() for prop in catalogue_category.properties] - ), + CatalogueCategoryPatchSchema(properties=[prop.model_dump() for prop in catalogue_category.properties]), ) catalogue_category_repository_mock.update.assert_not_called() assert str(exc.value) == (f"Duplicate property name: {catalogue_category.properties[0].name}") @@ -1183,9 +1179,7 @@ def test_update_change_properties_with_non_existent_unit_id( with pytest.raises(MissingRecordError) as exc: catalogue_category_service.update( catalogue_category.id, - CatalogueCategoryPatchRequestSchema( - properties=[prop.model_dump() for prop in catalogue_category.properties] - ), + CatalogueCategoryPatchSchema(properties=[prop.model_dump() for prop in catalogue_category.properties]), ) catalogue_category_repository_mock.update.assert_not_called() assert str(exc.value) == (f"No unit found with ID: {unit.id}") diff --git a/test/unit/services/test_catalogue_category_property.py b/test/unit/services/test_catalogue_category_property.py index 475f290c..39892bc6 100644 --- a/test/unit/services/test_catalogue_category_property.py +++ b/test/unit/services/test_catalogue_category_property.py @@ -19,8 +19,8 @@ from inventory_management_system_api.models.catalogue_item import PropertyIn from inventory_management_system_api.models.unit import UnitOut from inventory_management_system_api.schemas.catalogue_category import ( - CatalogueCategoryPropertyPatchRequestSchema, - CatalogueCategoryPropertyPostRequestSchema, + CatalogueCategoryPropertyPatchSchema, + CatalogueCategoryPropertyPostSchema, ) # pylint:disable=too-many-locals @@ -54,7 +54,7 @@ def test_create( """ catalogue_category_id = str(ObjectId()) unit = UnitOut(id=str(ObjectId()), **UNIT_A) - property_post = CatalogueCategoryPropertyPostRequestSchema( + property_post = CatalogueCategoryPropertyPostSchema( name="Property A", type="number", unit_id=unit.id, mandatory=mandatory, default_value=default_value ) stored_catalogue_category = CatalogueCategoryOut( @@ -145,7 +145,7 @@ def test_create_mandatory_property_without_default_value( """ catalogue_category_id = str(ObjectId()) unit = UnitOut(id=str(ObjectId()), **UNIT_A) - property_post = CatalogueCategoryPropertyPostRequestSchema( + property_post = CatalogueCategoryPropertyPostSchema( name="Property A", type="number", unit_id=unit.id, mandatory=True ) stored_catalogue_category = CatalogueCategoryOut( @@ -188,7 +188,7 @@ def test_create_non_existent_unit_id( """ catalogue_category_id = str(ObjectId()) unit_id = str(ObjectId()) - property_post = CatalogueCategoryPropertyPostRequestSchema( + property_post = CatalogueCategoryPropertyPostSchema( name="Property A", type="number", unit_id=unit_id, mandatory=False ) stored_catalogue_category = CatalogueCategoryOut( @@ -234,7 +234,7 @@ def test_create_mandatory_property_with_missing_catalogue_category( """ catalogue_category_id = str(ObjectId()) unit = UnitOut(id=str(ObjectId()), **UNIT_A) - property_post = CatalogueCategoryPropertyPostRequestSchema( + property_post = CatalogueCategoryPropertyPostSchema( name="Property A", type="number", unit_id=unit.id, mandatory=False ) stored_catalogue_category = None @@ -271,7 +271,7 @@ def test_create_mandatory_property_with_non_leaf_catalogue_category( """ catalogue_category_id = str(ObjectId()) unit = UnitOut(id=str(ObjectId()), **UNIT_A) - property_post = CatalogueCategoryPropertyPostRequestSchema( + property_post = CatalogueCategoryPropertyPostSchema( name="Property A", type="number", unit_id=unit.id, mandatory=False ) stored_catalogue_category = CatalogueCategoryOut( @@ -319,7 +319,7 @@ def test_update( """ catalogue_category_id = str(ObjectId()) property_id = str(ObjectId()) - property_patch = CatalogueCategoryPropertyPatchRequestSchema( + property_patch = CatalogueCategoryPropertyPatchSchema( name="Property Name", allowed_values={"type": "list", "values": [100, 500, 1000, 2000]} ) unit = UnitOut(id=str(ObjectId()), **UNIT_A) @@ -389,7 +389,7 @@ def test_update_category_only( """ catalogue_category_id = str(ObjectId()) property_id = str(ObjectId()) - property_patch = CatalogueCategoryPropertyPatchRequestSchema( + property_patch = CatalogueCategoryPropertyPatchSchema( allowed_values={"type": "list", "values": [100, 500, 1000, 2000]} ) unit = UnitOut(id=str(ObjectId()), **UNIT_A) @@ -456,7 +456,7 @@ def test_update_with_no_changes_allowed_values_none( """ catalogue_category_id = str(ObjectId()) property_id = str(ObjectId()) - property_patch = CatalogueCategoryPropertyPatchRequestSchema(allowed_values=None) + property_patch = CatalogueCategoryPropertyPatchSchema(allowed_values=None) unit = UnitOut(id=str(ObjectId()), **UNIT_A) stored_property = CatalogueCategoryPropertyOut( id=property_id, @@ -518,7 +518,7 @@ def test_update_with_missing_catalogue_category( """ catalogue_category_id = str(ObjectId()) property_id = str(ObjectId()) - property_patch = CatalogueCategoryPropertyPatchRequestSchema( + property_patch = CatalogueCategoryPropertyPatchSchema( name="Property Name", allowed_values={"type": "list", "values": [100, 500, 1000, 2000]} ) stored_catalogue_category = None @@ -552,7 +552,7 @@ def test_update_with_missing_property( """ catalogue_category_id = str(ObjectId()) property_id = str(ObjectId()) - property_patch = CatalogueCategoryPropertyPatchRequestSchema( + property_patch = CatalogueCategoryPropertyPatchSchema( name="Property Name", allowed_values={"type": "list", "values": [100, 500, 1000, 2000]} ) # pylint: disable=duplicate-code @@ -607,7 +607,7 @@ def test_update_allowed_values_from_none_to_value( """ catalogue_category_id = str(ObjectId()) property_id = str(ObjectId()) - property_patch = CatalogueCategoryPropertyPatchRequestSchema( + property_patch = CatalogueCategoryPropertyPatchSchema( name="Property Name", allowed_values={"type": "list", "values": [100, 500, 1000, 2000]} ) unit = UnitOut(id=str(ObjectId()), **UNIT_A) @@ -660,7 +660,7 @@ def test_update_allowed_values_from_value_to_none( """ catalogue_category_id = str(ObjectId()) property_id = str(ObjectId()) - property_patch = CatalogueCategoryPropertyPatchRequestSchema(name="Property Name", allowed_values=None) + property_patch = CatalogueCategoryPropertyPatchSchema(name="Property Name", allowed_values=None) unit = UnitOut(id=str(ObjectId()), **UNIT_A) stored_property = CatalogueCategoryPropertyOut( id=property_id, @@ -711,7 +711,7 @@ def test_update_allowed_values_removing_element( """ catalogue_category_id = str(ObjectId()) property_id = str(ObjectId()) - property_patch = CatalogueCategoryPropertyPatchRequestSchema( + property_patch = CatalogueCategoryPropertyPatchSchema( name="Property Name", allowed_values={"type": "list", "values": [100, 500, 1000]} ) unit = UnitOut(id=str(ObjectId()), **UNIT_A) @@ -767,7 +767,7 @@ def test_update_allowed_values_modifying_element( """ catalogue_category_id = str(ObjectId()) property_id = str(ObjectId()) - property_patch = CatalogueCategoryPropertyPatchRequestSchema( + property_patch = CatalogueCategoryPropertyPatchSchema( name="Property Name", allowed_values={"type": "list", "values": [100, 500, 1000, 2000]} ) unit = UnitOut(id=str(ObjectId()), **UNIT_A) @@ -824,7 +824,7 @@ def test_update_adding_allowed_values( """ catalogue_category_id = str(ObjectId()) property_id = str(ObjectId()) - property_patch = CatalogueCategoryPropertyPatchRequestSchema( + property_patch = CatalogueCategoryPropertyPatchSchema( allowed_values={"type": "list", "values": [100, 500, 1000, 2000, 3000, 4000]} ) unit = UnitOut(id=str(ObjectId()), **UNIT_A) diff --git a/test/unit/services/test_catalogue_item.py b/test/unit/services/test_catalogue_item.py index f3a59226..96400fe5 100644 --- a/test/unit/services/test_catalogue_item.py +++ b/test/unit/services/test_catalogue_item.py @@ -22,8 +22,8 @@ from inventory_management_system_api.models.catalogue_item import CatalogueItemIn, CatalogueItemOut from inventory_management_system_api.models.manufacturer import ManufacturerOut from inventory_management_system_api.schemas.catalogue_item import ( - CatalogueItemPatchRequestSchema, - CatalogueItemPostRequestSchema, + CatalogueItemPatchSchema, + CatalogueItemPostSchema, ) FULL_CATALOGUE_CATEGORY_A_INFO = { @@ -161,7 +161,7 @@ def test_create( test_helpers.mock_create(catalogue_item_repository_mock, catalogue_item) created_catalogue_item = catalogue_item_service.create( - CatalogueItemPostRequestSchema( + CatalogueItemPostSchema( catalogue_category_id=catalogue_item.catalogue_category_id, manufacturer_id=catalogue_item.manufacturer_id, **{ @@ -202,7 +202,7 @@ def test_create_with_non_existent_catalogue_category_id( with pytest.raises(MissingRecordError) as exc: catalogue_item_service.create( - CatalogueItemPostRequestSchema( + CatalogueItemPostSchema( catalogue_category_id=catalogue_category_id, manufacturer_id=str(ObjectId()), **{ @@ -252,7 +252,7 @@ def test_create_with_non_existent_manufacturer_id( manufacturer_id = str(ObjectId()) with pytest.raises(MissingRecordError) as exc: catalogue_item_service.create( - CatalogueItemPostRequestSchema( + CatalogueItemPostSchema( catalogue_category_id=catalogue_category_id, manufacturer_id=manufacturer_id, **{ @@ -284,7 +284,7 @@ def test_create_in_non_leaf_catalogue_category( with pytest.raises(NonLeafCatalogueCategoryError) as exc: catalogue_item_service.create( - CatalogueItemPostRequestSchema( + CatalogueItemPostSchema( catalogue_category_id=catalogue_category.id, manufacturer_id=str(ObjectId()), **{ @@ -355,7 +355,7 @@ def test_create_with_obsolete_replacement_catalogue_item_id( test_helpers.mock_create(catalogue_item_repository_mock, catalogue_item) created_catalogue_item = catalogue_item_service.create( - CatalogueItemPostRequestSchema( + CatalogueItemPostSchema( catalogue_category_id=catalogue_item.catalogue_category_id, manufacturer_id=catalogue_item.manufacturer_id, **{ @@ -415,7 +415,7 @@ def test_create_with_non_existent_obsolete_replacement_catalogue_item_id( obsolete_replacement_catalogue_item_id = str(ObjectId()) with pytest.raises(MissingRecordError) as exc: catalogue_item_service.create( - CatalogueItemPostRequestSchema( + CatalogueItemPostSchema( catalogue_category_id=catalogue_category.id, manufacturer_id=str(ObjectId()), **{ @@ -463,7 +463,7 @@ def test_create_without_properties( test_helpers.mock_create(catalogue_item_repository_mock, catalogue_item) created_catalogue_item = catalogue_item_service.create( - CatalogueItemPostRequestSchema( + CatalogueItemPostSchema( catalogue_category_id=catalogue_item.catalogue_category_id, manufacturer_id=catalogue_item.manufacturer_id, **{**CATALOGUE_ITEM_A_INFO, "properties": []}, @@ -507,7 +507,7 @@ def test_create_with_missing_mandatory_properties( with pytest.raises(MissingMandatoryProperty) as exc: catalogue_item_service.create( - CatalogueItemPostRequestSchema( + CatalogueItemPostSchema( catalogue_category_id=catalogue_category.id, manufacturer_id=str(ObjectId()), **{ @@ -552,7 +552,7 @@ def test_create_with_with_invalid_value_type_for_string_property( with pytest.raises(InvalidPropertyTypeError) as exc: catalogue_item_service.create( - CatalogueItemPostRequestSchema( + CatalogueItemPostSchema( catalogue_category_id=catalogue_category.id, manufacturer_id=str(ObjectId()), **{ @@ -599,7 +599,7 @@ def test_create_with_invalid_value_type_for_number_property( with pytest.raises(InvalidPropertyTypeError) as exc: catalogue_item_service.create( - CatalogueItemPostRequestSchema( + CatalogueItemPostSchema( catalogue_category_id=catalogue_category.id, manufacturer_id=str(ObjectId()), **{ @@ -646,7 +646,7 @@ def test_create_with_with_invalid_value_type_for_boolean_property( with pytest.raises(InvalidPropertyTypeError) as exc: catalogue_item_service.create( - CatalogueItemPostRequestSchema( + CatalogueItemPostSchema( catalogue_category_id=catalogue_category.id, manufacturer_id=str(ObjectId()), **{ @@ -776,7 +776,7 @@ def test_update_when_no_child_elements( updated_catalogue_item = catalogue_item_service.update( catalogue_item.id, - CatalogueItemPatchRequestSchema(name=catalogue_item.name, description=catalogue_item.description), + CatalogueItemPatchSchema(name=catalogue_item.name, description=catalogue_item.description), ) catalogue_item_repository_mock.update.assert_called_once_with( @@ -838,7 +838,7 @@ def test_update_when_has_child_elements( updated_catalogue_item = catalogue_item_service.update( catalogue_item.id, - CatalogueItemPatchRequestSchema(name=catalogue_item.name, description=catalogue_item.description), + CatalogueItemPatchSchema(name=catalogue_item.name, description=catalogue_item.description), ) catalogue_item_repository_mock.update.assert_called_once_with( @@ -867,7 +867,7 @@ def test_update_with_non_existent_id(test_helpers, catalogue_item_repository_moc catalogue_item_id = str(ObjectId()) with pytest.raises(MissingRecordError) as exc: - catalogue_item_service.update(catalogue_item_id, CatalogueItemPatchRequestSchema(properties=[])) + catalogue_item_service.update(catalogue_item_id, CatalogueItemPatchSchema(properties=[])) catalogue_item_repository_mock.update.assert_not_called() assert str(exc.value) == f"No catalogue item found with ID: {catalogue_item_id}" @@ -940,7 +940,7 @@ def test_update_change_catalogue_category_id_same_defined_properties_without_sup test_helpers.mock_update(catalogue_item_repository_mock, catalogue_item) updated_catalogue_item = catalogue_item_service.update( - catalogue_item.id, CatalogueItemPatchRequestSchema(catalogue_category_id=catalogue_item.catalogue_category_id) + catalogue_item.id, CatalogueItemPatchSchema(catalogue_category_id=catalogue_item.catalogue_category_id) ) catalogue_item_repository_mock.update.assert_called_once_with( @@ -1027,7 +1027,7 @@ def test_update_change_catalogue_category_id_same_defined_properties_with_suppli updated_catalogue_item = catalogue_item_service.update( catalogue_item.id, - CatalogueItemPatchRequestSchema( + CatalogueItemPatchSchema( catalogue_category_id=catalogue_item.catalogue_category_id, properties=[{"id": prop.id, "value": prop.value} for prop in catalogue_item.properties], ), @@ -1112,7 +1112,7 @@ def test_update_change_catalogue_category_id_different_defined_properties_withou with pytest.raises(InvalidActionError) as exc: catalogue_item_service.update( catalogue_item_id, - CatalogueItemPatchRequestSchema(catalogue_category_id=catalogue_category_id), + CatalogueItemPatchSchema(catalogue_category_id=catalogue_category_id), ) catalogue_item_repository_mock.update.assert_not_called() assert ( @@ -1184,7 +1184,7 @@ def test_update_change_catalogue_category_id_different_defined_properties_order_ with pytest.raises(InvalidActionError) as exc: catalogue_item_service.update( catalogue_item_id, - CatalogueItemPatchRequestSchema(catalogue_category_id=catalogue_category_id), + CatalogueItemPatchSchema(catalogue_category_id=catalogue_category_id), ) catalogue_item_repository_mock.update.assert_not_called() assert ( @@ -1265,7 +1265,7 @@ def test_update_change_catalogue_category_id_different_defined_properties_with_s updated_catalogue_item = catalogue_item_service.update( catalogue_item.id, - CatalogueItemPatchRequestSchema( + CatalogueItemPatchSchema( catalogue_category_id=catalogue_item.catalogue_category_id, properties=[{"id": prop.id, "value": prop.value} for prop in catalogue_item.properties], ), @@ -1316,7 +1316,7 @@ def test_update_with_non_existent_catalogue_category_id( with pytest.raises(MissingRecordError) as exc: catalogue_item_service.update( catalogue_item.id, - CatalogueItemPatchRequestSchema(catalogue_category_id=catalogue_category_id), + CatalogueItemPatchSchema(catalogue_category_id=catalogue_category_id), ) catalogue_item_repository_mock.update.assert_not_called() assert str(exc.value) == f"No catalogue category found with ID: {catalogue_category_id}" @@ -1367,7 +1367,7 @@ def test_update_with_existent_manufacturer_id_when_has_no_child_elements( updated_catalogue_item = catalogue_item_service.update( catalogue_item.id, - CatalogueItemPatchRequestSchema(manufacturer_id=catalogue_item.manufacturer_id), + CatalogueItemPatchSchema(manufacturer_id=catalogue_item.manufacturer_id), ) catalogue_item_repository_mock.update.assert_called_once_with( @@ -1428,7 +1428,7 @@ def test_update_with_existent_manufacturer_id_when_has_child_elements( with pytest.raises(ChildElementsExistError) as exc: catalogue_item_service.update( catalogue_item.id, - CatalogueItemPatchRequestSchema(manufacturer_id=catalogue_item.manufacturer_id), + CatalogueItemPatchSchema(manufacturer_id=catalogue_item.manufacturer_id), ) catalogue_item_repository_mock.update.assert_not_called() assert str(exc.value) == f"Catalogue item with ID {catalogue_item.id} has child elements and cannot be updated" @@ -1464,7 +1464,7 @@ def test_update_with_non_existent_manufacturer_id( with pytest.raises(MissingRecordError) as exc: catalogue_item_service.update( catalogue_item.id, - CatalogueItemPatchRequestSchema(manufacturer_id=manufacturer_id), + CatalogueItemPatchSchema(manufacturer_id=manufacturer_id), ) catalogue_item_repository_mock.update.assert_not_called() assert str(exc.value) == f"No manufacturer found with ID: {manufacturer_id}" @@ -1503,7 +1503,7 @@ def test_update_change_catalogue_category_id_non_leaf_catalogue_category( with pytest.raises(NonLeafCatalogueCategoryError) as exc: catalogue_item_service.update( catalogue_item.id, - CatalogueItemPatchRequestSchema(catalogue_category_id=catalogue_category_id), + CatalogueItemPatchSchema(catalogue_category_id=catalogue_category_id), ) catalogue_item_repository_mock.update.assert_not_called() assert str(exc.value) == "Cannot add catalogue item to a non-leaf catalogue category" @@ -1570,7 +1570,7 @@ def test_update_with_obsolete_replacement_catalogue_item_id( updated_catalogue_item = catalogue_item_service.update( catalogue_item.id, - CatalogueItemPatchRequestSchema( + CatalogueItemPatchSchema( is_obsolete=True, obsolete_replacement_catalogue_item_id=obsolete_replacement_catalogue_item_id ), ) @@ -1619,7 +1619,7 @@ def test_update_with_non_existent_obsolete_replacement_catalogue_item_id( with pytest.raises(MissingRecordError) as exc: catalogue_item_service.update( catalogue_item.id, - CatalogueItemPatchRequestSchema( + CatalogueItemPatchSchema( is_obsolete=True, obsolete_replacement_catalogue_item_id=obsolete_replacement_catalogue_item_id ), ) @@ -1687,7 +1687,7 @@ def test_update_add_non_mandatory_property( updated_catalogue_item = catalogue_item_service.update( catalogue_item.id, - CatalogueItemPatchRequestSchema( + CatalogueItemPatchSchema( properties=[{"id": prop.id, "value": prop.value} for prop in catalogue_item.properties] ), ) @@ -1763,7 +1763,7 @@ def test_update_remove_non_mandatory_property( updated_catalogue_item = catalogue_item_service.update( catalogue_item.id, - CatalogueItemPatchRequestSchema( + CatalogueItemPatchSchema( properties=[{"id": prop.id, "value": prop.value} for prop in catalogue_item.properties[-2:]] ), ) @@ -1828,7 +1828,7 @@ def test_update_remove_mandatory_property( with pytest.raises(MissingMandatoryProperty) as exc: catalogue_item_service.update( catalogue_item.id, - CatalogueItemPatchRequestSchema( + CatalogueItemPatchSchema( properties=[{"id": prop.id, "value": prop.value} for prop in catalogue_item.properties[:2]] ), ) @@ -1894,7 +1894,7 @@ def test_update_change_property_value( updated_catalogue_item = catalogue_item_service.update( catalogue_item.id, - CatalogueItemPatchRequestSchema( + CatalogueItemPatchSchema( properties=[{"id": prop.id, "value": prop.value} for prop in catalogue_item.properties] ), ) @@ -1958,7 +1958,7 @@ def test_update_change_value_for_string_property_invalid_type( with pytest.raises(InvalidPropertyTypeError) as exc: catalogue_item_service.update( catalogue_item.id, - CatalogueItemPatchRequestSchema(properties=properties), + CatalogueItemPatchSchema(properties=properties), ) catalogue_item_repository_mock.update.assert_not_called() assert ( @@ -2011,7 +2011,7 @@ def test_update_change_value_for_number_property_invalid_type( with pytest.raises(InvalidPropertyTypeError) as exc: catalogue_item_service.update( catalogue_item.id, - CatalogueItemPatchRequestSchema(properties=properties), + CatalogueItemPatchSchema(properties=properties), ) catalogue_item_repository_mock.update.assert_not_called() assert ( @@ -2064,7 +2064,7 @@ def test_update_change_value_for_boolean_property_invalid_type( with pytest.raises(InvalidPropertyTypeError) as exc: catalogue_item_service.update( catalogue_item.id, - CatalogueItemPatchRequestSchema(properties=properties), + CatalogueItemPatchSchema(properties=properties), ) catalogue_item_repository_mock.update.assert_not_called() assert ( @@ -2104,7 +2104,7 @@ def test_update_properties_when_has_child_elements( with pytest.raises(ChildElementsExistError) as exc: catalogue_item_service.update( catalogue_item.id, - CatalogueItemPatchRequestSchema(properties=[]), + CatalogueItemPatchSchema(properties=[]), ) catalogue_item_repository_mock.update.assert_not_called() assert str(exc.value) == f"Catalogue item with ID {catalogue_item.id} has child elements and cannot be updated" diff --git a/test/unit/services/test_item.py b/test/unit/services/test_item.py index 1ded711a..d2e658d3 100644 --- a/test/unit/services/test_item.py +++ b/test/unit/services/test_item.py @@ -23,7 +23,7 @@ from inventory_management_system_api.models.item import ItemIn, ItemOut from inventory_management_system_api.models.system import SystemOut from inventory_management_system_api.models.usage_status import UsageStatusOut -from inventory_management_system_api.schemas.item import ItemPatchRequestSchema, ItemPostRequestSchema +from inventory_management_system_api.schemas.item import ItemPatchSchema, ItemPostSchema # pylint: disable=duplicate-code FULL_CATALOGUE_CATEGORY_A_INFO = { @@ -180,7 +180,7 @@ def test_create( ) created_item = item_service.create( - ItemPostRequestSchema( + ItemPostSchema( catalogue_item_id=item.catalogue_item_id, system_id=item.system_id, usage_status_id=item.usage_status_id, @@ -221,7 +221,7 @@ def test_create_with_non_existent_catalogue_item_id( with pytest.raises(MissingRecordError) as exc: item_service.create( - ItemPostRequestSchema( + ItemPostSchema( catalogue_item_id=catalogue_item_id, usage_status_id=str(ObjectId()), system_id=str(ObjectId()), @@ -249,7 +249,7 @@ def test_create_with_non_existent_usage_status_id( with pytest.raises(MissingRecordError) as exc: item_service.create( - ItemPostRequestSchema( + ItemPostSchema( catalogue_item_id=str(ObjectId()), usage_status_id=usage_status_id, system_id=str(ObjectId()), @@ -277,7 +277,7 @@ def test_create_with_invalid_usage_status_id( with pytest.raises(MissingRecordError) as exc: item_service.create( - ItemPostRequestSchema( + ItemPostSchema( catalogue_item_id=str(ObjectId()), usage_status_id=usage_status_id, system_id=str(ObjectId()), @@ -328,7 +328,7 @@ def test_create_with_invalid_catalogue_category_id( with pytest.raises(DatabaseIntegrityError) as exc: item_service.create( - ItemPostRequestSchema( + ItemPostSchema( catalogue_item_id=catalogue_item_id, system_id=str(ObjectId()), usage_status_id=str(ObjectId()), @@ -377,7 +377,7 @@ def test_create_with_non_existent_catalogue_category_id_in_catalogue_item( with pytest.raises(DatabaseIntegrityError) as exc: item_service.create( - ItemPostRequestSchema( + ItemPostSchema( catalogue_item_id=catalogue_item_id, system_id=str(ObjectId()), usage_status_id=str(ObjectId()), @@ -460,7 +460,7 @@ def test_create_without_properties( "usage_status_id": item.usage_status_id, } del item_post["properties"] - created_item = item_service.create(ItemPostRequestSchema(**item_post)) + created_item = item_service.create(ItemPostSchema(**item_post)) catalogue_item_repository_mock.get.assert_called_once_with(item.catalogue_item_id) catalogue_category_repository_mock.get.assert_called_once_with(catalogue_category_id) @@ -596,7 +596,7 @@ def test_update( ) updated_item = item_service.update( item.id, - ItemPatchRequestSchema(is_defective=item.is_defective, usage_status_id=item.usage_status_id), + ItemPatchSchema(is_defective=item.is_defective, usage_status_id=item.usage_status_id), ) item_repository_mock.update.assert_called_once_with( @@ -627,7 +627,7 @@ def test_update_with_non_existent_id(test_helpers, item_repository_mock, item_se item_id = str(ObjectId()) with pytest.raises(MissingRecordError) as exc: - item_service.update(item_id, ItemPatchRequestSchema(properties=[])) + item_service.update(item_id, ItemPatchSchema(properties=[])) item_repository_mock.update.assert_not_called() assert str(exc.value) == f"No item found with ID: {item_id}" @@ -667,7 +667,7 @@ def test_update_change_catalogue_item_id(test_helpers, item_repository_mock, ite with pytest.raises(InvalidActionError) as exc: item_service.update( item.id, - ItemPatchRequestSchema(catalogue_item_id=catalogue_item_id), + ItemPatchSchema(catalogue_item_id=catalogue_item_id), ) item_repository_mock.update.assert_not_called() assert str(exc.value) == "Cannot change the catalogue item the item belongs to" @@ -734,7 +734,7 @@ def test_update_change_system_id( updated_item = item_service.update( item.id, - ItemPatchRequestSchema(system_id=item.system_id), + ItemPatchSchema(system_id=item.system_id), ) item_repository_mock.update.assert_called_once_with( @@ -792,7 +792,7 @@ def test_update_with_non_existent_system_id(test_helpers, system_repository_mock with pytest.raises(MissingRecordError) as exc: item_service.update( item.id, - ItemPatchRequestSchema(system_id=system_id), + ItemPatchSchema(system_id=system_id), ) item_repository_mock.update.assert_not_called() assert str(exc.value) == f"No system found with ID: {system_id}" @@ -838,7 +838,7 @@ def test_update_with_non_existent_usage_status( with pytest.raises(MissingRecordError) as exc: item_service.update( item.id, - ItemPatchRequestSchema(usage_status_id=usage_status_id), + ItemPatchSchema(usage_status_id=usage_status_id), ) item_repository_mock.update.assert_not_called() assert str(exc.value) == f"No usage status found with ID: {usage_status_id}" @@ -884,7 +884,7 @@ def test_update_with_invalid_usage_status( with pytest.raises(MissingRecordError) as exc: item_service.update( item.id, - ItemPatchRequestSchema(usage_status_id=usage_status_id), + ItemPatchSchema(usage_status_id=usage_status_id), ) item_repository_mock.update.assert_not_called() assert str(exc.value) == f"No usage status found with ID: {usage_status_id}" @@ -971,7 +971,7 @@ def test_update_change_property_value( updated_item = item_service.update( item.id, - ItemPatchRequestSchema(properties=[{"id": prop.id, "value": prop.value} for prop in item.properties]), + ItemPatchSchema(properties=[{"id": prop.id, "value": prop.value} for prop in item.properties]), ) item_repository_mock.update.assert_called_once_with( @@ -1072,7 +1072,7 @@ def test_update_with_missing_existing_properties( updated_item = item_service.update( item.id, - ItemPatchRequestSchema(properties=[{"id": prop.id, "value": prop.value} for prop in item.properties[-2:]]), + ItemPatchSchema(properties=[{"id": prop.id, "value": prop.value} for prop in item.properties[-2:]]), ) item_repository_mock.update.assert_called_once_with( @@ -1156,7 +1156,7 @@ def test_update_change_value_for_string_property_invalid_type( with pytest.raises(InvalidPropertyTypeError) as exc: item_service.update( item.id, - ItemPatchRequestSchema(properties=properties), + ItemPatchSchema(properties=properties), ) item_repository_mock.update.assert_not_called() assert ( @@ -1228,7 +1228,7 @@ def test_update_change_value_for_number_property_invalid_type( with pytest.raises(InvalidPropertyTypeError) as exc: item_service.update( item.id, - ItemPatchRequestSchema(properties=properties), + ItemPatchSchema(properties=properties), ) item_repository_mock.update.assert_not_called() assert ( @@ -1298,7 +1298,7 @@ def test_update_change_value_for_boolean_property_invalid_type( with pytest.raises(InvalidPropertyTypeError) as exc: item_service.update( item.id, - ItemPatchRequestSchema(properties=properties), + ItemPatchSchema(properties=properties), ) item_repository_mock.update.assert_not_called() assert ( diff --git a/test/unit/services/test_manufacturer.py b/test/unit/services/test_manufacturer.py index fd059339..ecbba6d7 100644 --- a/test/unit/services/test_manufacturer.py +++ b/test/unit/services/test_manufacturer.py @@ -13,8 +13,8 @@ from inventory_management_system_api.models.manufacturer import ManufacturerIn, ManufacturerOut from inventory_management_system_api.schemas.manufacturer import ( AddressSchema, - ManufacturerPatchRequestSchema, - ManufacturerPostRequestSchema, + ManufacturerPatchSchema, + ManufacturerPostSchema, ) @@ -51,7 +51,7 @@ def test_create( test_helpers.mock_create(manufacturer_repository_mock, manufacturer) created_manufacturer = manufacturer_service.create( - ManufacturerPostRequestSchema( + ManufacturerPostSchema( name=manufacturer.name, url=manufacturer.url, address=manufacturer.address, @@ -183,7 +183,7 @@ def test_partial_update_of_address( updated_manufacturer = manufacturer_service.update( manufacturer.id, - ManufacturerPatchRequestSchema(address={"address_line": "test"}), + ManufacturerPatchSchema(address={"address_line": "test"}), ) manufacturer_repository_mock.update.assert_called_once_with( @@ -230,7 +230,7 @@ def test_partial_update_of_manufacturer( # Mock `get` to return the updated manufacturer test_helpers.mock_update(manufacturer_repository_mock, manufacturer) - updated_manufacturer = manufacturer_service.update(manufacturer.id, ManufacturerPatchRequestSchema(name="test")) + updated_manufacturer = manufacturer_service.update(manufacturer.id, ManufacturerPatchSchema(name="test")) manufacturer_repository_mock.update.assert_called_once_with( manufacturer.id, ManufacturerIn(**full_manufacturer_info) diff --git a/test/unit/services/test_unit.py b/test/unit/services/test_unit.py index 29b28e4d..11b9c5b1 100644 --- a/test/unit/services/test_unit.py +++ b/test/unit/services/test_unit.py @@ -8,7 +8,7 @@ from bson import ObjectId from inventory_management_system_api.models.unit import UnitIn, UnitOut -from inventory_management_system_api.schemas.unit import UnitPostRequestSchema +from inventory_management_system_api.schemas.unit import UnitPostSchema def test_create( @@ -36,7 +36,7 @@ def test_create( test_helpers.mock_create(unit_repository_mock, unit) created_unit = unit_service.create( - UnitPostRequestSchema( + UnitPostSchema( value=unit.value, ) ) diff --git a/test/unit/services/test_usage_status.py b/test/unit/services/test_usage_status.py index c5954b99..98fdcb7c 100644 --- a/test/unit/services/test_usage_status.py +++ b/test/unit/services/test_usage_status.py @@ -8,7 +8,7 @@ from bson import ObjectId from inventory_management_system_api.models.usage_status import UsageStatusIn, UsageStatusOut -from inventory_management_system_api.schemas.usage_status import UsageStatusPostRequestSchema +from inventory_management_system_api.schemas.usage_status import UsageStatusPostSchema def test_create( @@ -35,7 +35,7 @@ def test_create( test_helpers.mock_create(usage_status_repository_mock, usage_status) created_usage_status = usage_status_service.create( - UsageStatusPostRequestSchema( + UsageStatusPostSchema( value=usage_status.value, ) ) diff --git a/test/unit/services/test_utils.py b/test/unit/services/test_utils.py index ad092bac..6ac9acca 100644 --- a/test/unit/services/test_utils.py +++ b/test/unit/services/test_utils.py @@ -11,7 +11,7 @@ MissingMandatoryProperty, ) from inventory_management_system_api.models.catalogue_category import AllowedValues, CatalogueCategoryPropertyOut -from inventory_management_system_api.schemas.catalogue_item import PropertyPostRequestSchema +from inventory_management_system_api.schemas.catalogue_item import PropertyPostSchema from inventory_management_system_api.services import utils DEFINED_PROPERTIES = [ @@ -41,17 +41,13 @@ ] SUPPLIED_PROPERTIES = [ - PropertyPostRequestSchema( - id=DEFINED_PROPERTIES[0].id, name="Property A", value=20, unit_id=DEFINED_PROPERTIES[0].unit_id - ), - PropertyPostRequestSchema(id=DEFINED_PROPERTIES[1].id, name="Property B", value=False), - PropertyPostRequestSchema( + PropertyPostSchema(id=DEFINED_PROPERTIES[0].id, name="Property A", value=20, unit_id=DEFINED_PROPERTIES[0].unit_id), + PropertyPostSchema(id=DEFINED_PROPERTIES[1].id, name="Property B", value=False), + PropertyPostSchema( id=DEFINED_PROPERTIES[2].id, name="Property C", value="20x15x10", unit_id=DEFINED_PROPERTIES[2].unit_id ), - PropertyPostRequestSchema( - id=DEFINED_PROPERTIES[3].id, name="Property D", value=2, unit_id=DEFINED_PROPERTIES[3].unit_id - ), - PropertyPostRequestSchema(id=DEFINED_PROPERTIES[4].id, name="Property E", value="red"), + PropertyPostSchema(id=DEFINED_PROPERTIES[3].id, name="Property D", value=2, unit_id=DEFINED_PROPERTIES[3].unit_id), + PropertyPostSchema(id=DEFINED_PROPERTIES[4].id, name="Property E", value="red"), ] EXPECTED_PROCESSED_PROPERTIES = [ @@ -144,9 +140,7 @@ def test_process_properties_with_undefined_properties(self): """ Test `process_properties` works correctly with supplied properties that have not been defined. """ - supplied_properties = SUPPLIED_PROPERTIES + [ - PropertyPostRequestSchema(id=str(ObjectId()), name="Property F", value=1) - ] + supplied_properties = SUPPLIED_PROPERTIES + [PropertyPostSchema(id=str(ObjectId()), name="Property F", value=1)] result = utils.process_properties(DEFINED_PROPERTIES, supplied_properties) assert result == EXPECTED_PROCESSED_PROPERTIES @@ -158,20 +152,20 @@ def test_process_properties_with_none_non_mandatory_properties(self): result = utils.process_properties( DEFINED_PROPERTIES, [ - PropertyPostRequestSchema( + PropertyPostSchema( id=DEFINED_PROPERTIES[0].id, name="Property A", value=None, unit_id=DEFINED_PROPERTIES[0].unit_id ), - PropertyPostRequestSchema(id=DEFINED_PROPERTIES[1].id, name="Property B", value=False), - PropertyPostRequestSchema( + PropertyPostSchema(id=DEFINED_PROPERTIES[1].id, name="Property B", value=False), + PropertyPostSchema( id=DEFINED_PROPERTIES[2].id, name="Property C", value="20x15x10", unit_id=DEFINED_PROPERTIES[2].unit_id, ), - PropertyPostRequestSchema( + PropertyPostSchema( id=DEFINED_PROPERTIES[3].id, name="Property D", value=2, unit_id=DEFINED_PROPERTIES[3].unit_id ), - PropertyPostRequestSchema(id=DEFINED_PROPERTIES[4].id, name="Property E", value=None), + PropertyPostSchema(id=DEFINED_PROPERTIES[4].id, name="Property E", value=None), ], ) assert result == [ @@ -220,11 +214,11 @@ def test_process_properties_with_invalid_value_type_for_string_property(self): property. """ supplied_properties = [ - PropertyPostRequestSchema(id=DEFINED_PROPERTIES[0].id, name="Property A", value=20), - PropertyPostRequestSchema(id=DEFINED_PROPERTIES[1].id, name="Property B", value=False), - PropertyPostRequestSchema(id=DEFINED_PROPERTIES[2].id, name="Property C", value=True), - PropertyPostRequestSchema(id=DEFINED_PROPERTIES[3].id, name="Property D", value=2), - PropertyPostRequestSchema(id=DEFINED_PROPERTIES[4].id, name="Property E", value="red"), + PropertyPostSchema(id=DEFINED_PROPERTIES[0].id, name="Property A", value=20), + PropertyPostSchema(id=DEFINED_PROPERTIES[1].id, name="Property B", value=False), + PropertyPostSchema(id=DEFINED_PROPERTIES[2].id, name="Property C", value=True), + PropertyPostSchema(id=DEFINED_PROPERTIES[3].id, name="Property D", value=2), + PropertyPostSchema(id=DEFINED_PROPERTIES[4].id, name="Property E", value="red"), ] with pytest.raises(InvalidPropertyTypeError) as exc: @@ -240,11 +234,11 @@ def test_process_properties_with_invalid_value_type_for_number_property(self): property. """ supplied_properties = [ - PropertyPostRequestSchema(id=DEFINED_PROPERTIES[0].id, name="Property A", value="20"), - PropertyPostRequestSchema(id=DEFINED_PROPERTIES[1].id, name="Property B", value=False), - PropertyPostRequestSchema(id=DEFINED_PROPERTIES[2].id, name="Property C", value="20x15x10"), - PropertyPostRequestSchema(id=DEFINED_PROPERTIES[3].id, name="Property D", value=2), - PropertyPostRequestSchema(id=DEFINED_PROPERTIES[4].id, name="Property E", value="red"), + PropertyPostSchema(id=DEFINED_PROPERTIES[0].id, name="Property A", value="20"), + PropertyPostSchema(id=DEFINED_PROPERTIES[1].id, name="Property B", value=False), + PropertyPostSchema(id=DEFINED_PROPERTIES[2].id, name="Property C", value="20x15x10"), + PropertyPostSchema(id=DEFINED_PROPERTIES[3].id, name="Property D", value=2), + PropertyPostSchema(id=DEFINED_PROPERTIES[4].id, name="Property E", value="red"), ] with pytest.raises(InvalidPropertyTypeError) as exc: @@ -260,11 +254,11 @@ def test_process_properties_with_invalid_value_type_for_boolean_property(self): property. """ supplied_properties = [ - PropertyPostRequestSchema(id=DEFINED_PROPERTIES[0].id, name="Property A", value=20), - PropertyPostRequestSchema(id=DEFINED_PROPERTIES[1].id, name="Property B", value="False"), - PropertyPostRequestSchema(id=DEFINED_PROPERTIES[2].id, name="Property C", value="20x15x10"), - PropertyPostRequestSchema(id=DEFINED_PROPERTIES[3].id, name="Property D", value=2), - PropertyPostRequestSchema(id=DEFINED_PROPERTIES[4].id, name="Property E", value="red"), + PropertyPostSchema(id=DEFINED_PROPERTIES[0].id, name="Property A", value=20), + PropertyPostSchema(id=DEFINED_PROPERTIES[1].id, name="Property B", value="False"), + PropertyPostSchema(id=DEFINED_PROPERTIES[2].id, name="Property C", value="20x15x10"), + PropertyPostSchema(id=DEFINED_PROPERTIES[3].id, name="Property D", value=2), + PropertyPostSchema(id=DEFINED_PROPERTIES[4].id, name="Property E", value="red"), ] with pytest.raises(InvalidPropertyTypeError) as exc: @@ -279,11 +273,11 @@ def test_process_properties_with_invalid_value_type_for_mandatory_property(self) Test `process_properties` works correctly with a None value given for a mandatory property. """ supplied_properties = [ - PropertyPostRequestSchema(id=DEFINED_PROPERTIES[0].id, name="Property A", value=20), - PropertyPostRequestSchema(id=DEFINED_PROPERTIES[1].id, name="Property B", value=False), - PropertyPostRequestSchema(id=DEFINED_PROPERTIES[2].id, name="Property C", value=None), - PropertyPostRequestSchema(id=DEFINED_PROPERTIES[3].id, name="Property D", value=2), - PropertyPostRequestSchema(id=DEFINED_PROPERTIES[4].id, name="Property E", value="red"), + PropertyPostSchema(id=DEFINED_PROPERTIES[0].id, name="Property A", value=20), + PropertyPostSchema(id=DEFINED_PROPERTIES[1].id, name="Property B", value=False), + PropertyPostSchema(id=DEFINED_PROPERTIES[2].id, name="Property C", value=None), + PropertyPostSchema(id=DEFINED_PROPERTIES[3].id, name="Property D", value=2), + PropertyPostSchema(id=DEFINED_PROPERTIES[4].id, name="Property E", value="red"), ] with pytest.raises(InvalidPropertyTypeError) as exc: @@ -297,11 +291,11 @@ def test_process_properties_with_invalid_allowed_value_list_number(self): of allowed values """ supplied_properties = [ - PropertyPostRequestSchema(id=DEFINED_PROPERTIES[0].id, name="Property A", value=20), - PropertyPostRequestSchema(id=DEFINED_PROPERTIES[1].id, name="Property B", value=False), - PropertyPostRequestSchema(id=DEFINED_PROPERTIES[2].id, name="Property C", value="20x15x10"), - PropertyPostRequestSchema(id=DEFINED_PROPERTIES[3].id, name="Property D", value=10), - PropertyPostRequestSchema(id=DEFINED_PROPERTIES[4].id, name="Property E", value="red"), + PropertyPostSchema(id=DEFINED_PROPERTIES[0].id, name="Property A", value=20), + PropertyPostSchema(id=DEFINED_PROPERTIES[1].id, name="Property B", value=False), + PropertyPostSchema(id=DEFINED_PROPERTIES[2].id, name="Property C", value="20x15x10"), + PropertyPostSchema(id=DEFINED_PROPERTIES[3].id, name="Property D", value=10), + PropertyPostSchema(id=DEFINED_PROPERTIES[4].id, name="Property E", value="red"), ] with pytest.raises(InvalidPropertyTypeError) as exc: @@ -317,11 +311,11 @@ def test_process_properties_with_invalid_allowed_value_list_string(self): list of allowed values """ supplied_properties = [ - PropertyPostRequestSchema(id=DEFINED_PROPERTIES[0].id, name="Property A", value=20), - PropertyPostRequestSchema(id=DEFINED_PROPERTIES[1].id, name="Property B", value=False), - PropertyPostRequestSchema(id=DEFINED_PROPERTIES[2].id, name="Property C", value="20x15x10"), - PropertyPostRequestSchema(id=DEFINED_PROPERTIES[3].id, name="Property D", value=4), - PropertyPostRequestSchema(id=DEFINED_PROPERTIES[4].id, name="Property E", value="invalid"), + PropertyPostSchema(id=DEFINED_PROPERTIES[0].id, name="Property A", value=20), + PropertyPostSchema(id=DEFINED_PROPERTIES[1].id, name="Property B", value=False), + PropertyPostSchema(id=DEFINED_PROPERTIES[2].id, name="Property C", value="20x15x10"), + PropertyPostSchema(id=DEFINED_PROPERTIES[3].id, name="Property D", value=4), + PropertyPostSchema(id=DEFINED_PROPERTIES[4].id, name="Property E", value="invalid"), ] with pytest.raises(InvalidPropertyTypeError) as exc: