コード例 #1
0
ファイル: BankTransferTest.py プロジェクト: rpolnx/python-tdd
    def test_should_create_transaction_history(self):
        sender_account_id = bankTransfer.create_account('sender', 15)
        receiver_account_id = bankTransfer.create_account('receiver', 25)

        transaction_id = bankTransfer.transfer_money(sender_account_id,
                                                     receiver_account_id, 10)

        transaction = bankTransfer.get_transaction_by_id(transaction_id)

        self.assertTrue(transaction)
コード例 #2
0
ファイル: BankTransferTest.py プロジェクト: rpolnx/python-tdd
    def test_should_get_all_transactions_from_account(self):
        sender_account_id = bankTransfer.create_account('sender', 15)
        receiver_account_id_1 = bankTransfer.create_account('receiver', 25)
        receiver_account_id_2 = bankTransfer.create_account('receiver2', 0)

        bankTransfer.transfer_money(sender_account_id, receiver_account_id_1,
                                    10)
        bankTransfer.transfer_money(sender_account_id, receiver_account_id_2,
                                    5)

        sender_transactions = bankTransfer.get_transactions_by_account_id(
            sender_account_id)
        receiver_transactions = bankTransfer.get_transactions_by_account_id(
            receiver_account_id_1)
        receiver_transactions_2 = bankTransfer.get_transactions_by_account_id(
            receiver_account_id_2)

        self.assertEqual(2, len(sender_transactions))
        self.assertTrue(1, len(receiver_transactions))
        self.assertTrue(1, len(receiver_transactions_2))
コード例 #3
0
ファイル: BankTransferTest.py プロジェクト: rpolnx/python-tdd
    def test_should_transfer_money_from_account_one_to_account_two(self):
        sender_account_id = bankTransfer.create_account('sender', 15)
        receiver_account_id = bankTransfer.create_account('receiver', 25)

        bankTransfer.transfer_money(sender_account_id, receiver_account_id, 10)

        sender_account_final_balance = bankTransfer.get_account(
            sender_account_id)['currentMoney']
        receiver_account_final_balance = bankTransfer.get_account(
            receiver_account_id)['currentMoney']

        self.assertEqual(5, sender_account_final_balance)
        self.assertEqual(35, receiver_account_final_balance)
コード例 #4
0
#获取配置信息
sys.path.append('./config')
from config import db_config

logger = Logger().getLog()

try:
    conn = pymysql.connect(**db_config)
except Except as e:
    logger.error('数据库连接失败,%s' % format(e))
    print('mysql connect faild ! {}'.format(e))

#定义终端的执行结果
if __name__ == '__main__':
    fromUser = sys.argv[1]
    targetUser = sys.argv[2]
    money = sys.argv[3]

transfer = BankTransfer(conn)

try:
    transfer.doTransfer(fromUser, targetUser, money)
    logger.info('帐户%s转账%s元钱至帐户%s成功' %
                (transfer.getUserById(fromUser)['name'], money,
                 transfer.getUserById(targetUser)['name']))
except Exception as e:
    logger.error('帐户转账失败%s' % e)
    print('transfer money failed %s' % format(e))
finally:
    conn.close()
コード例 #5
0
ファイル: BankTransferTest.py プロジェクト: rpolnx/python-tdd
 def test_create_account_should_return_account_number(self):
     account = bankTransfer.create_account('test')
     self.assertEqual(35, len(account))
コード例 #6
0
ファイル: BankTransferTest.py プロジェクト: rpolnx/python-tdd
 def test_cannot_transfer_more_money_than_account_balance(self):
     sender_account_id = bankTransfer.create_account('sender')
     receiver_account_id = bankTransfer.create_account('receiver')
     with self.assertRaises(Exception):
         bankTransfer.transfer_money(sender_account_id, receiver_account_id,
                                     2)
コード例 #7
0
ファイル: BankTransferTest.py プロジェクト: rpolnx/python-tdd
 def test_new_account_starts_with_money_zero(self):
     account_id = bankTransfer.create_account('test')
     account = bankTransfer.get_account(account_id)
     self.assertEqual(0, account['currentMoney'])