Exemplo n.º 1
0
 def test_settle_hold_valid(self):
     dc = DebitCard()
     dc.create_account(initial_balance=14)
     dc.hold(vendor_id=1, amount=12)
     dc.settle_hold(vendor_id=1, amount=5)
     self.assertEqual(dc.check_balance(), 9)
     self.assertFalse(bool(dc.vendor_holds))  # dict should be empty
Exemplo n.º 2
0
 def setUp(self):
     self.balance = 200
     self.acnt = DebitCard()
     self.id = '42eb703e-4231-4d6d-be90-e87f167293c2'
     self.acnt.accounts[self.id] = {'balance': float(self.balance)}
     self.vendor_id = '123'
     self.vendor_id2 = '234'
     self.vendor_id3 = '345'
     self.charge = 75
     self.hold = 25
     self.accual_amount = 125
Exemplo n.º 3
0
 def test_settle_hold_over_charge(self):
     """balance is same as initial since insufficient funds"""
     dc = DebitCard()
     dc.create_account(initial_balance=14)
     dc.hold(vendor_id=1, amount=12)
     dc.settle_hold(vendor_id=1, amount=15)
     self.assertEqual(dc.check_balance(), 14)
     self.assertFalse(bool(dc.vendor_holds))  # dict should be empty
Exemplo n.º 4
0
class Customer:
    def __init__(self):
        print("Making a purchase...")
        self._debit_card = DebitCard()
        self._is_purchased = None

    def make_payment(self):
        self._is_purchased = self._debit_card.charge()

    def __del__(self):
        if self._is_purchased:
            print("Item purchased.")
        else:
            print("Not enough funds.")
Exemplo n.º 5
0
 def test_valid_account_id(self):
     dc = DebitCard()
     dc.create_account(1)
     self.assertTrue(dc.account_id)
Exemplo n.º 6
0
 def test_settle_hold_not_active(self):
     dc = DebitCard()
     dc.create_account(initial_balance=14)
     with self.assertRaises(AssertionError):
         dc.settle_hold(vendor_id=1, amount=1)
Exemplo n.º 7
0
 def test_create_account_bad_balance(self):
     dc = DebitCard()
     with self.assertRaises(AssertionError):
         dc.create_account(-1)
Exemplo n.º 8
0
class DebitCardTests(unittest.TestCase):
    """Test class to test DebitClass functionality"""
    def setUp(self):
        self.balance = 200
        self.acnt = DebitCard()
        self.id = '42eb703e-4231-4d6d-be90-e87f167293c2'
        self.acnt.accounts[self.id] = {'balance': float(self.balance)}
        self.vendor_id = '123'
        self.vendor_id2 = '234'
        self.vendor_id3 = '345'
        self.charge = 75
        self.hold = 25
        self.accual_amount = 125

    def tearDown(self):
        pass

    def test_create_count(self):
        id = self.acnt.create_account(1000)
        self.assertEqual(len(id), 36)

    def test_charge(self):
        res = self.acnt.charge(self.id, self.charge)
        self.assertEqual(res, self.balance - self.charge)

    def test_charge_more_than_once(self):
        res1 = self.acnt.charge(self.id, self.charge)
        self.assertEqual(res1, self.balance - self.charge)
        res2 = self.acnt.charge(self.id, 50.0)
        self.assertEqual(res2, self.balance - self.charge - 50.0)

    def test_charge_more_than_funds_available(self):
        charge = self.balance + 10
        with self.assertRaises(InsufficentFundError):
            self.acnt.charge(self.id, charge)

    def test_hold(self):
        res = self.acnt.hold(self.id, self.vendor_id, self.hold)
        self.assertEqual(res, self.balance - self.hold)

    def test_hold_with_charge(self):
        self.acnt.charge(self.id, self.charge)
        res = self.acnt.hold(self.id, self.vendor_id, self.hold)
        self.assertEqual(res, self.balance - self.charge - self.hold)

    def test_hold_more_than_funds_available(self):
        hold = self.balance + 10
        with self.assertRaises(InsufficentFundError):
            self.acnt.hold(self.id, self.vendor_id, hold)

    def test_one_hold_per_vender(self):
        res1 = self.acnt.hold(self.id, self.vendor_id, self.hold)
        self.assertEqual(res1, self.balance - self.hold)
        with self.assertRaises(VendorError):
            self.acnt.hold(self.id, self.vendor_id, 30.0)

    def test_hold_for_multiple_venders(self):
        res1 = self.acnt.hold(self.id, self.vendor_id, self.hold)
        self.assertEqual(res1, self.balance - self.hold)
        res2 = self.acnt.hold(self.id, self.vendor_id2, 30.0)
        self.assertEqual(res2, self.balance - self.hold - 30.0)
        res3 = self.acnt.hold(self.id, self.vendor_id3, 50.0)
        self.assertEqual(res3, self.balance - self.hold - 50.0 - 30.0)

    def test_settle_hold_when_actual_amount_less_than_balance(self):
        self.acnt.hold(self.id, self.vendor_id, self.hold)
        res = self.acnt.settle_hold(self.id, self.vendor_id,
                                    self.accual_amount)
        self.assertEqual(res, self.balance - self.accual_amount)

    def test_settle_hold_when_actual_amount_more_than_balance(self):
        self.acnt.hold(self.id, self.vendor_id, self.hold)
        with self.assertRaises(InsufficentFundError):
            self.acnt.settle_hold(self.id, self.vendor_id, 210.0)
Exemplo n.º 9
0
 def test_hold_valid(self):
     dc = DebitCard()
     dc.create_account(initial_balance=14)
     dc.hold(vendor_id=1, amount=12)
     self.assertEqual(dc.check_balance(), 2)
     self.assertEqual(dc.vendor_holds[1], 12)
Exemplo n.º 10
0
 def test_no_account_id(self):
     self.assertFalse(DebitCard().account_id)
Exemplo n.º 11
0
 def test_charge_negative(self):
     dc = DebitCard()
     dc.create_account(1)
     with self.assertRaises(AssertionError):
         dc.charge(amount=-1)
Exemplo n.º 12
0
 def test_charge_under(self):
     dc = DebitCard()
     dc.create_account(initial_balance=2)
     dc.charge(amount=1)
     self.assertEqual(dc.check_balance(), 1)
Exemplo n.º 13
0
 def test_charge_over(self):
     dc = DebitCard()
     dc.create_account(45)
     with self.assertRaises(AssertionError):
         dc.charge(amount=46)
Exemplo n.º 14
0
 def test_create_account_good(self):
     dc = DebitCard()
     dc.create_account(45)
     self.assertEqual(dc.check_balance(), 45)
Exemplo n.º 15
0
 def test_create_account_bad_balance_format(self):
     dc = DebitCard()
     with self.assertRaises(ValueError):
         dc.create_account('one')
Exemplo n.º 16
0
 def __init__(self):
     print("Making a purchase...")
     self._debit_card = DebitCard()
     self._is_purchased = None
Exemplo n.º 17
0
 def new_debit_card(self, card, holder):
     debit_card = DebitCard(self, holder, self.get_debit_card_number())
     card.debit_card.append(debit_card)
Exemplo n.º 18
0
 def test_hold_duplicate(self):
     dc = DebitCard()
     dc.create_account(initial_balance=14)
     dc.hold(vendor_id=1, amount=12)
     with self.assertRaises(AssertionError):
         dc.hold(vendor_id=1, amount=12)
Exemplo n.º 19
0
 def test_hold_multiple(self):
     dc = DebitCard()
     dc.create_account(initial_balance=14)
     dc.hold(vendor_id=1, amount=12)
     dc.hold(vendor_id=2, amount=2)
     self.assertEqual(dc.check_balance(), 0)
Exemplo n.º 20
0
 def test_initial_balance(self):
     dc = DebitCard()
     self.assertEqual(dc.check_balance(), 0)