def test_repr_method(self):
     paint_f = PaintFactory('test', 20)
     paint_f.add_ingredient('red', 10)
     expected_output = f"Factory name: {paint_f.name} with capacity {paint_f.capacity}.\n"
     for key, value in paint_f.ingredients.items():
         expected_output += f"{key}: {value}\n"
     self.assertEqual(paint_f.__repr__(), expected_output)
Example #2
0
 def test_add_ingredient_raise_error_if_ingreient_not_valid(self):
     pfac = PaintFactory('pfac', 2)
     with self.assertRaises(TypeError) as cm:
         pfac.add_ingredient('cghfg', 1)
     self.assertEqual(
         str(cm.exception),
         "Ingredient of type cghfg not allowed in PaintFactory")
Example #3
0
 def test_add_ingredient_raises_exception_when_wrong_ingredient_type_given(
         self):
     test_paint_factory = PaintFactory("Charley's", 10)
     with self.assertRaises(TypeError) as context:
         test_paint_factory.add_ingredient("banana", 2)
     self.assertEqual(
         str(context.exception),
         "Ingredient of type banana not allowed in PaintFactory")
 def test_remove_ingredient(self):
     paint_f = PaintFactory('test', 20)
     paint_f.add_ingredient('red', 5)
     paint_f.remove_ingredient('red', 2)
     self.assertEqual(paint_f.ingredients['red'], 3)
     with self.assertRaises(KeyError) as ex:
         paint_f.remove_ingredient('sd', 2)
     self.assertEqual(str(ex.exception),
                      "'No such ingredient in the factory'")
     with self.assertRaises(ValueError) as ex:
         paint_f.remove_ingredient('red', 10)
     self.assertEqual(str(ex.exception),
                      "Ingredient quantity cannot be less than zero")
Example #5
0
 def test_products(self):
     pfac = PaintFactory('pfac', 3)
     pfac.add_ingredient('yellow', 1)
     pfac.add_ingredient('white', 1)
     pfac.add_ingredient('blue', 1)
     actual = pfac.products
     expected = {'blue': 1, 'white': 1, 'yellow': 1}
     self.assertEqual(expected, actual)
Example #6
0
 def test_init(self):
     pf = PaintFactory("Test", 100)
     self.assertEqual("Test", pf.name)
     self.assertEqual(100, pf.capacity)
     self.assertEqual({}, pf.ingredients)
     self.assertEqual(["white", "yellow", "blue", "green", "red"],
                      pf.valid_ingredients)
 def test_add_ingredient(self):
     paint_f = PaintFactory('test', 20)
     paint_f.add_ingredient('red', 5)
     self.assertIn('red', paint_f.ingredients)
     self.assertEqual(paint_f.ingredients['red'], 5)
     with self.assertRaises(TypeError) as ex:
         paint_f.add_ingredient('sd', 5)
     self.assertEqual(str(ex.exception),
                      f"Ingredient of type sd not allowed in PaintFactory")
     with self.assertRaises(ValueError) as ex:
         paint_f.add_ingredient('red', 20)
     self.assertEqual(str(ex.exception), "Not enough space in factory")
Example #8
0
 def test_remove_raise_error_if_quantity_bigger(self):
     pfac = PaintFactory('pfac', 3)
     pfac.add_ingredient('white', 2)
     with self.assertRaises(ValueError) as cm:
         pfac.remove_ingredient('white', 3)
     self.assertEqual(str(cm.exception),
                      "Ingredient quantity cannot be less than zero")
Example #9
0
 def test_add_ingredients_sets_new_ingredients_types_quantities_to_given_quantities(
         self):
     test_paint_factory = PaintFactory("Charley's", 10)
     test_paint_factory.add_ingredient("white", 2)
     test_paint_factory.add_ingredient("blue", 3)
     self.assertEqual(test_paint_factory.ingredients["white"], 2)
     self.assertEqual(test_paint_factory.ingredients["blue"], 3)
 def test_can_add_method(self):
     paint_f = PaintFactory('test', 20)
     paint_f.add_ingredient('red', 5)
     self.assertIn('red', paint_f.ingredients.keys())
     with self.assertRaises(ValueError) as ex:
         paint_f.add_ingredient('red', 20)
     self.assertEqual(str(ex.exception), "Not enough space in factory")
Example #11
0
 def test_remove_raise_error_if_ingredient_not_in(self):
     pfac = PaintFactory('pfac', 3)
     pfac.add_ingredient('white', 2)
     with self.assertRaises(KeyError) as cm:
         pfac.remove_ingredient('blue', 1)
     self.assertEqual("'No such ingredient in the factory'",
                      str(cm.exception))
Example #12
0
 def test_remove_ingredient_raises_error_when_no_such_product_to_be_removed(
         self):
     test_paint_factory = PaintFactory("Charley's", 10)
     test_paint_factory.add_ingredient("white", 5)
     with self.assertRaises(KeyError) as context:
         test_paint_factory.remove_ingredient("black", 7)
     self.assertEqual(str(context.exception),
                      "'No such ingredient in the factory'")
Example #13
0
 def test_remove_ingredient_raises_error_when_not_enough_quantity_of_remaining_product_to_be_removed(
         self):
     test_paint_factory = PaintFactory("Charley's", 10)
     test_paint_factory.add_ingredient("white", 5)
     with self.assertRaises(ValueError) as context:
         test_paint_factory.remove_ingredient("white", 7)
     self.assertEqual(str(context.exception),
                      "Ingredient quantity cannot be less than zero")
Example #14
0
class TestPaintFactory(unittest.TestCase):
    def setUp(self):
        self.factory = PaintFactory("Test", 5)

    def test_paint_factory_init__expect_correct_attributes(self):
        self.assertEqual("Test", self.factory.name)
        self.assertEqual(5, self.factory.capacity)
        self.assertEqual({}, self.factory.ingredients)

    def test_paint_factory_add_ingredient__when_not_valid_ingredients_type__expect_type_error(
            self):
        with self.assertRaises(TypeError) as context:
            self.factory.add_ingredient("test", 2)

        self.assertEqual(
            f"Ingredient of type test not allowed in PaintFactory",
            str(context.exception))

    def test_paint_factory_add_ingredient__when_not_enough_capacity__expect_value_error(
            self):
        with self.assertRaises(ValueError) as context:
            self.factory.add_ingredient("white", 6)

        self.assertEqual("Not enough space in factory", str(context.exception))

    def test_paint_factory_add_ingredient__when_ingredient_not_in_ingredients__expect_to_add_it_with_given_value(
            self):
        self.assertEqual({}, self.factory.ingredients)
        self.factory.add_ingredient("white", 2)
        self.assertEqual({"white": 2}, self.factory.ingredients)

    def test_paint_factory_add_ingredient__when_ingredient_in_ingredients__expect_to_addition(
            self):
        self.factory.add_ingredient("white", 2)
        self.factory.add_ingredient("white", 2)
        self.assertEqual({"white": 4}, self.factory.ingredients)

    def test_paint_factory_remove_ingredient__when_ingredient_not_in_ingredients__expect_key_error(
            self):
        with self.assertRaises(KeyError) as context:
            self.factory.remove_ingredient("test", 2)

        self.assertEqual("'No such ingredient in the factory'",
                         str(context.exception))

    def test_paint_factory_remove_ingredient__when_given_quantity_is_more_than_item_has__expect_value_error(
            self):
        self.factory.add_ingredient("white", 2)
        with self.assertRaises(ValueError) as context:
            self.factory.remove_ingredient("white", 3)

        self.assertEqual("Ingredients quantity cannot be less than zero",
                         str(context.exception))

    def test_paint_factory_remove_ingredient__when_correct_params__expect_to_subtract_item_quantity(
            self):
        self.factory.add_ingredient("white", 2)
        self.factory.remove_ingredient("white", 2)
        self.assertEqual({"white": 0}, self.factory.ingredients)

    def test_paint_factory_product_prop__expect_to_return_ingredients(self):
        self.assertEqual({}, self.factory.products)
Example #15
0
 def setUp(self):
     self.factory = PaintFactory("Test", 5)
Example #16
0
class TestPaintFactory(unittest.TestCase):
    def setUp(self):
        self.fabrika = PaintFactory('Qica', 2500)

    def test_one(self):
        result = (self.fabrika.name, self.fabrika.capacity,
                  self.fabrika.ingredients)
        expected = ('Qica', 2500, {})

        self.assertEqual(result, expected)

    def test_two(self):
        with self.assertRaises(TypeError):
            self.fabrika.add_ingredient('test', 2000)

        with self.assertRaises(ValueError):
            self.fabrika.add_ingredient('white', 3000)

        self.fabrika.add_ingredient('white', 5)
        self.assertEqual(self.fabrika.products, {'white': 5})
        self.assertEqual(self.fabrika.capacity, 2495)

    def test_three(self):
        with self.assertRaises(KeyError):
            self.fabrika.remove_ingredient('test', 5)

        self.fabrika.add_ingredient('white', 5)

        with self.assertRaises(ValueError):
            self.fabrika.remove_ingredient('white', 6)

        self.fabrika.remove_ingredient('white', 2)
        self.assertEqual(self.fabrika.products, {'white': 3})

    def test_four(self):
        self.assertFalse(self.fabrika.can_add(5000))
        self.assertTrue(self.fabrika.can_add(10))
Example #17
0
 def setUp(self):
     self.fabrika = PaintFactory('Qica', 2500)
class TestPaintFactory(TestCase):
    def setUp(self) -> None:
        self.paint_factory = PaintFactory("Test", 100)

    def test_initializing_all_attributes(self):
        self.assertEqual("Test", self.paint_factory.name)
        self.assertEqual(100, self.paint_factory.capacity)
        self.assertListEqual(["white", "yellow", "blue", "green", "red"], self.paint_factory.valid_ingredients)
        self.assertDictEqual(self.paint_factory.products, self.paint_factory.ingredients)

    def test_can_add(self):
        self.paint_factory.ingredients = {"white": 10, "yellow": 10}
        result = self.paint_factory.can_add(50)
        self.assertEqual(True, result)

        result2 = self.paint_factory.can_add(90)
        self.assertEqual(False, result2)

    def test_add_gradient_invalid_product_type_raises(self):
        with self.assertRaises(TypeError) as ex:
            self.paint_factory.add_ingredient("pink", 10)

        self.assertEqual("Ingredient of type pink not allowed in PaintFactory", str(ex.exception))

    def test_add_gradient_not_enough_space_raises(self):
        with self.assertRaises(ValueError) as ex:
            self.paint_factory.add_ingredient("white", 120)

        self.assertEqual("Not enough space in factory", str(ex.exception))

    def test_add_gradient_successfully(self):
        self.assertDictEqual({}, self.paint_factory.products)
        result = self.paint_factory.add_ingredient("white", 50)
        self.assertDictEqual({"white": 50}, self.paint_factory.products)
        self.assertIsNone(result)

        self.paint_factory.add_ingredient("white", 10)
        self.assertDictEqual({"white": 60}, self.paint_factory.products)

        self.paint_factory.add_ingredient("yellow", 10)
        self.assertDictEqual({"white": 60, "yellow": 10}, self.paint_factory.products)

    def test_remove_gradient_not_found_rises(self):
        with self.assertRaises(KeyError) as ex:
            self.paint_factory.remove_ingredient("white", 10)

        self.assertEqual("'No such ingredient in the factory'", str(ex.exception))

    def test_remove_gradient_less_than_zero(self):
        self.paint_factory.ingredients = {"white": 10}
        with self.assertRaises(ValueError) as ex:
            self.paint_factory.remove_ingredient("white", 20)

        self.assertEqual("Ingredients quantity cannot be less than zero", str(ex.exception))

    def test_remove_gradient_successfully(self):
        self.paint_factory.ingredients = {"white": 20}
        result = self.paint_factory.remove_ingredient("white", 10)
        self.assertDictEqual({"white": 10}, self.paint_factory.ingredients)
        self.assertIsNone(result)

    def test_repr_representation(self):
        self.paint_factory.ingredients = {"white": 10, "yellow": 10}
        expected = "Factory name: Test with capacity 100.\n" \
                   "white: 10\n" \
                   "yellow: 10\n"
        self.assertEqual(expected, repr(self.paint_factory))
 def setUp(self) -> None:
     self.paint_factory = PaintFactory("Test", 100)
Example #20
0
class TestPaintFactory(unittest.TestCase):
    def setUp(self) -> None:
        self.factory = PaintFactory(name='Sharo', capacity=5)

    def test_paint_factory_if_all_attributes_are_set_correctly(self):
        self.assertEqual('Sharo', self.factory.name)
        self.assertEqual(5, self.factory.capacity)
        self.assertEqual({}, self.factory.ingredients)
        self.assertEqual({}, self.factory.products)
        # self.assertEqual(["white", "yellow", "blue", "green", "red"], self.factory.valid_ingredients)

    def test_paint_factory_add_ingredient_if_is_NOT_in_ingredients_list(self):
        with self.assertRaises(Exception) as ex:
            self.factory.add_ingredient('pink', 5)
        self.assertEqual("Ingredient of type pink not allowed in PaintFactory", str(ex.exception))

    def test_paint_factory_add_ingredient_if_capacity_is_NOT_enough(self):
        with self.assertRaises(Exception) as ex:
            self.factory.add_ingredient('white', 10)
        self.assertEqual("Not enough space in factory", str(ex.exception))

    def test_paint_factory_add_ingredient_if_ingredient_type_NOT_in_ingredients_dict(self):
        self.assertTrue('white' not in self.factory.ingredients)
        self.factory.add_ingredient('white', 3)
        self.assertTrue('white' in self.factory.ingredients)
        self.assertEqual(3, self.factory.ingredients['white'])

    def test_paint_factory_remove_ingredient_if_ingredient_type_NOT_in_ingredients_dict(self):
        with self.assertRaises(Exception) as ex:
            self.factory.remove_ingredient('white', 3)
        self.assertEqual("'No such ingredient in the factory'", str(ex.exception))

    def test_paint_factory_remove_ingredients_if_quantity_is_bigger_than_capacity(self):
        self.factory.ingredients['white'] = 5
        with self.assertRaises(Exception) as ex:
            self.factory.remove_ingredient('white', 6)
        self.assertEqual("Ingredients quantity cannot be less than zero", str(ex.exception))

    def test_paint_factory_remove_ingredients_if_all_conditions_are_covered(self):
        self.factory.ingredients['white'] = 5
        self.factory.remove_ingredient('white', 3)
        self.assertEqual(2, self.factory.ingredients['white'])
Example #21
0
 def setUp(self) -> None:
     self.factory = PaintFactory(name='Sharo', capacity=5)
Example #22
0
class PaintFactoryTests(unittest.TestCase):
    def setUp(self):
        self.paint_factory = PaintFactory("Factory", 100)

    def test_init__expect_attributes_to_be_set(self):
        self.assertEqual("Factory", self.paint_factory.name)
        self.assertEqual(100, self.paint_factory.capacity)
        # self.assertEqual(["white", "yellow", "blue", "green", "red"], self.paint_factory.valid_ingredients)
        self.assertEqual({}, self.paint_factory.ingredients)
        self.assertEqual({}, self.paint_factory.products)

    def test_add_ingredient__when_ingredient_is_not_valid_expect_type_error(
            self):
        with self.assertRaises(TypeError) as err:
            self.paint_factory.add_ingredient("purple", 10)
        expected_msg = "Ingredient of type purple not allowed in PaintFactory"
        self.assertEqual(expected_msg, str(err.exception))

    def test_add_ingredient__when_capacity_is_not_enough_expect_value_error(
            self):
        with self.assertRaises(ValueError) as err:
            self.paint_factory.add_ingredient("white", 105)
        expected_msg = "Not enough space in factory"
        self.assertEqual(expected_msg, str(err.exception))

    def test_add_ingredient__when_ingredient_is_not_in_ingredients_expect_to_add_it(
            self):
        self.paint_factory.add_ingredient("white", 10)
        expected = {"white": 10}
        self.assertEqual(expected, self.paint_factory.products)

    def test_add_ingredient__when_ingredient_is_in_ingredients_expect_to_raise_it_s_value(
            self):
        self.paint_factory.add_ingredient("white", 10)
        self.paint_factory.add_ingredient("white", 10)
        expected = {"white": 20}
        self.assertEqual(expected, self.paint_factory.products)

    def test_remove_ingredient__when_ingredient_type_not_in_ingredients_expect_key_error(
            self):
        with self.assertRaises(KeyError) as err:
            self.paint_factory.remove_ingredient("white", 10)
        expected_msg = "'No such ingredient in the factory'"
        self.assertEqual(expected_msg, str(err.exception))

    def test_remove_ingredient__when_quantity_exceeds_ingredient_quantity_expect_value_error(
            self):
        self.paint_factory.add_ingredient("white", 5)
        with self.assertRaises(ValueError) as err:
            self.paint_factory.remove_ingredient("white", 10)
        expected_msg = "Ingredients quantity cannot be less than zero"
        self.assertEqual(expected_msg, str(err.exception))

    def test_remove_ingredient__expect_to_decrease_ingredient_quantity_with_given(
            self):
        self.paint_factory.add_ingredient("white", 10)
        self.paint_factory.remove_ingredient("white", 5)
        expected = {"white": 5}
        self.assertEqual(expected, self.paint_factory.products)
Example #23
0
 def test_ingredients_attribute_initializes_properly_as_empty_dictionary(
         self):
     test_paint_factory = PaintFactory("Charley's", 10)
     self.assertEqual(test_paint_factory.ingredients, {})
Example #24
0
 def test_init_sets_the_correct_attributes(self):
     test_paint_factory = PaintFactory("Charley's", 10)
     self.assertEqual(test_paint_factory.__class__.__name__, "PaintFactory")
Example #25
0
class TestPaintFactory(TestCase):
    def setUp(self):
        self.pf = PaintFactory("Anycomp", 100)

    def test_init(self):
        self.assertEqual("Anycomp", self.pf.name)
        self.assertEqual(100, self.pf.capacity)
        self.assertEqual(["white", "yellow", "blue", "green", "red"],
                         self.pf.valid_ingredients)
        self.assertEqual({}, self.pf.ingredients)

    def test_add_ingredient_valid_product_type_and_quantity_product_type_exist(
            self):
        self.pf.ingredients = {"white": 10}
        self.pf.add_ingredient("white", 20)
        self.assertEqual({"white": 30}, self.pf.ingredients)

    def test_add_ingredient_valid_product_type_and_quantity_product_type_not_exist(
            self):
        self.assertEqual({}, self.pf.ingredients)
        self.pf.add_ingredient("white", 20)
        self.assertEqual({"white": 20}, self.pf.ingredients)

    def test_add_ingredient_insufficient_capacity_raises(self):
        with self.assertRaises(ValueError) as ex:
            self.pf.add_ingredient("white", 150)

        self.assertEqual("Not enough space in factory", str(ex.exception))

    def test_add_ingredient_invalid_ingredients_raises(self):
        with self.assertRaises(TypeError) as ex:
            self.pf.add_ingredient("black", 50)

        self.assertEqual(
            f"Ingredient of type black not allowed in {self.pf.__class__.__name__}",
            str(ex.exception))

    def test_remove_ingredient_if_ingredient_exist_greater_than_zero(self):
        self.pf.ingredients = {"white": 120}
        self.pf.remove_ingredient("white", 20)
        self.assertEqual({"white": 100}, self.pf.ingredients)

    def test_remove_ingredient_if_ingredient_exist_equal_to__zero(self):
        self.pf.ingredients = {"white": 120}
        self.pf.remove_ingredient("white", 120)
        self.assertEqual({"white": 0}, self.pf.ingredients)

    def test_remove_ingredient_if_ingredient_exist_less_than__zero_raises(
            self):
        self.pf.ingredients = {"white": 120}
        with self.assertRaises(ValueError) as ex:
            self.pf.remove_ingredient("white", 130)

        self.assertEqual("Ingredients quantity cannot be less than zero",
                         str(ex.exception))

    def test_remove_ingredient_if_ingredient_not_exist_raises(self):
        with self.assertRaises(KeyError) as ex:
            self.pf.remove_ingredient("white", 130)

        self.assertEqual("'No such ingredient in the factory'",
                         str(ex.exception))

    def test_product_property(self):
        self.pf.ingredients = {"white": 120}
        result = self.pf.products
        self.assertEqual({"white": 120}, result)
class PaintFactoryTests(unittest.TestCase):
    def setUp(self):
        self.paint_factory = PaintFactory("name", 100)
        # self.valid_ingredients = ["white", "yellow", "blue", "green", "red"]

    def test_paint_factory_initialized(self):
        self.assertEqual(self.paint_factory.name, "name")
        self.assertEqual(self.paint_factory.capacity, 100)
        self.assertEqual(self.paint_factory.ingredients, {})
        self.assertEqual(self.paint_factory.valid_ingredients,
                         ["white", "yellow", "blue", "green", "red"])

    def test_add_ingredient_ingredient_type_not_in_list(self):
        self.assertRaises(TypeError, self.paint_factory.add_ingredient,
                          "brown", 5)

    def test_add_ingredient_capacity_less_than_quantity(self):
        self.assertRaises(ValueError, self.paint_factory.add_ingredient,
                          "green", 105)

    def test_inherits_from_factory(self):
        self.assertTrue(issubclass(PaintFactory, Factory))

    def test_add_zero(self):
        self.paint_factory.add_ingredient("white", 0)
        self.assertEqual(self.paint_factory.ingredients, {"white": 0})

    def test_add_ingredient_add_new_ingredient_type(self):
        self.paint_factory.add_ingredient("white", 5)
        self.assertEqual(self.paint_factory.ingredients, {"white": 5})

    def test_remove_ingredient_ingredient_type_not_in_list(self):
        self.assertRaises(KeyError, self.paint_factory.remove_ingredient,
                          "brown", 5)

    def test_remove_ingredient_quantity_more_than_existing(self):
        self.paint_factory.add_ingredient("white", 5)
        self.assertRaises(ValueError, self.paint_factory.remove_ingredient,
                          "white", 6)

    def test_remove_ingredient_quantity(self):
        self.paint_factory.add_ingredient("white", 5)
        self.paint_factory.remove_ingredient("white", 3)
        self.assertEqual(self.paint_factory.ingredients, {"white": 2})
        self.paint_factory.remove_ingredient("white", 2)
        self.assertEqual(self.paint_factory.ingredients, {"white": 0})

    def test_get_ingredients(self):
        self.paint_factory.add_ingredient("white", 5)
        self.paint_factory.add_ingredient("yellow", 10)
        dict = self.paint_factory.ingredients
        self.assertEqual(dict, {"white": 5, "yellow": 10})

    def test_can_add(self):
        self.paint_factory.add_ingredient("white", 5)
        self.assertEqual(self.paint_factory.can_add(100), False)
        self.assertEqual(self.paint_factory.can_add(10), True)

    def test_if_instanse(self):
        self.assertIsInstance(PaintFactory)

    def test_property_products(self):
        self.assertEqual({}, self.paint_factory.products)
 def setUp(self):
     self.paint_factory = PaintFactory("name", 100)
Example #28
0
 def test_remove_ingredient_quantity_with_given_quantity(self):
     test_paint_factory = PaintFactory("Charley's", 10)
     test_paint_factory.add_ingredient("white", 5)
     test_paint_factory.remove_ingredient("white", 3)
     self.assertEqual(test_paint_factory.ingredients["white"], 2)
Example #29
0
 def setUp(self):
     self.pf = PaintFactory("Anycomp", 100)
Example #30
0
 def test_products_property_returns_ingredients(self):
     test_paint_factory = PaintFactory("Charley's", 10)
     self.assertEqual(test_paint_factory.products,
                      test_paint_factory.ingredients)