def test_credit_acc_below_zero(self):
     chrgamt = "$2589"
     crdamt = "$2600"
     acc = Account(name="Alan", ccnum="4111111111111111", cclimit="$3000")
     acc.charge_acc(chrgamt)
     acc.credit_acc(crdamt)
     self.assertEqual(acc.balance, -11)
 def test_process_input_credit_acc(self):
     dict = {}
     acc =  Account(name='Tom', ccnum='4111111111111111', cclimit='$1000')
     acc.charge_acc('$800')
     dict[acc.name] = acc
     accarry = runapp.process_input('Credit Tom $500',dict)
     self.assertEqual(dict[acc.name].name, 'Tom')
     self.assertEqual(dict[acc.name].ccnum, 4111111111111111)
     self.assertEqual(dict[acc.name].cclimit, 1000)
     self.assertEqual(dict[acc.name].balance, 300)
Beispiel #3
0
def process_input(input, accdict):
    """
    Process all arguments into accounts and add them to the dictionary. Return a dictionary of all active accounts.
    :param input: the command line arguments converted into a list:
    :param accdict: a dictionary containing all active accounts with the account name as a key.
    :return an updated accdict:
    """
    accinfo = input.split()
    if accinfo[1] in accdict:
        acc = accdict[accinfo[1]]
    else:
        acc = None
    if not acc and accinfo[0] == 'Add':
        acc = Account(name=accinfo[1], ccnum=accinfo[2], cclimit=accinfo[3])
    if acc and accinfo[0] == 'Charge':
        acc.charge_acc(accinfo[2])
    if acc and accinfo[0] == 'Credit':
        acc.credit_acc(accinfo[2])
    accdict[acc.name] = acc
    return accdict
 def test_charge_acc_decline_invalid_cc_num(self):
     acc = Account(name="Alan", ccnum="1234567890123456", cclimit="$3000")
     self.assertFalse(acc.charge_acc("$59"))
 def test_charge_acc_success_then_decline(self):
     acc = Account(name="Alan", ccnum="4111111111111111", cclimit="$1000")
     self.assertTrue(acc.charge_acc("$300"))
     self.assertFalse(acc.charge_acc("$2701"))
 def test_charge_acc_declined(self):
     acc = Account(name="Alan", ccnum=4111111111111111, cclimit="$3000")
     self.assertFalse(acc.charge_acc("$3500"))
 def test_charge_acc_accepted(self):
     acc = Account(name="Alan", ccnum="4111111111111111", cclimit="$3000")
     self.assertTrue(acc.charge_acc("$3000"))