def test_print_empty_balance(capsys, mock_statement): mock_statement.format_transactions.return_value = "date || credit || debit || balance" account = Account(mock_statement) account.print_statement() out, err = capsys.readouterr() assert out == "date || credit || debit || balance\n"
def write_excel(self, df: pd.DataFrame, path, account: Account, positionMgr: PositionMgr): writer = pd.ExcelWriter(path=path) df.to_excel(writer, sheet_name='daily_data', index=False) account.to_excel(writer) positionMgr.to_excel(writer) writer.save()
def test_feature_print_empty_balance(capsys): account = Account() account.print_statement() out, err = capsys.readouterr() assert out == "date || credit || debit || balance\n" assert err == ""
def test_registration_schedule(wallet: Wallet, genesis: Genesis): def expected_reward_value(schedule): registration_bonus = Amount(genesis['registration_bonus']) total_accounts = len(wallet.list_accounts()) for s in schedule: if total_accounts <= s['users']: return registration_bonus * s['bonus_percent'] // 100 return registration_bonus * schedule[-1]['bonus_percent'] // 100 registration_schedule = list(genesis['registration_schedule']) total_users_in_schedule = 0 for stage in registration_schedule: total_users_in_schedule += stage['users'] stage['users'] = total_users_in_schedule names = ['martin', 'doug', 'kevin', 'joe', 'jim'] accounts = [Account(name) for name in names] for account in accounts: wallet.create_account_by_committee( DEFAULT_WITNESS, account.name, active=account.active.get_public_key(), owner=account.owner.get_public_key(), posting=account.posting.get_public_key()) assert wallet.get_account_sp_balance(account.name) == expected_reward_value(registration_schedule), \ '{} sp balance differs from expected'.format(account.name)
def setUp(self): # set up mock Transaction class and object transaction_object = mock.Mock() self.TransactionClass = mock.Mock() self.TransactionClass.return_value = transaction_object # setup mock printer self.printer_mock = mock.Mock() self.printer_mock.print_statement.return_value = "" # instantiate account test object self.account = Account(self.TransactionClass, self.printer_mock)
def test_feature_print_balance_after_two_deposits_and_one_withdraw(capsys): date = datetime.now().strftime("%m/%d/%Y") account = Account() account.deposit(1000) account.deposit(2000) account.withdraw(500) account.print_statement() out, err = capsys.readouterr() transaction1 = f"{date} || 1000.00 || || 1000.00" transaction2 = f"{date} || 2000.00 || || 3000.00" transaction3 = f"{date} || || 500.00 || 2500.00" assert out == f"date || credit || debit || balance\n{transaction3}\n{transaction2}\n{transaction1}\n" assert err == ""
def render_POST(self, request, conn): # Ricava gli argomenti del form dalla richiesta name = "" if "name" in request.args: name = request.args["name"][0].capitalize() password = "" if "password" in request.args: password = request.args["password"][0] password2 = "" if "password2" in request.args: password2 = request.args["password2"][0] email = "" if email in request.args: email = request.args["email"][0].lower() # Controlla la validità degli argomenti inseriti nel form err_msg_name = get_error_message_name(name, False) err_msg_password = get_error_message_password(password) err_msg_password2 = "" err_msg_email = get_error_message_email(email) if password != password2: err_msg_password2 = "Le password non coincidono, reinseriscile" password = "" password2 = "" # Se i dati sono corretti crea l'account e passa alla pagina della sua gestione if (err_msg_name == "" and err_msg_password == "" and err_msg_password2 == "" and err_msg_email == ""): conn.account = Account(name) database["accounts"][name] = conn.account conn.account.password = password conn.account.email = email conn.account.options = Flags(OPTION.NEWBIE, OPTION.ITALIAN, OPTION.AUTO_GOLD, OPTION.AUTO_SPLIT, OPTION.AUTO_LOOT, OPTION.AUTO_OPEN, OPTION.MAP, OPTION.COMET) # Se c'è solo il nuovo account nel database allora gli dona # il massimo dei permessi if len(database["accounts"]) == 1: conn.account.trust = TRUST.IMPLEMENTOR request.redirect("players.html") request.finish() return server.NOT_DONE_YET return self.create_page(request, conn, name, password, password2, email, err_msg_name, err_msg_password, err_msg_password2, err_msg_email)
def add_account(self, user_username, user_password, acct_type: AccountType, pin: int, balance: float, daily_withdrawal_limit: float = 1000) -> Account: user = self.login(user_username, user_password) account = Account(user_password, user_password, balance, user.dob, user.address, user.name, daily_withdrawal_limit=daily_withdrawal_limit) self._accounts[user.username].append(account) return account
def test_withdrawFunds_smallAmount_nativeClient(self): account = Account(1000) self.assertEquals(account.withdrawFunds(amount=100, native_client=True), [100])
def test_withdraw_returns_current_balance(): account = Account() account.deposit(1) assert account.withdraw(1) == 0
def test_withdrawFunds_bigAmount_nativeClient(self): account = Account(1000) self.assertEquals(account.withdrawFunds(amount=999, native_client=True), [200, 200, 200, 200, 100, 50, 20, 20])
def test_withdrawFunds_mediumAmount_otherClient(self): account = Account(1000) self.assertEquals(account.withdrawFunds(amount=450, native_client=False), [200, 200, 50])
def test_transfer_zero_debit(self): account = Account(999, 10000) account.transfer(-10000) self.assertEqual(account.funds, 0)
def test_wrong_transfer_class(self): self.assertRaises( Exception, lambda: Account(999, -1000, transferClass='Transfer'))
def simulate(self, start_day: str = '', end_day: str = '', init_amount: float = 100000.0, positionMgr: PositionMgr = PositionMgr(), excel_path: str = None): df = self.df.copy() ctx = self.ctx if start_day == '' and end_day == '': pass else: if end_day == '': df = df.loc[start_day:] else: df = df.loc[start_day:end_day] ctx['start_day'] = start_day ctx['end_day'] = end_day account = Account(init_amount=init_amount) self.before_run(df) ctx['df'] = df for index in range(len(df)): if index < self.data_lookback_window: continue df_data = df.iloc[index - self.data_lookback_window:index + 1] trade_date = df_data.tail(1).iloc[0]['trade_date'] account.day_start(trade_date=trade_date) positionMgr.day_start(trade_date=trade_date) # self.log.info('start_simu_day' + trade_date) self.run_strategy(trade_day=trade_date, df_day=df_data, account=account, positionMgr=positionMgr, ctx=ctx) # self.log.info('end_simu_day' + trade_date) series_today = df_data.tail(1).iloc[0] positionMgr.update(series_today=series_today) account.update(trade_date=trade_date, cash_change=0, positionMgr=positionMgr) positionMgr.day_end(trade_date=trade_date) account.day_end(trade_date=trade_date) # self.log.info('update_day' + trade_date) if excel_path is not None: self.write_excel(df=df, path=excel_path, account=account, positionMgr=positionMgr) return { 'daily_data': df, 'account': account.df, 'account_report': account.gen_report(), 'position': positionMgr.df, 'position_record': positionMgr.df_pos_record, 'position_report': positionMgr.gen_position_report(), 'trade_detail': positionMgr.trade_detail.df }
sec_qs = { row.security_question_1: row.security_answer_1, row.security_question_2: row.security_answer_2, row.security_question_3: row.security_answer_3 } dt = datetime.combine(pd.Timestamp(row.dob).date(), datetime.min.time()) bank.add_user(User(row.username, row.password, row['name'], dt, row.address, sec_qs)) # You can assume that the code above is correct. # Use the space below to test out any functions or pieces of code. user = User("Huang", "123456", "Zean", datetime.now(), "Qingdao", { "favoriteFood": "Apple", "Parent": "Mother", "Sports": "Basketball"}) print(user.__str__()) if type(bank) == Bank: print("You can delete this block of code in main.py if you want!") account = Account(user, AccountType.SAVINGS, "123456", 1000.2) print(account.__str__()) transaction = Transaction(user._uuid, account._uuid, "123456", datetime.now(), 600, TransactionType.DEPOSIT) print(transaction.__str__()) print(account.validate_transaction(transaction)) print(account.get_deposit_history())
def add_account(self, name, balance="100.000000000 SCR"): amount = Amount(balance) account = self.get_account(name) if not account: account = name if type(name) is Account else Account(name) self.genesis_accounts.append(GenesisAccount(account, amount))
def test_deposit_returns_current_balance(): account = Account() assert account.deposit(1) == 1
def test_user_can_print_account_statement(self): """ Integration statement output date || credit || debit || balance 14/01/2012 || || 200.00 || 0.00 20/02/2015 || 50.55 || || 200.00 21/02/2012 || || 3000.00 || 149.45 01/03/2015 || 3.50 || || 3149.45 11/01/2016 || 10.20 || || 3145.95 """ printer = Printer() account = Account(Transaction, printer) account.deposit(200) account.withdraw(50.55) account.deposit(3000) account.withdraw(3.5) account.withdraw(10.20) statement = ("date || credit || debit || balance" "\n" + datetime.now().strftime("%d/%m/%Y") + " || || 200.00 || 0.00 " "\n" + datetime.now().strftime("%d/%m/%Y") + " || 50.55 || || 200.00 " "\n" + datetime.now().strftime("%d/%m/%Y") + " || || 3000.00 || 149.45 " "\n" + datetime.now().strftime("%d/%m/%Y") + " || 3.50 || || 3149.45" "\n" + datetime.now().strftime("%d/%m/%Y") + " || 10.20 || || 3145.95") self.assertEqual(account.print_statement(), statement)
def get_account(self, name): account = name if type(name) is Account else Account(name) for ga in self.genesis_accounts: if account == ga.account: return ga.account
def test_withdraw_raises_an_error_if_not_enough_balance(): account = Account() with pytest.raises(NotEnoughMoney): account.withdraw(1)
def add_account(self, account): acc = account if type(account) is Account else Account(account) self.accounts.append(acc)
def test_transfer_deposit(self): account = Account(999, 10000) account.transfer(1000) self.assertEqual(account.funds, 11000)
def add_account(self, balance, account_type): bonus = 10 a = Account(balance + bonus, account_type) self.accounts.append(a)
def test_transfer_negative_debit(self): account = Account(999, -10000) account.transfer(-1000) self.assertEqual(account.funds, -11500)
import sys import asyncio from os.path import abspath, join, dirname import pandas as pd sys.path.insert(0, join(abspath(dirname(__file__)), '..')) from src.account import Account account = Account(init_amount=100000, start_date='20190101') account.df.to_excel('test_account.xlsx')
def test_account(self): account = Account(999, 10000) self.assertEqual(account.number, 999) self.assertEqual(account.funds, 10000)