Esempio n. 1
0
    def test_obtain_savings_goal__invalid(self, mock_input, mock_err):
        mock_input.side_effect = ['LOTS OF MONEY', '10000']
        UI.obtain_savings_goal()

        self.assertEqual(mock_input.call_count, 2)
        mock_err.assert_called_once_with(
            'Please input a valid number or keyboard command.')
Esempio n. 2
0
    def test_pad_name(self):
        test_ui = UI()
        test_ui.acc_padding = 8

        result = test_ui._pad_name('TEST')
        expected_result = 'TEST:   '
        self.assertEqual(result, expected_result)
Esempio n. 3
0
    def test_obtain_savings_goal__exit(self, mock_input, mock_cancel):
        mock_input.return_value = 'Q'
        with self.assertRaises(SystemExit):
            UI.obtain_savings_goal()

        mock_input.assert_called_once()
        mock_cancel.assert_called_once()
Esempio n. 4
0
    def test_obtain_savings_goal__negative(self, mock_input, mock_err):
        mock_input.side_effect = ['-10000', '10000']
        UI.obtain_savings_goal()

        self.assertEqual(mock_input.call_count, 2)
        mock_err.assert_called_once_with(
            'Please enter a savings goal greater than 0.')
Esempio n. 5
0
 def simulate(self):
     goal_met = False
     while not goal_met:
         self.month += 1
         goal_met = self._step_forward()
     # TODO: Construct and save final report
     UI.end(self.month)
Esempio n. 6
0
    def test_handle_confirmation__restart(self, mock_input, mock_cancel):
        mock_input.return_value = 'R'
        test_ui = UI()

        with self.assertRaises(UserRequestedRestart):
            test_ui._handle_confirmation()

        mock_cancel.assert_not_called()
Esempio n. 7
0
    def test_end_year(self, mock_heading, mock_print):
        mock_model = Mock()
        mock_model.total_saved.return_value = Decimal('1500')

        UI.end_year(mock_model, year=3)

        mock_heading.assert_called_once_with('END OF YEAR 3', level=2)
        mock_print.assert_any_call('Total saved to date: £1500')
Esempio n. 8
0
    def test_handle_confirmation__cancel(self, mock_input, mock_cancel):
        mock_input.return_value = 'Q'
        test_ui = UI()

        with self.assertRaises(SystemExit):
            test_ui._handle_confirmation()

        mock_cancel.assert_called_once()
Esempio n. 9
0
    def test_handle_user_input__restart(self, mock_input):
        mock_prompt = 'Mock Prompt: £'
        mock_input.return_value = 'R'
        test_ui = UI()
        test_ui.remaining_disposable = Decimal('1000')

        with self.assertRaises(UserRequestedRestart):
            result = test_ui._handle_user_input(mock_prompt)

        mock_input.assert_called_once_with(mock_prompt)
Esempio n. 10
0
    def test_handle_user_input__happy_path(self, mock_input):
        mock_prompt = 'Mock Prompt: £'
        mock_input.return_value = '250'
        test_ui = UI()
        test_ui.remaining_disposable = Decimal('1000')

        result = test_ui._handle_user_input(mock_prompt)

        self.assertEqual(result, Decimal('250'))
        mock_input.assert_called_once_with(mock_prompt)
Esempio n. 11
0
    def test_new_strategy_hint__no_cleared(self):
        test_ui = UI()
        test_ui.recently_cleared = []
        mock_person = Mock()
        mock_person.name = 'Joe'
        test_ui.current_person = mock_person

        result = test_ui._new_strategy_hint()
        expected_hint = ('Please provide a new strategy for Joe.\n')
        self.assertEqual(result, expected_hint)
Esempio n. 12
0
    def test_handle_user_input__exit(self, mock_input, mock_cancel):
        mock_prompt = 'Mock Prompt: £'
        mock_input.return_value = 'Q'
        test_ui = UI()
        test_ui.remaining_disposable = Decimal('1000')

        with self.assertRaises(SystemExit):
            result = test_ui._handle_user_input(mock_prompt)

        mock_input.assert_called_once_with(mock_prompt)
        mock_cancel.assert_called_once()
Esempio n. 13
0
    def test_new_strategy_hint__many_cleared(self):
        test_ui = UI()
        test_ui.recently_cleared = ['Credit Card', 'Car Loan', 'Overdraft']
        mock_person = Mock()
        mock_person.name = 'Joe'
        test_ui.current_person = mock_person

        result = test_ui._new_strategy_hint()
        expected_hint = (
            'Joe has paid off Credit Card, Car Loan and Overdraft. Please provide a new strategy for them.\n'
        )
        self.assertEqual(result, expected_hint)
Esempio n. 14
0
    def test_handle_user_input__invalid_input(self, mock_input, mock_err):
        mock_prompt = 'Mock Prompt: £'
        mock_input.side_effect = ['all', '250']
        test_ui = UI()
        test_ui.remaining_disposable = Decimal('1000')

        result = test_ui._handle_user_input(mock_prompt)

        self.assertEqual(result, Decimal('250'))
        self.assertEqual(mock_input.call_count, 2)
        mock_input.assert_called_with(mock_prompt)
        expected_err = 'Please input a valid number or keyboard command.'
        mock_err.assert_called_with(expected_err)
Esempio n. 15
0
    def test_handle_user_input__high_payment(self, mock_input, mock_err):
        mock_prompt = 'Mock Prompt: £'
        mock_input.side_effect = ['1500', '250']
        test_ui = UI()
        test_ui.remaining_disposable = Decimal('1000')

        result = test_ui._handle_user_input(mock_prompt)

        self.assertEqual(result, Decimal('250'))
        self.assertEqual(mock_input.call_count, 2)
        mock_input.assert_called_with(mock_prompt)
        expected_err = 'Payment amount exceeds remaining disposable income. Please enter a valid value.'
        mock_err.assert_called_with(expected_err)
Esempio n. 16
0
    def test_obtain_new_strategy__happy_path(self, mock_prepare, mock_hint,
                                             mock_summary, mock_strategy):
        test_ui = UI()
        mock_person = Mock()
        mock_person.name = 'Joe'
        mock_person.current_strategy = {'Current Strategy': 'test data'}

        result = test_ui.obtain_new_strategy(mock_person)

        self.assertDictEqual(result, {'TEST': 'test stuff '})
        mock_prepare.assert_called_once_with(mock_person)
        mock_hint.assert_called_once()
        mock_summary.assert_called_once_with({'Current Strategy': 'test data'})
        mock_strategy.assert_called_once()
Esempio n. 17
0
 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
Esempio n. 18
0
    def _step_forward(self):
        if (self.month % 12) == 1:
            self.model.begin_year()

        self.model.simulate_month()
        if self._achieved_goal():
            return True

        if (self.month % 12) == 0:
            self.model.end_year()
            UI.end_year(self.model, self.month // 12)
        else:
            if self.model.updated:
                self.model.strategise()

        return False
Esempio n. 19
0
    def test_obtain_savings_goal__happy_path(self, mock_input, mock_err):
        mock_input.return_value = '10000'
        result = UI.obtain_savings_goal()

        mock_input.assert_called_once()
        mock_err.assert_not_called()
        self.assertEqual(result, Decimal('10000'))
Esempio n. 20
0
 def test_heading__level_1(self):
     result = UI._heading('TEST', level=1)
     expected_heading = (
         '\n\t====================================================' +
         '\n\t======================[ TEST ]======================' +
         '\n\t====================================================\n')
     self.assertEqual(result, expected_heading)
Esempio n. 21
0
    def test_obtain_initial_strategy__happy_path(self, mock_prepare, mock_hint,
                                                 mock_summary, mock_strategy,
                                                 mock_print):
        test_ui = UI()
        mock_person = Mock()
        mock_person.name = 'Joe'

        result = test_ui.obtain_initial_strategy(mock_person)

        self.assertDictEqual(result, {'TEST': 'test stuff '})
        mock_prepare.assert_called_once_with(mock_person)
        mock_print.assert_any_call(
            'Please provide an initial financial strategy for Joe.')
        mock_hint.assert_not_called()
        mock_summary.assert_not_called()
        mock_strategy.assert_called_once()
Esempio n. 22
0
    def test_obtain_initial_strategy__multiple_attempts(
            self, mock_prepare, mock_strategy, mock_heading):
        test_ui = UI()
        mock_person = Mock()
        mock_person.name = 'Joe'
        mock_strategy.side_effect = [
            UserRequestedRestart(),
            UserRequestedRestart(), {
                'TEST': 'test stuff '
            }
        ]

        result = test_ui.obtain_initial_strategy(mock_person)

        self.assertDictEqual(result, {'TEST': 'test stuff '})
        self.assertEqual(mock_strategy.call_count, 3)
        mock_heading.assert_any_call('RESTARTING STRATEGY', level=3)
Esempio n. 23
0
    def test_obtain_strategy__no_debts(self, mock_obtain, mock_summary,
                                       mock_confirm, mock_print):
        test_ui = UI()
        mock_person = Mock()
        mock_person.name = 'Joe'
        mock_savings = Mock()
        test_ui.current_person = mock_person
        test_ui.remaining_disposable = Decimal('1000')
        test_ui.debts = []
        test_ui.savings = mock_savings
        mock_obtain.return_value = [{'MOCK_STRATEGY': 'STUFF'}]

        result = test_ui._obtain_strategy()

        expected_strategy = {
            'savings': [{
                'MOCK_STRATEGY': 'STUFF'
            }],
            'remaining': Decimal('1000')
        }
        self.assertDictEqual(result, expected_strategy)
        mock_print.assert_any_call(
            'Joe has ~£1000 disposable income per month.\n')
        mock_obtain.assert_called_once_with(mock_savings)
        mock_print.assert_any_call(
            '\nThank you. Here’s a summary of Joe’s monthly strategy:\n')
        mock_summary.assert_called_once_with(expected_strategy)
        mock_confirm.assert_called_once()
Esempio n. 24
0
    def __init__(self, data):
        self.group_mode = data.group_mode
        if self.group_mode:
            self.model = Group(data)
        else:
            self.model = Person(data.get_people()[0])
        self.month = 0

        goal_from_data = data.savings_goal
        if goal_from_data is not None:
            self.savings_goal = goal_from_data
        else:
            self.savings_goal = UI.obtain_savings_goal()
Esempio n. 25
0
    def test_prepare_data_for_strategy(self):
        mock_person = Mock()
        mock_person.disposable_income = Decimal('850.75')
        mock_debt_1 = Mock()
        mock_debt_2 = Mock()
        mock_debt_1.name = 'Credit Card'
        mock_debt_2.name = 'Car Loan'
        mock_person.debts.to_list.return_value = [mock_debt_1, mock_debt_2]
        mock_savings_1 = Mock()
        mock_savings_2 = Mock()
        mock_savings_1.name = 'Lifetime ISA'
        mock_savings_2.name = 'Savings'
        mock_person.savings.to_list.return_value = [
            mock_savings_1, mock_savings_2
        ]

        test_ui = UI()
        test_ui._prepare_data_for_strategy(mock_person)

        self.assertEqual(test_ui.remaining_disposable, Decimal('850'))
        self.assertEqual(test_ui.acc_padding, 14)
        self.assertEqual(test_ui.rem_padding, 3)
Esempio n. 26
0
    def test_summarise_strategy(self):
        test_ui = UI()
        test_ui.recently_cleared = ['Credit Card']
        test_ui.acc_padding = 13
        mock_strategy = {
            'debts': [{
                'name': 'Credit Card',
                'payment': Decimal('250')
            }, {
                'name': 'Car Loan',
                'payment': Decimal('100')
            }],
            'savings': [],
            'remaining':
            Decimal('150')
        }

        result = test_ui._summarise_strategy(mock_strategy)

        expected_summary = ('\tC̶r̶e̶d̶i̶t̶ ̶C̶a̶r̶d̶:̶ ̶ ̶£̶2̶5̶0̶\n' +
                            '\tCar Loan:     £100\n' +
                            '\t------------------\n' +
                            '\tRemaining:    £150\n')
        self.assertEqual(result, expected_summary)
Esempio n. 27
0
    def test_obtain_account_payments(self, mock_input):
        test_ui = UI()
        test_ui.remaining_disposable = Decimal('1000')
        test_ui.rem_padding = 4
        test_ui.acc_padding = 13
        mock_acc_1 = Mock()
        mock_acc_2 = Mock()
        mock_acc_1.name = 'Credit Card'
        mock_acc_2.name = 'Car Loan'
        test_accounts = [mock_acc_1, mock_acc_2]
        mock_input.side_effect = [Decimal('100'), Decimal('250')]

        result = test_ui._obtain_account_payments(test_accounts)

        mock_input.assert_any_call('\t[£1000 Remaining]    Credit Card:  £')
        mock_input.assert_any_call('\t[£900  Remaining]    Car Loan:     £')
        self.assertEqual(test_ui.remaining_disposable, Decimal('650'))
        expected_payments = [{
            'name': 'Credit Card',
            'payment': Decimal('100')
        }, {
            'name': 'Car Loan',
            'payment': Decimal('250')
        }]
Esempio n. 28
0
from finsim.ui import UI
from finsim.simulation import Simulation
from finsim.sim_data import SimData

UI.initialise()
sim_data = SimData()
simulation = Simulation(sim_data)

UI.begin()
simulation.simulate()
Esempio n. 29
0
 def test_err(self):
     result = UI._err('TEST')
     expected_err = '\n[ ERROR ]: TEST\n'
     self.assertEqual(result, expected_err)
Esempio n. 30
0
 def test_strike(self):
     result = UI._strike('TEST')
     self.assertEqual(result, 'T̶E̶S̶T̶')