Esempio n. 1
0
    def test_feed_pet_method_pet_not_in_pets_list(self):
        self.shop = PetShop("Monkey")
        with self.assertRaises(Exception) as exc:
            self.shop.feed_pet("pet_food", "Jerry")

        msg = "Please insert a valid pet name"
        self.assertEqual(str(exc.exception), msg)
Esempio n. 2
0
    def test_pet_shop_has_correct_representation(self):
        msg = '''Shop test_shop:
Pets: test1, test2'''
        p = PetShop('test_shop')
        p.add_pet('test1')
        p.add_pet('test2')
        self.assertEqual(msg, repr(p))
Esempio n. 3
0
    def test_add_food_method_raises_error(self):
        self.shop = PetShop("Monkey")
        with self.assertRaises(ValueError) as exc:
            self.shop.add_food("seeds", 0)

        msg = "Quantity cannot be equal to or less than 0"
        self.assertEqual(str(exc.exception), msg)
Esempio n. 4
0
    def test_add_pet_raises_error(self):
        self.shop = PetShop("Monkey")
        self.shop.add_pet("Jerry")
        with self.assertRaises(Exception) as exc:
            self.shop.add_pet("Jerry")

        msg = "Cannot add a pet with the same name"
        self.assertEqual(str(exc.exception), msg)
Esempio n. 5
0
 def setUp(self) -> None:
     self.pet_shop = PetShop("Test")
Esempio n. 6
0
class PetShopTest(unittest.TestCase):

    def test_correct__init__(self):
        self.shop = PetShop("Monkey")
        self.assertEqual(self.shop.name, "Monkey")
        self.assertEqual(self.shop.food, {})
        self.assertEqual(self.shop.pets, [])

    def test_incorrect__init__(self):
        self.shop = PetShop("Monkey")
        self.assertNotEqual(self.shop.name, "Donkey")
        self.assertEqual(self.shop.food, {})
        self.assertEqual(self.shop.pets, [])

    def test_add_food_method_raises_error(self):
        self.shop = PetShop("Monkey")
        with self.assertRaises(ValueError) as exc:
            self.shop.add_food("seeds", 0)

        msg = "Quantity cannot be equal to or less than 0"
        self.assertEqual(str(exc.exception), msg)

    def test_add_food_not_in_foods_dict(self):
        self.shop = PetShop("Monkey")
        self.shop.add_food("seeds", 5)
        self.assertEqual(self.shop.food, {"seeds": 5})

    def test_add_food_return_message(self):
        self.shop = PetShop("Monkey")
        msg = f"Successfully added 5.00 grams of seeds."
        self.assertEqual(self.shop.add_food("seeds", 5), msg)

    def test_add_food_method_food_already_in_food_dict(self):
        self.shop = PetShop("Monkey")
        self.shop.add_food("seeds", 5)
        self.shop.add_food("seeds", 5)
        self.assertEqual(self.shop.food, {"seeds": 10})

    def test_add_pet_method(self):
        self.shop = PetShop("Monkey")
        msg = "Successfully added Jerry."
        self.assertEqual(self.shop.add_pet("Jerry"), msg)
        self.assertEqual(self.shop.pets, ["Jerry"])

    def test_add_pet_raises_error(self):
        self.shop = PetShop("Monkey")
        self.shop.add_pet("Jerry")
        with self.assertRaises(Exception) as exc:
            self.shop.add_pet("Jerry")

        msg = "Cannot add a pet with the same name"
        self.assertEqual(str(exc.exception), msg)

    def test_feed_pet_method_pet_not_in_pets_list(self):
        self.shop = PetShop("Monkey")
        with self.assertRaises(Exception) as exc:
            self.shop.feed_pet("pet_food", "Jerry")

        msg = "Please insert a valid pet name"
        self.assertEqual(str(exc.exception), msg)

    def test_feed_pet_method_food_not_in_foods_dict(self):
        self.shop = PetShop("Monkey")
        self.shop.add_pet("Jerry")
        msg = "You do not have pet food"
        self.assertEqual(self.shop.feed_pet("pet food", "Jerry"), msg)

    def test_feed_pet_method_food_quantity_less_than_100(self):
        self.shop = PetShop("Monkey")
        self.shop.add_pet("Jerry")
        self.shop.add_food("seeds", 99)
        self.assertEqual(self.shop.feed_pet("seeds", "Jerry"), "Adding food...")
        self.assertEqual(self.shop.food, {"seeds": 1099.00})

    def test_feed_pet_positive_result(self):
        self.shop = PetShop("Monkey")
        self.shop.add_pet("Jerry")
        self.shop.add_food("seeds", 101)
        self.assertEqual(self.shop.feed_pet("seeds", "Jerry"), "Jerry was successfully fed")
        self.assertEqual(self.shop.food, {"seeds": 1})

    def test__repr__method(self):
        self.shop = PetShop("Monkey")
        self.shop.add_pet("Jerry")
        self.shop.add_pet("Tom")
        msg = "Shop Monkey:\nPets: Jerry, Tom"
        self.assertEqual(self.shop.__repr__(), msg)
Esempio n. 7
0
 def test_add_pet_method(self):
     self.shop = PetShop("Monkey")
     msg = "Successfully added Jerry."
     self.assertEqual(self.shop.add_pet("Jerry"), msg)
     self.assertEqual(self.shop.pets, ["Jerry"])
Esempio n. 8
0
 def test_add_food_return_message(self):
     self.shop = PetShop("Monkey")
     msg = f"Successfully added 5.00 grams of seeds."
     self.assertEqual(self.shop.add_food("seeds", 5), msg)
Esempio n. 9
0
 def test_add_food_method_food_already_in_food_dict(self):
     self.shop = PetShop("Monkey")
     self.shop.add_food("seeds", 5)
     self.shop.add_food("seeds", 5)
     self.assertEqual(self.shop.food, {"seeds": 10})
Esempio n. 10
0
class TestPetShop(unittest.TestCase):
    def setUp(self):
        self.pet_shop = PetShop('PetShop')

    def test_petshop_init_method(self):
        self.assertEqual(self.pet_shop.name, 'PetShop')
        self.assertEqual(self.pet_shop.food, {})
        self.assertEqual(self.pet_shop.pets, [])
    
    def test_petshop_add_food_method_when_quantity_zero_should_raises(self):
        with self.assertRaises(ValueError) as ex:
            self.pet_shop.add_food('food', 0)
        
        self.assertTrue(str(ex.exception))

    def test_petshop_add_food_method_when_quantity_below_zero_should_raises(self):
        with self.assertRaises(Exception) as ex:
            self.pet_shop.add_food('food', -7)
        
        self.assertIsNotNone(str(ex.exception))

    def test_petshop_add_food_method(self):
        self.pet_shop.add_food('food', 10)
        
        self.assertEqual(self.pet_shop.food, {'food': 10})

    def test_pethshop_add_food_method_when_food_in_list(self):
        self.pet_shop.add_food('food', 10)
        self.pet_shop.add_food('food', 110)

        self.assertEqual(self.pet_shop.food, {'food': 120})

    def test_petshop_add_food_method_return_massage(self):
        result = self.pet_shop.add_food('food', 10)
        expected_result = f'Successfully added 10.00 grams of food.'
        
        self.assertEqual(result, expected_result)
    
    def test_pethsop_add_pet_method_when_pet_already_in_list_should_raises(self):
        self.pet_shop.add_pet('Rusty')
        with self.assertRaises(Exception) as ex:
            self.pet_shop.add_pet('Rusty')
        
        # self.assertIsNotNone(str(ex.exception))
        self.assertEqual(str(ex.exception), 'Cannot add a pet with the same name')
    
    def test_pethsop_add_pet_method(self):
        self.pet_shop.add_pet('Rusty')
        
        self.assertEqual(self.pet_shop.pets[0], 'Rusty')
    
    def test_pethsop_add_pet_method_return_massage(self):
        result = self.pet_shop.add_pet('Rusty')
        expected_result = f'Successfully added Rusty.'

        self.assertEqual(self.pet_shop.pets[0], 'Rusty')
        self.assertEqual(result, expected_result)
    
    def test_petshop_feed_pet_method_when_pet_not_in_list_should_raises(self):
        self.pet_shop.add_pet('Jupyter')
        self.pet_shop.add_food('pulneny chushki', 100)
        with self.assertRaises(Exception) as ex:
            self.pet_shop.feed_pet('pulneny chushki', 'Rusty')
        
        # self.assertIsNotNone(str(ex.exception))
        self.assertEqual(str(ex.exception), 'Please insert a valid pet name')

    def test_petshop_feed_pet_method_when_food_non_in_list(self):
        self.pet_shop.add_pet('Rusty')
        self.pet_shop.add_food('pulneny chushki', 100)

        result = self.pet_shop.feed_pet('chushki', 'Rusty')
        expected_result = f'You do not have chushki'

        self.assertEqual(result, expected_result)
    
    def test_petshop_feed_pet_method_when_food_below_100(self):
        self.pet_shop.add_pet('Rusty')
        self.pet_shop.add_food('pulneny chushki', 10)

        result = self.pet_shop.feed_pet('pulneny chushki', 'Rusty')
        expected_result = f'Adding food...'

        self.assertEqual(self.pet_shop.food['pulneny chushki'], 1010)
        self.assertEqual(result, expected_result)

    def test_petshop_feed_pet_method_when_food_above_100(self):
        self.pet_shop.add_pet('Rusty')
        self.pet_shop.add_food('pulneny chushki', 200)

        result = self.pet_shop.feed_pet('pulneny chushki', 'Rusty')
        expected_result = f'Rusty was successfully fed'

        self.assertEqual(self.pet_shop.food['pulneny chushki'], 100)
        self.assertEqual(result, expected_result)
    
    def test_petshop_repr_method(self):
        self.pet_shop.add_pet('Rusty')
        result = self.pet_shop.__repr__()
        expected_result = f'Shop PetShop:\nPets: Rusty'

        self.assertEqual(result, expected_result)
Esempio n. 11
0
 def test_add_food_not_in_foods_dict(self):
     self.shop = PetShop("Monkey")
     self.shop.add_food("seeds", 5)
     self.assertEqual(self.shop.food, {"seeds": 5})
Esempio n. 12
0
 def test_feed_pet_method_food_not_in_foods_dict(self):
     self.shop = PetShop("Monkey")
     self.shop.add_pet("Jerry")
     msg = "You do not have pet food"
     self.assertEqual(self.shop.feed_pet("pet food", "Jerry"), msg)
Esempio n. 13
0
 def test_feed_pet_positive_result(self):
     self.shop = PetShop("Monkey")
     self.shop.add_pet("Jerry")
     self.shop.add_food("seeds", 101)
     self.assertEqual(self.shop.feed_pet("seeds", "Jerry"), "Jerry was successfully fed")
     self.assertEqual(self.shop.food, {"seeds": 1})
Esempio n. 14
0
class PetShopTests(TestCase):
    def setUp(self) -> None:
        self.pet_shop = PetShop("Test")

    def test_init(self):
        self.assertEqual("Test", self.pet_shop.name)
        self.assertEqual([], self.pet_shop.pets)
        self.assertEqual({}, self.pet_shop.food)

    def test_add_food_invalid_quantity_raises(self):
        with self.assertRaises(ValueError) as ex:
            self.pet_shop.add_food("food", 0)
        self.assertEqual("Quantity cannot be equal to or less than 0",
                         str(ex.exception))

    def test_add_food_valid(self):
        self.assertEqual({}, self.pet_shop.food)
        expected_result = "Successfully added 1000.00 grams of meat."
        actual_result = self.pet_shop.add_food("meat", 1000)
        self.assertEqual(expected_result, actual_result)
        self.assertEqual({"meat": 1000}, self.pet_shop.food)

    def test_add_food_existing_food_quantity_increases(self):
        self.pet_shop.food = {"meat": 5}
        self.pet_shop.add_food("meat", 3)
        self.assertEqual({"meat": 8}, self.pet_shop.food)

    def test_add_pet_valid(self):
        self.assertEqual([], self.pet_shop.pets)
        expected_result = "Successfully added Jerry."
        actual_result = self.pet_shop.add_pet("Jerry")
        self.assertEqual(expected_result, actual_result)
        self.assertEqual(["Jerry"], self.pet_shop.pets)

    def test_add_pet_existing_pet_raises(self):
        self.pet_shop.pets = ["Jerry"]
        with self.assertRaises(Exception) as ex:
            self.pet_shop.add_pet("Jerry")
        self.assertEqual("Cannot add a pet with the same name",
                         str(ex.exception))

    def test_feed_pet_not_existing_pet_raises(self):
        self.pet_shop.food = {"meat": 5}
        with self.assertRaises(Exception) as ex:
            self.pet_shop.feed_pet("meat", "Jerry")
        self.assertEqual("Please insert a valid pet name", str(ex.exception))

    def test_feed_pet_not_existing_food_raises(self):
        self.pet_shop.pets = ["Jerry"]
        self.assertEqual({}, self.pet_shop.food)
        expected_result = "You do not have meat"
        actual_result = self.pet_shop.feed_pet("meat", "Jerry")
        self.assertEqual(expected_result, actual_result)

    def test_feed_pet_adds_food(self):
        self.pet_shop.pets = ["Jerry"]
        self.pet_shop.food = {"meat": 50}
        expected_result = "Adding food..."
        actual_result = self.pet_shop.feed_pet("meat", "Jerry")
        self.assertEqual(expected_result, actual_result)
        self.assertEqual(1050.0, self.pet_shop.food["meat"])

    def test_feed_pet_food_valid(self):
        self.pet_shop.pets = ["Jerry"]
        self.pet_shop.food = {"meat": 1100}
        expected_result = "Jerry was successfully fed"
        actual_result = self.pet_shop.feed_pet("meat", "Jerry")
        self.assertEqual(expected_result, actual_result)
        self.assertEqual(1000, self.pet_shop.food["meat"])

    def test_repr_method(self):
        self.pet_shop.pets = ["Jerry", "Tom"]
        expected_result = "Shop Test:\nPets: Jerry, Tom"
        actual_result = repr(self.pet_shop)
        self.assertEqual(expected_result, actual_result)
Esempio n. 15
0
class PetShopTests(unittest.TestCase):
    def setUp(self) -> None:
        self.ps = PetShop('test')

    def test_pet_shop_has_correct_attributes_after_init(self):
        self.assertEqual(
            (True, True, True),
            (
                hasattr(self.ps, 'name'),
                hasattr(self.ps, 'food'),
                hasattr(self.ps, 'pets'),
            ),
        )
        self.assertEqual(
            ('test', {}, []),
            (self.ps.name, self.ps.food, self.ps.pets),
        )

    def test_pet_shop_add_food_raises_with_negative_qty(self):
        msg = 'Quantity cannot be equal to or less than 0'
        with self.assertRaises(ValueError) as ctx:
            self.ps.add_food('test_food', -1)
        self.assertEqual(
            (msg, 0),
            (str(ctx.exception), len(self.ps.food))
        )

    def test_pet_shop_add_food_new_food(self):
        self.assertEqual(0, len(self.ps.food))
        self.assertNotIn('new_food', self.ps.food)
        self.ps.add_food('new_food', 5)
        self.assertEqual(1, len(self.ps.food))
        self.assertIn('new_food', self.ps.food)
        self.assertEqual(5, self.ps.food['new_food'])
        self.assertEqual(1, len(self.ps.food))
        self.assertNotIn('another_food', self.ps.food)
        self.ps.add_food('another_food', 10)
        self.assertEqual(2, len(self.ps.food))
        self.assertIn('another_food', self.ps.food)
        self.assertEqual(5, self.ps.food['new_food'])
        self.assertEqual(10, self.ps.food['another_food'])

    def test_pet_shop_adds_qty_if_food_exist(self):
        self.assertEqual(0, len(self.ps.food))
        self.ps.add_food('new_food', 5)
        self.assertEqual(1, len(self.ps.food))
        self.assertIn('new_food', self.ps.food)
        self.ps.add_food('new_food', 15)
        self.assertEqual(1, len(self.ps.food))
        self.assertEqual(20, self.ps.food['new_food'])

    def test_pet_shop_add_food_returns_correct_message(self):
        msg = 'Successfully added 10.00 grams of test_food.'
        rv = self.ps.add_food('test_food', 10)
        self.assertEqual(msg, rv)

    def test_pet_shop_add_pet_can_add_pet_if_it_is_not_already_present(self):
        self.assertEqual(0, len(self.ps.pets))
        msg = 'Successfully added new_pet.'
        rv = self.ps.add_pet('new_pet')
        self.assertEqual(msg, rv)
        self.assertEqual(1, len(self.ps.pets))
        self.assertIn('new_pet', self.ps.pets)
        msg2 = 'Successfully added another_pet.'
        rv2 = self.ps.add_pet('another_pet')
        self.assertEqual(msg2, rv2)
        self.assertEqual(2, len(self.ps.pets))
        self.assertIn('another_pet', self.ps.pets)

    def test_pet_shop_add_pet_raises_if_name_of_pet_already_present(self):
        self.assertEqual(0, len(self.ps.pets))
        self.ps.add_pet('new_pet')
        self.assertEqual(1, len(self.ps.pets))
        self.assertIn('new_pet', self.ps.pets)
        msg = 'Cannot add a pet with the same name'
        with self.assertRaises(Exception) as ctx:
            self.ps.add_pet('new_pet')
        self.assertEqual(msg, str(ctx.exception))

    def test_petshop_can_feed_pet_if_such_pet_and_enough_food_exists(self):
        msg = 'test_pet was successfully fed'
        self.ps.add_pet('test_pet')
        self.ps.add_food('test_food', 150)
        rv = self.ps.feed_pet('test_food', 'test_pet')
        self.assertEqual(msg, rv)
        self.assertEqual(50, self.ps.food['test_food'])

    def test_petshop_feed_pet_raises_if_no_such_pet_exist(self):
        msg = 'Please insert a valid pet name'
        self.ps.add_pet('test_pet')
        self.ps.add_food('test_food', 150)
        with self.assertRaises(Exception) as ctx:
            self.ps.feed_pet('test_food', 'pet')
        self.assertEqual(msg, str(ctx.exception))
        self.assertEqual(150, self.ps.food['test_food'])

    def test_petshop_feed_pet_returns_correct_msg_if_no_such_food_exist(self):
        msg = 'You do not have food'
        self.ps.add_pet('test_pet')
        self.ps.add_food('test_food', 150)
        rv = self.ps.feed_pet('food', 'test_pet')
        self.assertEqual(msg, rv)
        self.assertEqual(150, self.ps.food['test_food'])

    def test_petshop_feed_pet_returns_correct_msg_if_food_is_not_enough(self):
        msg = 'Adding food...'
        self.ps.add_pet('test_pet')
        self.ps.add_food('test_food', 50)
        rv = self.ps.feed_pet('test_food', 'test_pet')
        self.assertEqual(msg, rv)
        self.assertEqual(1050.00, self.ps.food['test_food'])

    def test_pet_shop_has_correct_representation(self):
        msg = '''Shop test_shop:
Pets: test1, test2'''
        p = PetShop('test_shop')
        p.add_pet('test1')
        p.add_pet('test2')
        self.assertEqual(msg, repr(p))
Esempio n. 16
0
 def setUp(self):
     self.petshop = PetShop("Test")
Esempio n. 17
0
class TestPetShop(TestCase):
    def setUp(self):
        self.petshop = PetShop("Test")

    def test_initializing_all_attributes(self):
        self.assertEqual("Test", self.petshop.name)
        self.assertEqual({}, self.petshop.food)
        self.assertEqual([], self.petshop.pets)

    def test_add_food_negative_quantity_raises(self):
        with self.assertRaises(ValueError) as ex:
            self.petshop.add_food("TestFood", 0)

        self.assertEqual("Quantity cannot be equal to or less than 0", str(ex.exception))

    def test_add_food(self):
        self.petshop.add_food("TestFood", 10)
        self.assertDictEqual({"TestFood": 10}, self.petshop.food)

        result = self.petshop.add_food("TestFood", 10)
        self.assertDictEqual({"TestFood": 20}, self.petshop.food)
        self.assertEqual("Successfully added 10.00 grams of TestFood.", result)

    def test_add_existing_pet_raises(self):
        self.petshop.add_pet("TestPet")
        with self.assertRaises(Exception) as ex:
            self.petshop.add_pet("TestPet")

        self.assertEqual("Cannot add a pet with the same name", str(ex.exception))

    def test_add_pet(self):
        self.assertListEqual([], self.petshop.pets)
        result = self.petshop.add_pet("TestPet")
        self.assertListEqual(["TestPet"], self.petshop.pets)
        self.assertEqual("Successfully added TestPet.", result)

    def test_feed_not_existing_pet_raises(self):
        self.petshop.add_pet("TestPet")
        self.petshop.add_food("TestFood", 10)

        with self.assertRaises(Exception) as ex:
            self.petshop.feed_pet("TestFood", "PetTest")

        self.assertEqual("Please insert a valid pet name", str(ex.exception))

    def test_feed_pet_food_not_exist(self):
        self.petshop.add_pet("TestPet")
        self.petshop.add_food("TestFood", 10)

        result = self.petshop.feed_pet("FoodTest", "TestPet")
        self.assertEqual("You do not have FoodTest", result)

    def test_feed_pet_with_less_than_hundred(self):
        self.petshop.add_pet("TestPet")
        self.petshop.add_food("TestFood", 10)
        self.assertDictEqual({"TestFood": 10}, self.petshop.food)

        result = self.petshop.feed_pet("TestFood", "TestPet")
        self.assertDictEqual({"TestFood": 1010}, self.petshop.food)
        self.assertEqual("Adding food...", result)

    def test_feed_pet(self):
        self.petshop.add_pet("TestPet")
        self.petshop.add_food("TestFood", 100)
        self.assertDictEqual({"TestFood": 100}, self.petshop.food)

        result = self.petshop.feed_pet("TestFood", "TestPet")
        self.assertDictEqual({"TestFood": 0}, self.petshop.food)
        self.assertEqual("TestPet was successfully fed", result)

    def test_repr_representation(self):
        self.petshop.add_pet("TestPet")
        self.petshop.add_pet("TestPet2")

        self.assertEqual(f'Shop Test:\n'
                         f'Pets: TestPet, TestPet2', repr(self.petshop))
Esempio n. 18
0
 def setUp(self):
     self.name = PetShop("Bubba")
Esempio n. 19
0
class TestPetShop(TestCase):
    def setUp(self):
        self.name = PetShop("Bubba")

    def test_init_attribute(self):
        self.assertEqual(f"{self.name}", self.name)

    def test_add_food_successfully(self):
        added = self.name.add_food("Meat", 5)
        self.assertEqual("Successfully added 5.00 grams of Meat.", added)

    def test_add_pet_successfully(self):
        added = self.name.add_pet("Dudda")
        self.assertEqual("Successfully added Dudda.", added)

    def test_feed_pet_successfully(self):
        fed = self.name.feed_pet("Hills", "Lory")
        self.assertEqual(f"Lory was successfully fed", fed)

    def test_add_zero_food_rise_value_error(self):
        with self.assertRaises(ValueError) as ve:
            self.name.add_food("Meat", -5)
        self.assertEqual("Quantity cannot be equal to or less than 0", str(ve.exception))

    def test_add_pet_with_same_name_raises_exception(self):
        self.name.add_pet("Bubba")
        with self.assertRaises(Exception) as ex:
            self.name.add_pet("Bubba")
        self.assertEqual("Cannot add a pet with the same name", str(ex.exception))

    def test_feed_a_pet_not_in_list_rasies_exeption(self):
        with self.assertRaises(Exception) as ex:
            self.name.feed_pet("Hills", "Jojoba")
        self.assertEqual("Please insert a valid pet name", str(ex.exception))

    def test_feed_a_pet_with_a_food_not_in_list_return_message(self):
        message = self.name.feed_pet("Jojoba", "Hills")
        self.assertEqual("You do not have Jojoba", message)
Esempio n. 20
0
 def setUp(self) -> None:
     self.ps = PetShop('test')
Esempio n. 21
0
 def test_correct__init__(self):
     self.shop = PetShop("Monkey")
     self.assertEqual(self.shop.name, "Monkey")
     self.assertEqual(self.shop.food, {})
     self.assertEqual(self.shop.pets, [])
Esempio n. 22
0
class TestPetShop(TestCase):
    def setUp(self):
        self.pet_shop = PetShop("test_name")

    def test_correct_initialization(self):
        self.assertEqual("test_name", self.pet_shop.name)
        self.assertEqual({}, self.pet_shop.food)
        self.assertEqual([], self.pet_shop.pets)

    def test_add_food_less_then_zero_raises(self):
        with self.assertRaises(ValueError) as ex:
            self.pet_shop.add_food("food_name", -1)
        self.assertEqual("Quantity cannot be equal to or less than 0",
                         str(ex.exception))

    def test_add_food_zero_raises(self):
        with self.assertRaises(ValueError) as ex:
            self.pet_shop.add_food("food_name", 0)
        self.assertEqual("Quantity cannot be equal to or less than 0",
                         str(ex.exception))

    def test_added_new_food(self):
        msg = self.pet_shop.add_food("meat", 1)
        self.assertEqual({"meat": 1}, self.pet_shop.food)
        self.assertEqual("Successfully added 1.00 grams of meat.", msg)

    def test_added_more_food(self):
        msg = self.pet_shop.add_food("meat", 1)
        self.assertEqual({"meat": 1}, self.pet_shop.food)
        self.assertEqual("Successfully added 1.00 grams of meat.", msg)
        msg_2 = self.pet_shop.add_food("Granula", 100)
        self.assertEqual({"meat": 1, "Granula": 100}, self.pet_shop.food)
        self.assertEqual("Successfully added 100.00 grams of Granula.", msg_2)

    def test_increase_food(self):
        msg = self.pet_shop.add_food("meat", 1)
        msg_2 = self.pet_shop.add_food("meat", 1)
        self.assertEqual({"meat": 2}, self.pet_shop.food)
        self.assertEqual("Successfully added 1.00 grams of meat.", msg)
        self.assertEqual("Successfully added 1.00 grams of meat.", msg_2)

    def test_add_pet(self):
        msg = self.pet_shop.add_pet("Jack")
        self.assertEqual(["Jack"], self.pet_shop.pets)
        self.assertEqual("Successfully added Jack.", msg)

    def test_add_another_pet(self):
        msg = self.pet_shop.add_pet("Jack")
        self.assertEqual(["Jack"], self.pet_shop.pets)
        self.assertEqual("Successfully added Jack.", msg)
        msg_2 = self.pet_shop.add_pet("Tobi")
        self.assertEqual(["Jack", "Tobi"], self.pet_shop.pets)
        self.assertEqual("Successfully added Tobi.", msg_2)

    def test_add_existing_pet_raises(self):
        msg = self.pet_shop.add_pet("Jack")
        self.assertEqual("Successfully added Jack.", msg)
        with self.assertRaises(Exception) as ex:
            self.pet_shop.add_pet("Jack")
        self.assertEqual("Cannot add a pet with the same name",
                         str(ex.exception))

    def test_feed_pet_not_in_pets_raises(self):
        self.pet_shop.add_pet("Tobi")
        self.pet_shop.add_food("Granula", 200)
        with self.assertRaises(Exception) as ex:
            self.pet_shop.feed_pet("Granula", "Jack")
        self.assertEqual("Please insert a valid pet name", str(ex.exception))

    def test_feed_pet_with_wrong_food(self):
        self.pet_shop.add_pet("Jack")
        self.pet_shop.add_food("Granula", 200)
        msg = self.pet_shop.feed_pet("meat", "Jack")
        self.assertEqual("You do not have meat", msg)

    def test_feed_pet_with_less_then_100(self):
        self.pet_shop.add_food("Granula", 90)
        self.pet_shop.add_pet("Jack")
        msg = self.pet_shop.feed_pet("Granula", "Jack")
        self.assertEqual("Adding food...", msg)

    def test_feed_pet(self):
        self.pet_shop.add_food("Granula", 200)
        self.pet_shop.add_pet("Jack")
        msg = self.pet_shop.feed_pet("Granula", "Jack")
        self.assertEqual(100, self.pet_shop.food["Granula"])
        self.assertEqual("Jack was successfully fed", msg)

    def test_repr_method(self):
        self.pet_shop.add_pet("Jack")
        self.pet_shop.add_pet("Simba")
        msg = f'Shop {self.pet_shop.name}:\n' \
              f'Pets: {", ".join(self.pet_shop.pets)}'
        self.assertEqual(msg, repr(self.pet_shop))
Esempio n. 23
0
 def test_feed_pet_method_food_quantity_less_than_100(self):
     self.shop = PetShop("Monkey")
     self.shop.add_pet("Jerry")
     self.shop.add_food("seeds", 99)
     self.assertEqual(self.shop.feed_pet("seeds", "Jerry"), "Adding food...")
     self.assertEqual(self.shop.food, {"seeds": 1099.00})
Esempio n. 24
0
 def setUp(self):
     self.pet_shop = PetShop("test_name")
Esempio n. 25
0
 def test__repr__method(self):
     self.shop = PetShop("Monkey")
     self.shop.add_pet("Jerry")
     self.shop.add_pet("Tom")
     msg = "Shop Monkey:\nPets: Jerry, Tom"
     self.assertEqual(self.shop.__repr__(), msg)
Esempio n. 26
0
 def setUp(self):
     self.pet_shop = PetShop('PetShop')