def update_output(list_of_contents, list_of_names, list_of_dates, bank_id, account_name, account_type): if list_of_contents is not None: try: account.add_new_operations(models.Bank[bank_id], account_name, contents=list_of_contents, account_tye=models.Account(account_type)) return 'success' except Exception as ex: log.info(f'Error occured: {ex}') return 'failure'
def test_add_new_operation_for_incorrect_bank(): # GIVEN bank = 'NOT KNOWN BANK' # WHEN with pytest.raises(KeyError) as ex: account.add_new_operations(bank, 'not known account', file_name='not_known_bank.csv') # THEN assert 'Failed to load data from file. Not known bank. Was provided {} bank'.format(bank) in str(ex.value)
def test_add_new_operations_multiple_banks(mocker): # GIVEN bank = models.Bank.PL_MILLENIUM start_data = td.account_data([ ['Millenium', 'checking', '360', '2020-12-01', 'a', 'a', np.NaN, '', -1000, 'PLN', 2000], ['Millenium', 'checking', '360', '2021-01-01', 'a', 'a', np.NaN, '', 1000, 'PLN', 1000], ['ING', 'checking', 'Direct', '2021-01-31', 'a', 'a', np.NaN, np.NaN, -222.22, 'PLN', 10] ]) millenium = td.account_data([ ['Millenium', 'checking', '360', '2021-02-15', 'Train ticket', 'Detail new', np.NaN, np.NaN, -500, 'PLN', np.NaN] ]) mocker.patch('scripts.main.importer.importer.load_bank_data', side_effect=[millenium]) mocker.patch('scripts.main.database.load_accounts', side_effect=[start_data]) mocker.patch('scripts.main.total.update_total_money') mocker.patch('scripts.main.total.update_monthly_profit') mocker.patch('pandas.DataFrame.to_csv') # WHEN df = account.add_new_operations(bank, '360', file_name='test_pl_millenium.csv') # THEN millenium_balance = df.iloc[-1]['Balance'] assert millenium_balance == 500
def test_add_new_operations_by_filename(mocker): # GIVEN bank = models.Bank.PL_MILLENIUM mocker.patch('scripts.main.importer.importer.load_bank_data', side_effect=[millenium_data]) mocker.patch('scripts.main.database.load_accounts', side_effect=[start_data]) mocker.patch('scripts.main.total.update_total_money') mocker.patch('scripts.main.total.update_monthly_profit') mocker.patch('pandas.DataFrame.to_csv') # WHEN df = account.add_new_operations(bank, '360', file_name='test_pl_millenium.csv') # THEN assert_frame_equal(end_data, df)
def test_add_new_operations_by_contents(mocker): # GIVEN bank = models.Bank.PL_MILLENIUM account_raw_data = open(config.data_path() + 'test_pl_millenium.csv', "r", encoding="utf8").read().encode('utf8') encoded_account = base64.b64encode(account_raw_data) mocker.patch('scripts.main.importer.importer.load_bank_data', side_effect=[millenium_data]) mocker.patch('scripts.main.database.load_accounts', side_effect=[start_data]) mocker.patch('scripts.main.total.update_total_money') mocker.patch('scripts.main.total.update_monthly_profit') mocker.patch('pandas.DataFrame.to_csv') # WHEN df = account.add_new_operations(bank, '360', contents='data:application/vnd.ms-excel;' + str(encoded_account)) # THEN assert_frame_equal(end_data, df)