class TestPub(unittest.TestCase): def setUp(self): # this sets up the list with two list items self.drink_1 = Drink("Brew Dog", 5) self.drink_2 = Drink("Dolce Banana", 15) # this says that the two items go in the list drinks = [self.drink_1, self.drink_2] # this gives values to the parameters to Class pub self.pub = Pub("The Prancing Pony", 100.00, drinks) def test_pub_has_name(self): # this checks if the pub has a name self.assertEqual("The Prancing Pony", self.pub.name) def test_does_till_have_cash(self): # this checks if the pub has cash self.assertEqual(100.00, self.pub.till) def test_can_add_money(self): # this checks if the pub can have money added self.pub.add_money(10.00) self.assertEqual(110.00, self.pub.till) def test_pub_stock_count(self): # this checks if the pub has 2 in its list self.assertEqual(2, self.pub.drink_count()) def test_can_add_drink_to_stock(self): # this sets up a new drink with its price new_drink = Drink("White Russian", 10) # this calls the add_drink method from pub.py and adds the drink assigned to new_drink self.pub.add_drink(new_drink) # this checks if the list now has three items, the 2 in the list and the 1 added self.assertEqual(3, self.pub.drink_count()) def test_can_find_drink_by_name(self): # this calls the find_drink_by_name method from pub.py and checking the drinks in the list self.pub.find_drink_by_name(self.drink_1) # this checks the name of the drink against name in the list self.assertEqual("Brew Dog", self.drink_1.name) def test_sell_drink_to_customer(self): customer = Customer("Michael Sinclair", 1000) self.pub.sell_drink_to_customer("Brew Dog", customer) # don't need 'self'.customer because customer is an instance in this method self.assertEqual(995, customer.wallet) self.assertEqual(105, self.pub.till)
class TestPub(unittest.TestCase): def setUp(self): self.pub = Pub("Ox", 100.00) self.customer_1 = Customer("David", 50.00) self.drink_beer = Drink("Beer", 5.00) self.drink_wine = Drink("Wine", 6.00) self.drink_gnt = Drink("Gin & Tonic", 7.50) self.drink_rum = Drink("Rum", 5.50) self.drink_coke = Drink("Coke", 0.75) self.drink_lemonade = Drink("Lemonade", 0.65) self.pub.menu_of_drinks = [ self.drink_beer, # put the other menu items in here ] def test_pub_has_name(self): self.assertEqual("Ox", self.pub.name) def test_pub_has_cash_in_till(self): self.assertEqual(100.00, self.pub.cash) def test_till_transaction__add(self): self.pub.till_transaction(5) self.assertEqual(105.00, self.pub.cash) def test_drink_has_been_added_to_menu(self): self.pub.add_drink(self.drink_beer) self.assertEqual(2, self.pub.drink_count()) def test_drink_has_been_removed_from_menu(self): self.pub.remove_drink(self.drink_beer) self.assertEqual(0, self.pub.drink_count()) def test_sell_drink_to_customer(self): self.customer_1.add_drink_to_customer_hand(self.drink_beer) self.customer_1.alter_customer_wallet_amount(self.drink_beer.price) self.pub.till_transaction(self.drink_beer.price) self.pub.remove_drink(self.drink_beer) self.assertEqual(1, len(self.customer_1.drinks_in_hand)) self.assertEqual(45, self.customer_1.wallet) self.assertEqual(105.00, self.pub.cash) self.assertEqual(0, self.pub.drink_count()) def test_check_customer_age(self): self.assertEqual(True, self.pub.check_customer_age())
class TestPub(unittest.TestCase): def setUp(self): self.drink_1 = Drink("beer", 2.00) self.drink_2 = Drink("wine", 3.00) self.drink_3 = Drink("gin", 4.00) self.pub = Pub("The Prancing Pony", 100.00) self.customer = Customer("Frodo", 10.00) def test_pub_has_name(self): self.assertEqual("The Prancing Pony", self.pub.name) def test_pub_has_till(self): self.assertEqual(100.00, self.pub.till) def test_pub_can_add_drinks(self): self.pub.add_drink(self.drink_1) self.assertEqual(1, self.pub.drink_count()) def test_pub_cannot_serve_drink(self): self.pub.add_drink(self.drink_1) self.pub.add_drink(self.drink_2) self.pub.serve(self.customer, self.drink_1) self.assertEqual(8.00, self.customer.wallet) self.assertEqual(102.00, self.pub.till) self.assertEqual(1, self.pub.drink_count()) def test_pub_cannot_serve_unstocked_drink(self): self.pub.add_drink(self.drink_1) self.pub.serve(self.customer, self.drink_2) self.assertEqual(10.00, self.customer.wallet) self.assertEqual(100.00, self.pub.till) self.assertEqual(1, self.pub.drink_count()) def test_pub_does_not_serve_too_many_drinks(self): self.pub.add_drink(self.drink_1) self.pub.add_drink(self.drink_1) self.pub.serve(self.customer, self.drink_1) self.assertEqual(1, self.pub.drink_count())
class TestPub (unittest.TestCase): def setUp(self): self.drink_1 = Drink("Mojito", 8.0, 7) self.drink_2 = Drink("Pilsen", 6.5, 4) self.customer_1 = Customer("Malcolm", 25.0, 28) self.customer_2 = Customer("Erika", 30.0, 17) drinks = [self.drink_2, self.drink_1] self.pub = Pub("JP's", drinks, 500) def test_pub_has_name(self): self.assertEqual("JP's", self.pub.name) def test_pub_has_till(self): self.assertEqual(500, self.pub.till) def test_pub_has_drinks(self): self.assertEqual(2, self.pub.drink_count()) def test_can_increase_till(self): self.pub.increase_till(8.0) self.assertEqual(508.0, self.pub.till) def test_can_find_drink_by_name(self): self.pub.find_drink_by_name(self.drink_1) self.assertEqual("Mojito", self.drink_1.name) def test_can_check_customer_age__overage(self): self.assertEqual(False, self.pub.check_if_under_age(self.customer_1)) def test_can_check_customer_age__underage(self): self.assertEqual(True, self.pub.check_if_under_age(self.customer_2)) def test_can_check_customer_drunkennes__drunk(self): self.pub.sell_drink(self.drink_1, self.customer_1) self.pub.sell_drink(self.drink_2, self.customer_1) self.assertEqual(True, self.pub.check_if_drunk(self.customer_1)) def test_can_check_customer_drunkennes__not_drunk(self): self.pub.sell_drink(self.drink_1, self.customer_1) self.assertEqual(False, self.pub.check_if_drunk(self.customer_1)) def test_pub_sell_drink(self): self.pub.sell_drink(self.drink_2, self.customer_1) self.assertEqual(18.5, self.customer_1.wallet) self.assertEqual(506.5, self.pub.till) self.assertEqual(1, self.customer_1.drink_count()) self.assertEqual(4, self.customer_1.drunkenness_level)
class TestPub(unittest.TestCase): def setUp(self): self.pub = Pub("The Prancing Pony", 100) self.customer_1 = Customer("Ben", 10, 18, 0) self.customer_2 = Customer("Adam", 1, 12, 0) self.drink_1 = Drink("Tennents", 2, 1) self.drink_2 = Drink("wine", 4, 2) self.drink_3 = Drink("gin", 5, 3) def test_pub_has_name(self): self.assertEqual("The Prancing Pony", self.pub.pub_name) #@unittest.skip("Delete this line to run the test") def test_pub_has_money(self): self.assertEqual(100, self.pub.till) #@unittest.skip("Delete this line to run the test") def test_pub_has_drinks(self): self.assertEqual(0, self.pub.stock_count()) def test_pub_can_add_drinks(self): self.pub.add_drink(self.drink_1) self.assertEqual(1, self.pub.stock_count()) #@unittest.skip("Delete this line to run the test") def test_customer_has_money(self): self.assertEqual( True, self.pub.check_customer_wallet(self.customer_1, self.drink_1)) #@unittest.skip("Delete this line to run the test" def test_customer_has_money(self): self.assertEqual( False, self.pub.check_customer_wallet(self.customer_2, self.drink_1)) def test_customer_money_reduced(self): self.assertEqual( 8, self.pub.take_customer_money(self.customer_1, self.drink_1)) def test_add_money_to_till(self): self.assertEqual(102, self.pub.add_to_till(self.customer_1, self.drink_1)) def test_customer_id(self): self.assertEqual(True, self.pub.age_id(self.customer_1)) def test_customer_id(self): self.assertEqual(False, self.pub.age_id(self.customer_2)) def test_customer_drunk(self): self.assertEqual( 1, self.pub.get_customer_drunk(self.customer_1, self.drink_1)) def test_pub_can_serve_drink(self): self.pub.add_drink(self.drink_1) self.pub.add_drink(self.drink_2) self.pub.serve(self.customer_1, self.drink_1) self.assertEqual(8.00, self.customer.wallet) self.assertEqual(102.00, self.pub.till) self.assertEqual(1, self.pub.drink_count())