Пример #1
0
class TestPub(unittest.TestCase):
    def setUp(self):
        self.customer_holder = CustomerHolder
        self.pub = Pub("The Pink Truncheon", 100)

    def test_pub_has_name(self):
        self.assertEqual("The Pink Truncheon", self.pub.name)

    def test_pub_has_till(self):
        self.assertLess(0, self.pub.till)

    def test_add_drink_stock(self):
        name = "Pink Flamingo"
        price = 10000
        units = 3
        self.pub.add_drink_stock(name, price, units)
        self.assertEqual(5, len(self.pub.drinks))

    def test_find_drink_by_name(self):
        test_drink = {"name": "fosters", "price": 500, "units": 2}
        self.assertEqual(test_drink, self.pub.find_drink_by_name("fosters"))

    def test_add_money(self):
        self.pub.add_money(500)
        self.assertEqual(600, self.pub.till)

    def test_check_customer_age(self):
        customer = self.customer_holder.get_customer3()
        # self.assertEqual(False, self.pub.check_customer_age(customer))
        self.assertEqual(False, self.pub.check_customer_age(customer))
Пример #2
0
class TestPub(unittest.TestCase):
    
    def setUp(self):
        self.drink_1=Drink("beer", 3.00, 1, 10)
        self.drink_2=Drink("red wine", 2.00, 2, 8)
        self.drinks=[self.drink_1, self.drink_2]

        self.pub = Pub("The Prancing Pony", 100.00, self.drinks)
        self.customer_1 = Customer("Callum", 10.00, 24, 6)
        self.customer_2 = Customer("John", 5.00, 16, 0)
        self.customer_3 = Customer("James", 15.00, 30, 3)

    def test_pub_has_name(self):
        name = self.pub.name
        self.assertEqual("The Prancing Pony", name)

    def test_does_add_to_till(self):
        self.pub.add_money(self.drink_1)
        self.assertEqual(103.00, self.pub.till)

    def test_is_of_age_true(self):
        self.assertTrue(self.pub.is_of_age(self.customer_1))

    def test_is_of_age_false(self):
        self.assertFalse(self.pub.is_of_age(self.customer_2))

    def test_if_too_drunk(self):
        self.assertTrue(self.pub.refuse_service(self.customer_1))

    def test_if_not_drunk(self):
        self.assertFalse(self.pub.refuse_service(self.customer_3))

    def test_stock_level(self):
        total = self.pub.stock_value(self.drinks)
        self.assertEqual(46, total)
Пример #3
0
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)