def test_add_raises_duplicated_id_exception(self):
     item = Item(1, "chair", "made of wood", 23, "room")
     self.repository.add(item)
     self.assertTrue(self.repository.exists(1))
     item_one = Item(1, "table", "made of steel", 34, "roof")
     self.repository.add(item_one)
     self.assertEqual(item, self.repository.find_by_id(1))
예제 #2
0
 def setUp(self) -> None:
     self.repository = ItemRepository()
     self.remover = ItemRemover(self.repository, ItemValidator(self.repository))
     item = Item(1, "chair", "made of wood", 23, "room")
     self.repository.add(item)
     item_one = Item(2, "chair", "made of wood", 23, "room")
     self.repository.add(item_one)
예제 #3
0
 def validate(self, item: Item):
     if not isinstance(item.get_id(), int):
         raise InvalidItemException("ID '{}' is not int".format(
             item.get_id()))
     if not isinstance(item.get_price(), int):
         raise InvalidItemException("name '{}' is not int".format(
             item.get_price()))
     if item.get_description() == "":
         raise InvalidItemException("Description must not be null")
     if item.get_name() == "":
         raise InvalidItemException("Name must not be null")
예제 #4
0
 def test_items_with_same_data_different_id_not_equal(self):
     item_one = Item(1, "chair", "made of wood", 23, "room")
     item_two = Item(2, "chair", "made of wood", 23, "room")
     self.assertNotEqual(item_one, item_two)
예제 #5
0
 def test_equal(self):
     item_one = Item(1, "chair", "made of wood", 23, "room")
     item_two = Item(1, "chair", "made of wood", 23, "room")
     self.assertEqual(item_one, item_two)
예제 #6
0
 def test_validate_id_raises_exception(self):
     item = Item("a", "chair", "made", 23, "home")
     validator = ItemValidator(ItemRepository())
     self.assertRaises(InvalidItemException,
                       lambda: validator.validate(item))
예제 #7
0
 def test_validate_name_not_null(self):
     item = Item(1, "", "made", 23, "home")
     validator = ItemValidator(ItemRepository())
     self.assertRaises(InvalidItemException,
                       lambda: validator.validate(item))
예제 #8
0
 def test_validate_price_raises_exception(self):
     item_one = Item(1, "chair", "made of wood", "c", "room")
     validator = ItemValidator(ItemRepository())
     self.assertRaises(InvalidItemException,
                       lambda: validator.validate(item_one))
예제 #9
0
 def add(self, item: Item):
     if not self.exists(item.get_id()):
         self.__items[item.get_id()] = item