示例#1
0
def test_transfer():
    """Test transfer method in Account class."""
    p1 = Person('Jack', 'Jackson', 19)
    p2 = Person('Anna', 'Dark', 194)
    p3 = Person('Igor', 'Smirnov', 33)
    p4 = Person('Nana', 'Banana', 44)
    b1 = Bank('NotSwedBank')
    b2 = Bank('CoolerThanLHV')
    b3 = Bank('NotYourSEB')
    p1_acc = Account(100, p1, b1)
    p2_acc = Account(25, p2, b2)
    p3_acc = Account(300, p3, b3)
    p4_acc = Account(0, p4, b3)
    with pytest.raises(TransactionError):
        assert p2_acc.transfer(100500, p1_acc)
    """transaction1 = Transaction(5, datetime.date.today(), p2_acc, p1_acc, False)
    transaction2 = Transaction(10, datetime.date.today(), p3_acc, p2_acc, False)"""

    # different banks transfer
    p2_acc.transfer(5, p1_acc)
    assert p2_acc.transactions == p1_acc.transactions == b1.transactions == b2.transactions
    # transaction repr tests for different bank operations
    expected = f'(5 €) {p2} -> {p1}'
    assert p2_acc.transactions[0].__repr__() == expected

    # same bank transfer
    p3_acc.transfer(10, p4_acc)
    assert p3_acc.transactions == p4_acc.transactions == b3.transactions
示例#2
0
def test_person_definition():
    """Test Person class."""
    p1 = Person('Jack', 'Jackson', 19)
    p3 = Person('Igor', 'Smirnov', 33)
    assert p3.age == 33
    assert p1.__repr__() == p1.full_name
    assert p1.bank_account is None
    with pytest.raises(PersonError):
        assert Person("aa", "BB", -4)
示例#3
0
def test_person():
    """Test person class."""
    person1 = Person("Ellina", "Gedrojets", 18)
    person2 = Person("Robert", "Soidla", 19)
    assert person2.age == 19
    assert person2.__repr__() == person2.full_name
    assert person1.bank_account is None
    with pytest.raises(PersonError):
        assert Person("Ellina", "Mailna", -20)
示例#4
0
def test_account():
    """Test account class."""
    person1 = Person("Ellina", "Gedrojets", 18)
    person2 = Person("Robert", "Soidla", 19)
    bank1 = Bank("Swed")
    bank2 = Bank("LHV")
    acc1 = Account(20, person1, bank1)
    acc2 = Account(100, person2, bank2)
    assert len(acc1.number) == 20
    assert acc2._balance == 100
示例#5
0
def test_bank():
    """Test bank class."""
    person2 = Person("Robert", "Soidla", 19)
    person1 = Person("Ellina", "Gedrojets", 18)
    bank1 = Bank("Swed")
    assert bank1.add_customer(person2) is True
    assert person2 in bank1.customers
    assert bank1.add_customer(person2) is False
    assert bank1.remove_customer(person2) is True
    assert bank1.remove_customer(person1) is False
    assert bank1.__repr__() == bank1.name
示例#6
0
def test_account():
    """Test Account class."""
    p1 = Person('Jack', 'Jackson', 19)
    p2 = Person('Anna', 'Dark', 194)
    b1 = Bank('NotSwedBank')
    b2 = Bank('CoolerThanLHV')
    p1_acc = Account(100, p1, b1)
    p2_acc = Account(25, p2, b2)
    assert len(p1_acc.number[2:]) == 18
    assert p1_acc.number[2]
    assert p1_acc.balance == 100
    assert p2_acc.balance == 25
示例#7
0
def test_transaction():
    """Test transaction class."""
    person1 = Person("Ellina", "Gedrojets", 18)
    person2 = Person("Robert", "Soidla", 19)
    bank1 = Bank("Swed")
    bank2 = Bank("LHV")
    acc1 = Account(20, person1, bank1)
    acc2 = Account(100, person2, bank2)
    tr1 = Transaction(10, datetime.date.today(), acc1, acc2, False)
    tr2 = Transaction(20, datetime.date.today(), acc1, acc1, True)
    assert tr1.__repr__() == "(10 €) Ellina Gedrojets -> Robert Soidla"
    assert tr2.__repr__() == "(20 €) ATM"
示例#8
0
def test_deposit():
    """Test deposit method in Account class."""
    p1 = Person('Jack', 'Jackson', 19)
    p2 = Person('Anna', 'Dark', 194)
    b1 = Bank('NotSwedBank')
    b2 = Bank('CoolerThanLHV')
    p1_acc = Account(100, p1, b1)
    p2_acc = Account(25, p2, b2)
    with pytest.raises(TransactionError):
        assert p1_acc.deposit(-15)

    p1_acc.deposit(15)
    tr1 = Transaction(15, datetime.date.today(), p1_acc, p1_acc, True)
    assert str(p1_acc.transactions[0]) == str(tr1)

    p2_acc.deposit(20, is_from_atm=False)
    assert p2_acc.balance == 45
示例#9
0
def test_deposit():
    """Test deposit."""
    person1 = Person("Ellina", "Gedrojets", 18)
    person2 = Person("Robert", "Soidla", 19)
    bank1 = Bank("Swed")
    bank2 = Bank("LHV")
    acc1 = Account(20, person1, bank1)
    acc2 = Account(100, person2, bank2)
    with pytest.raises(TransactionError):
        assert acc1.deposit(-10)

    acc2.deposit(2, True)
    tr1 = Transaction(2, datetime.date.today(), acc2, acc2, True)
    assert str(acc2.transactions[0]) == str(tr1)

    acc1.deposit(10, False)
    assert acc1.balance == 30
示例#10
0
def test_get_net_turnover():
    """Test."""
    person1 = Person("Ellina", "Gedrojets", 18)
    bank1 = Bank("Swed")
    acc1 = Account(200, person1, bank1)
    acc1.deposit(10)
    acc1.withdraw(50)
    assert acc1.get_net_turnover(datetime.date.today(),
                                 datetime.date.today()) == -40
示例#11
0
def test_withdraw():
    """Test function withdraw."""
    person1 = Person("Ellina", "Gedrojets", 18)
    person2 = Person("Robert", "Soidla", 19)
    bank1 = Bank("Swed")
    bank2 = Bank("LHV")
    acc1 = Account(20, person1, bank1)
    acc2 = Account(100, person2, bank2)
    with pytest.raises(TransactionError):
        assert acc1.withdraw(-10)
    with pytest.raises(TransactionError):
        assert acc1.withdraw(acc1.balance + 1)

    acc2.withdraw(10, False)
    assert acc2.balance == 90

    acc2.withdraw(10)
    tr = Transaction(-10, datetime.date.today(), acc2, acc2, True)
    assert str(acc2.transactions[0]) == str(tr)
示例#12
0
def test_withdraw():
    """Test withdraw method in Account class."""
    p1 = Person('Jack', 'Jackson', 19)
    p2 = Person('Anna', 'Dark', 194)
    b1 = Bank('NotSwedBank')
    b2 = Bank('CoolerThanLHV')
    p1_acc = Account(100, p1, b1)
    p2_acc = Account(25, p2, b2)
    with pytest.raises(TransactionError):
        assert p1_acc.withdraw(p1_acc.balance + 5)
    with pytest.raises(TransactionError):
        assert p1_acc.withdraw(-225)

    p2_acc.withdraw(20)
    tr = Transaction(-20, datetime.date.today(), p2_acc, p2_acc, True)
    assert str(p2_acc.transactions[0]) == str(tr)

    p1_acc.withdraw(15, is_from_atm=False)
    assert p1_acc.balance == 100 - 15
示例#13
0
def test_net_turnover():
    """Test get_net_turnover method in Account class."""
    p1 = Person('Jack', 'Jackson', 19)
    b1 = Bank('NotSwedBank')
    p1_acc = Account(100, p1, b1)
    p1_acc = Account(100, p1, b1)
    expected1 = 450
    p1_acc.deposit(500)
    p1_acc.withdraw(50)
    assert p1_acc.get_net_turnover(datetime.date.today(),
                                   datetime.date.today()) == expected1

    p2 = Person('Anna', 'Dark', 194)
    p2_acc = Account(200, p2, b1)
    expected2 = -50
    p2_acc.deposit(100)
    p2_acc.withdraw(150)
    assert p2_acc.get_net_turnover(datetime.date.today(),
                                   datetime.date.today()) == expected2
示例#14
0
def test_debit_turnover():
    """Test get_debit_turnover method in Account class."""
    p1 = Person('Jack', 'Jackson', 19)
    b1 = Bank('NotSwedBank')
    p1_acc = Account(100, p1, b1)
    expected = 600
    p1_acc.deposit(500)
    p1_acc.deposit(100)
    p1_acc.withdraw(150)
    assert p1_acc.get_debit_turnover(datetime.date.today(),
                                     datetime.date.today()) == expected
示例#15
0
def test_transfer():
    """Test transfer function."""
    person1 = Person("Ellina", "Gedrojets", 18)
    person2 = Person("Robert", "Soidla", 19)
    person3 = Person("Mari", "Mets", 80)
    person4 = Person("Lilian", "Valge", 40)
    bank1 = Bank("Swed")
    bank2 = Bank("LHV")
    bank3 = Bank("Luminor")
    acc1 = Account(20, person1, bank1)
    acc2 = Account(100, person2, bank2)
    acc3 = Account(250, person3, bank3)
    acc4 = Account(0, person4, bank3)
    with pytest.raises(TransactionError):
        assert acc1.transfer(10000, acc2)
    """different banks transfer."""
    acc1.transfer(10, acc2)
    assert acc1.transactions == acc2.transactions == bank1.transactions == bank2.transactions
    """Same banks transfer."""
    acc3.transfer(7, acc4)
    assert acc3.transactions == acc4.transactions == bank3.transactions
示例#16
0
def test_bank_definition():
    """Test Bank class."""
    p1 = Person('Jack', 'Jackson', 19)
    p2 = Person('Anna', 'Dark', 194)
    p3 = Person('Igor', 'Smirnov', 33)
    b1 = Bank('NotSwedBank')
    b2 = Bank('CoolerThanLHV')
    assert b1.add_customer(p1) is True
    assert p1 in b1.customers
    assert b2.add_customer(p2) is True
    assert b2.add_customer(p3) is True
    assert p2 in b2.customers
    assert p3 in b2.customers
    assert b2.add_customer(p2) is False
    assert b2.remove_customer(Person('Jey', 'Winston', 57)) is False
    assert p1.bank_account.balance == 0
    assert len(b2.customers) == 2
    assert b2.customers == [p2, p3]
    assert b2.remove_customer(p3) is True
    assert p3 not in b2.customers
    assert len(b2.customers) == 1
    assert b1.__repr__() == b1.name
示例#17
0
def test_acc_statement():
    """Test."""
    person1 = Person("Ellina", "Gedrojets", 18)
    bank1 = Bank("Swed")
    acc1 = Account(20, person1, bank1)
    old_transaction = Transaction(
        150,
        datetime.date.today() - datetime.timedelta(days=19), acc1, acc1, True)
    acc1.transactions.append(old_transaction)
    new_transaction = Transaction(
        50,
        datetime.date.today() - datetime.timedelta(days=5), acc1, acc1, True)
    acc1.transactions.append(new_transaction)
    result_is_new_trans = acc1.account_statement(
        datetime.date.today() - datetime.timedelta(days=7),
        datetime.date.today())

    assert result_is_new_trans == [new_transaction]
示例#18
0
def test_acc_statement():
    """Test account_statement method in Account class."""
    p1 = Person('Jack', 'Jackson', 19)
    b1 = Bank('NotSwedBank')
    p1_acc = Account(100, p1, b1)
    old_trans = Transaction(
        150,
        datetime.date.today() - datetime.timedelta(days=15), p1_acc, p1_acc,
        True)
    p1_acc.transactions.append(old_trans)
    new_trans = Transaction(50,
                            datetime.date.today() - datetime.timedelta(days=5),
                            p1_acc, p1_acc, True)
    p1_acc.transactions.append(new_trans)

    res_newer = p1_acc.account_statement(
        datetime.date.today() - datetime.timedelta(days=7),
        datetime.date.today())
    assert res_newer == [new_trans]

    res_old = p1_acc.account_statement(
        datetime.date.today() - datetime.timedelta(days=365),
        datetime.date.today() - datetime.timedelta(days=10))
    assert res_old == [old_trans]
示例#19
0
class TestPersonFullName(unittest.TestCase):
    def setUp(self):
        self.person = Person(1, "Olivier", "LON")

    def testFullName(self):
        self.assertEqual("Olivier LON", self.person.getFullName())
示例#20
0
 def setUp(self):
     self.person = Person(1, "Olivier", "LON")