Beispiel #1
0
 def export_items_by_id(self, product_id: str, count: int = 1) -> None:
     """
     Exports Items from the inventory by product id.
     """
     CheckInput.check_type(product_id, str)
     item = self.get_item_by_product_id(product_id)
     self.export_items(item, count)
 def create_item(self, inventory_type: InventoryEnum, **product_details) -> Item:
     """
     Constructs an item based on the inventory type.
     """
     CheckInput.check_type(inventory_type, InventoryEnum)
     if inventory_type == InventoryEnum.TOY:
         return self.create_toy(**product_details)
     if inventory_type == InventoryEnum.STUFFED_ANIMAL:
         return self.create_stuffed_animal(**product_details)
     return self.create_candy(**product_details)
Beispiel #3
0
 def _check_input(self, rooms_number: int, dimensions: float, min_age: int,
                  has_batteries: bool, name: str, description: str,
                  product_id: str) -> None:
     """
     Checks input.
     """
     CheckInput.check_all_input_type([rooms_number, min_age], int)
     CheckInput.check_type(dimensions, int, float)
     CheckInput.check_type(has_batteries, bool)
     CheckInput.check_all_input_value_is_lower_equal_than_threshold(
         [rooms_number, dimensions, min_age], 0)
     CheckInput.check_all_input_type([description, product_id, name], str)
Beispiel #4
0
    def check_if_item_enough(self, product_id: str, count: int) -> bool:
        """
        Checks if the inventory has enough stock for exporting this item.

        :return: True if it has enough items, False if not
        """
        CheckInput.check_type(product_id, str)
        CheckInput.check_type(count, int)
        CheckInput.check_value_is_lower_equal_than_threshold(count, 0)
        item = self.get_item_by_product_id(product_id)
        if item is None:
            return False
        return self._items[item] >= count
Beispiel #5
0
 def _check_input(self, speed: float, jump_height: float,
                  is_grow_in_dark: bool, spider_type: SpiderType,
                  min_age: int, has_batteries: bool, name: str,
                  description: str, product_id: str) -> None:
     """
     Checks input.
     """
     CheckInput.check_all_input_type([speed, jump_height, min_age], int,
                                     float)
     CheckInput.check_type(spider_type, SpiderType)
     CheckInput.check_all_input_type([is_grow_in_dark, has_batteries], bool)
     CheckInput.check_all_input_type([name, description, product_id], str)
     CheckInput.check_all_input_value_is_lower_equal_than_threshold(
         [speed, jump_height, min_age], 0)
Beispiel #6
0
 def _check_input(self, size: Size, stuffing: Stuffing, fabric: Fabric,
                  has_glow: bool, name: str, description: str,
                  product_id: str) -> None:
     CheckInput.check_type(size, Size)
     CheckInput.check_type(stuffing, Stuffing)
     CheckInput.check_type(fabric, Fabric)
     CheckInput.check_type(has_glow, bool)
     CheckInput.check_all_input_type([name, description, product_id], str)
Beispiel #7
0
 def _check_input(self, colour: Colours, size: Size, stuffing: Stuffing,
                  fabric: Fabric, name: str, description: str,
                  product_id: str) -> None:
     CheckInput.check_type(colour, Colours)
     CheckInput.check_type(stuffing, Stuffing)
     CheckInput.check_type(fabric, Fabric)
     CheckInput.check_type(size, Size)
     CheckInput.check_all_input_type([name, description, product_id], str)
Beispiel #8
0
    def export_items(self, item: Item, count: int = 1) -> None:
        """
        Exports Items from the inventory.

        :param item: Item
        :param count: the number of item, default is 1
        """
        CheckInput.check_type(item, Item)
        CheckInput.check_type(count, int)
        CheckInput.check_value_is_lower_equal_than_threshold(count, 0)
        if item not in self._items.keys():
            raise KeyError(item, "Inventory doesn't have this item")
        if self._items[item] < count:
            raise ValueError("The Inventory doesn't have enough stock for %s" %
                             item)
        self._items[item] -= count
Beispiel #9
0
    def import_items(self, item: Item, count: int = 100) -> None:
        """
        Add Items stock. If the item already existed in the inventory, increase the count.
        Else put the item into inventory.

        :param item: Item
        :param count: the number of item, default is 1
        """
        CheckInput.check_type(item, Item)
        CheckInput.check_type(count, int)
        CheckInput.check_value_is_lower_equal_than_threshold(count, 0)
        if count < 100:
            count = 100
        if item in self._items.keys():
            self._items[item] += count
            return None
        self._items[item] = count
Beispiel #10
0
 def _check_input(self, sound_effects_number: int, colour: Colours,
                  has_batteries: bool, name: str, description: str,
                  product_id: str) -> None:
     CheckInput.check_type(sound_effects_number, int)
     CheckInput.check_type(colour, Colours)
     CheckInput.check_type(has_batteries, bool)
     CheckInput.check_all_input_type([name, description, product_id], str)
     CheckInput.check_value_is_lower_equal_than_threshold(
         sound_effects_number, 0)
Beispiel #11
0
 def _check_input_type(
         order_number: int,
         product_id: str,
         name: str,
         quantity: int,
         item_type: InventoryEnum,
         product_details: dict,
         factory: FestiveSeasonFactory) -> None:
     """
     Checks if all inputs are valid.
     """
     CheckInput.check_all_input_type([product_id, name], str)
     CheckInput.check_all_input_type([order_number, quantity], int)
     CheckInput.check_type(item_type, InventoryEnum)
     CheckInput.check_type(product_details, dict)
     CheckInput.check_type(factory, FestiveSeasonFactory)
 def _check_input(self, contains_nuts: bool, variety: ToffeeVariety,
                  has_lactose: bool, name: str, description: str,
                  product_id: str) -> None:
     CheckInput.check_all_input_type([contains_nuts, has_lactose], bool)
     CheckInput.check_type(variety, ToffeeVariety)
     CheckInput.check_all_input_type([name, description, product_id], str)
Beispiel #13
0
 def _check_input(self, has_nut: bool, has_lactose: bool, pack_size: int,
                  name: str, description: str, product_id: str) -> None:
     CheckInput.check_type(pack_size, int)
     CheckInput.check_value_is_lower_equal_than_threshold(pack_size, 0)
     CheckInput.check_all_input_type([has_nut, has_lactose], bool)
     CheckInput.check_all_input_type([name, description, product_id], str)
Beispiel #14
0
 def _check_input(self, stripes_colour, has_nuts: bool, has_lactose: bool,
                  name: str, description: str, product_id: str) -> None:
     CheckInput.check_type(stripes_colour, Colours)
     CheckInput.check_all_input_type([name, description, product_id], str)
     CheckInput.check_all_input_type([has_lactose, has_nuts], bool)