Exemple #1
0
class TestPurchase(unittest.TestCase):
    def setUp(self):
        self.vm = VendingMachine(MenuImp(items))
        self.vm.menu.items.__getitem__(drink).__setitem__('stock', 10)

    def test_stock_depletes_after_successful_purchase(self):
        self.vm.insert_five()
        self.vm.make_selection(drink)
        self.assertEqual(9,
                         self.vm.menu.items.__getitem__(drink).info['stock'])

    def test_balance_depletes_after_successful_purchase(self):
        self.vm.insert_five()
        self.vm.make_selection(drink)
        self.assertEqual('$3.25', self.vm.balance.get_amount())

    def test_stock_does_not_deplete_if_purchase_fails(self):
        with self.assertRaises(PyVendingMachineError) as context:
            self.vm.insert_dollar()
            self.vm.make_selection(drink)
        self.assertEqual(10,
                         self.vm.menu.items.__getitem__(drink).info['stock'])

    def test_balance_does_not_deplete_if_purchase_fails(self):
        with self.assertRaises(PyVendingMachineError) as context:
            self.vm.insert_dollar()
            self.vm.make_selection(drink)
        self.assertEqual(100, self.vm.balance.amount)
Exemple #2
0
class TestInsertMoney(unittest.TestCase):
    def setUp(self):
        self.vm = VendingMachine(MenuImp(items))

    def test_no_change_if_no_money_inserted(self):
        self.assertEqual(zero_balance, self.vm.get_change())

    def test_insert_quarter(self):
        self.vm.insert_quarter()
        self.assertEqual(quarter, self.vm.get_change())

    def test_insert_two_quarters(self):
        self.vm.insert_quarter()
        self.vm.insert_quarter()
        self.assertEqual(fifty_cent, self.vm.get_change())

    def test_insert_dollar(self):
        self.vm.insert_dollar()
        self.assertEqual(dollar, self.vm.get_change())

    def test_insert_five(self):
        self.vm.insert_five()
        self.assertEqual(five, self.vm.get_change())

    def test_insert_twenty(self):
        self.vm.insert_twenty()
        self.assertEqual(twenty, self.vm.get_change())

    def test_insert_all_bills(self):
        self.vm.insert_quarter()
        self.vm.insert_dollar()
        self.vm.insert_five()
        self.vm.insert_twenty()
        self.assertEqual(all_currency, self.vm.get_change())

    def test_balance_should_be_zero_after_get_change(self):
        self.vm.insert_twenty()
        self.vm.get_change()
        self.assertEqual(zero_balance, self.vm.get_change())