Пример #1
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)
Пример #2
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()
Пример #3
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()
Пример #4
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()
Пример #5
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)
Пример #6
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)
Пример #7
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)
Пример #8
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()
Пример #9
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)
Пример #10
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)
Пример #11
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)
Пример #12
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()
Пример #13
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
Пример #14
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()
Пример #15
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)
Пример #16
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)
Пример #17
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')
        }]
Пример #18
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)
Пример #19
0
    def test_handle_confirmation__ok(self, mock_input, mock_cancel):
        mock_input.return_value = ''
        test_ui = UI()

        test_ui._handle_confirmation()
        mock_cancel.assert_not_called()