Esempio n. 1
0
    def test_reset_recently_cleared(self, *_):
        debt_group = Debts(generate_test_data())
        debt_group.recently_cleared = ['Credit Card']

        debt_group.reset_recently_cleared()

        self.assertListEqual(debt_group.recently_cleared, [])
Esempio n. 2
0
    def test_to_list__active_only(self, mock_debt_init):
        mock_loan = Mock()
        mock_loan.active = True
        mock_credit = Mock()
        mock_credit.active = False
        mock_debt_init.side_effect = [mock_loan, mock_credit]
        debt_group = Debts(generate_test_data())

        result = debt_group.to_list(active_only=True)
Esempio n. 3
0
    def test_end_year(self, mock_account_init):
        mock_loan = Mock()
        mock_credit = Mock()
        mock_account_init.side_effect = [mock_loan, mock_credit]

        debt_group = Debts(generate_test_data())
        debt_group.end_year()

        mock_loan.end_year.assert_called_once()
        mock_credit.end_year.assert_called_once()
Esempio n. 4
0
    def __init__(self, person_data):
        self.name = person_data['name']
        self.payroll = Payroll(person_data['salary'])
        self.expenses = Expenses(person_data['expenses'])
        self.savings = SavingsAccounts(person_data['savings'])
        self.debts = Debts(person_data['debts'])

        self.joint_contrib = None
        self.disposable_income = None
        self.current_strategy = None
        self.outdated_strategies = []
        self.updated = False
Esempio n. 5
0
    def test_to_string__empty(self, mock_debt_init):
        test_data = generate_test_data()
        loan = Debt(test_data[0])
        loan.active = False
        credit = Debt(test_data[1])
        credit.active = False
        mock_debt_init.side_effect = [loan, credit]
        debt_group = Debts(test_data)

        result = debt_group.to_string()

        self.assertEqual(result, '')
Esempio n. 6
0
    def test_to_string(self, mock_debt_init):
        test_data = generate_test_data()
        loan = Debt(test_data[0])
        credit = Debt(test_data[1])
        mock_debt_init.side_effect = [loan, credit]
        debt_group = Debts(test_data)

        result = debt_group.to_string()

        expected_string = (
            '\tLoan from Friend:  £1000\n' +
            '\tCredit Card:       £1500\n'
        )
        self.assertEqual(result, expected_string)
Esempio n. 7
0
    def test_pay(self, mock_debt_init):
        mock_loan = Mock()
        mock_loan.was_updated.return_value = False
        mock_credit = Mock()
        mock_credit.was_updated.return_value = True
        mock_debt_init.side_effect = [mock_loan, mock_credit]
        debt_group = Debts(generate_test_data())

        debt_group.pay()

        mock_loan.pay.assert_called_once()
        mock_loan.was_updated.assert_called_once()
        mock_credit.pay.assert_called_once()
        mock_loan.was_updated.assert_called_once()
        self.assertListEqual(debt_group.recently_cleared, ['Credit Card'])
Esempio n. 8
0
    def test_apply_strategy(self, mock_account_init):
        mock_loan = Mock()
        mock_credit = Mock()
        mock_account_init.side_effect = [mock_loan, mock_credit]
        test_strategy = [{
            'name': 'Loan from Friend',
            'payment': Decimal('100')
        }, {
            'name': 'Credit Card',
            'payment': Decimal('125')
        }]

        debt_group = Debts(generate_test_data())
        debt_group.apply_strategy(test_strategy)

        self.assertEqual(mock_loan.payment_amount, Decimal('100'))
        self.assertEqual(mock_credit.payment_amount, Decimal('125'))
Esempio n. 9
0
class Person:
    def __init__(self, person_data):
        self.name = person_data['name']
        self.payroll = Payroll(person_data['salary'])
        self.expenses = Expenses(person_data['expenses'])
        self.savings = SavingsAccounts(person_data['savings'])
        self.debts = Debts(person_data['debts'])

        self.joint_contrib = None
        self.disposable_income = None
        self.current_strategy = None
        self.outdated_strategies = []
        self.updated = False

    def begin_year(self, joint_contrib=0):
        self.joint_contrib = joint_contrib
        total_expenses = self.expenses.monthly_total + joint_contrib
        self.disposable_income = self.payroll.net_monthly - total_expenses
        self.strategise()

    def strategise(self):
        ui = UI()
        if self.current_strategy is None:
            new_strategy = ui.obtain_initial_strategy(self)
        else:
            new_strategy = ui.obtain_new_strategy(self)
            self.outdated_strategies.append(self.current_strategy)
        
        self.current_strategy = new_strategy
        self.savings.apply_strategy(new_strategy['savings'])
        if new_strategy.get('debts', None) is not None:
            self.debts.apply_strategy(new_strategy['debts'])
        self.debts.reset_recently_cleared()
        self.updated = False

    def simulate_month(self):
        self.debts.pay()
        self.savings.deposit()
        if len(self.debts.recently_cleared) > 0:
            self.updated = True

    def total_saved(self):
        return self.savings.total_saved()

    def end_year(self):
        self.payroll.payrise()
        self.expenses.inflate()
        self.debts.end_year()
        self.savings.end_year()
Esempio n. 10
0
    def test_init(self, mock_account_init):
        mock_account = mock_account_init.return_value
        test_data = generate_test_data()

        debt_group = Debts(test_data)

        self.assertEqual(len(debt_group.account_dict), 2)
        self.assertDictEqual(debt_group.account_dict, {
            'Loan from Friend': mock_account,
            'Credit Card': mock_account
        })
        mock_account_init.assert_any_call(account_data=test_data[0])
        mock_account_init.assert_any_call(account_data=test_data[1])
        self.assertEqual(mock_account_init.call_count, 2)
Esempio n. 11
0
 def test_init(self, *_):
     test_data = generate_test_data()
     debt_group = Debts(test_data)
     self.assertListEqual(debt_group.recently_cleared, [])