def test_action_record_integrity_failure(action):
    card_num, account_id, last_record_index, session_key, uow, session_manager = setup_account_test(
        1, True)
    with pytest.raises(service_exceptions.AccountHistoryIntegrityError):
        handler.account_action(session_key=session_key,
                               account_id=account_id,
                               action=action,
                               card_num=card_num,
                               uow=uow,
                               amount=1,
                               session_manager=session_manager)
def test_invalid_card():
    card_num, account_id, last_record_index, session_key, uow, session_manager = setup_account_test(
        0)
    with pytest.raises(service_exceptions.InvalidCardNum):
        handler.account_action(session_key=session_key,
                               account_id=account_id,
                               action=AccountRecord.DEPOSIT,
                               card_num=card_num + 1,
                               uow=uow,
                               amount=10,
                               session_manager=session_manager)
def test_invalid_action():
    card_num, account_id, last_record_index, session_key, uow, session_manager = setup_account_test(
        0)
    with pytest.raises(ValueError):
        handler.account_action(session_key=session_key,
                               account_id=account_id,
                               action='some',
                               card_num=card_num,
                               uow=uow,
                               amount=1,
                               session_manager=session_manager)
def test_invalid_amount():
    card_num, account_id, last_record_index, session_key, uow, session_manager = setup_account_test(
        0)
    with pytest.raises(domain_exception.InvalidAmount):
        handler.account_action(session_key=session_key,
                               account_id=account_id,
                               action=AccountRecord.DEPOSIT,
                               card_num=card_num,
                               uow=uow,
                               amount=-1,
                               session_manager=session_manager)
def test_invalid_withdrawal(amount, balance):
    balance = 3289
    card_num, account_id, last_record_index, session_key, uow, session_manager = setup_account_test(
        balance)
    with pytest.raises(domain_exception.NegativeAccountBalanceException):
        handler.account_action(session_key=session_key,
                               account_id=account_id,
                               action=AccountRecord.WITHDRAWAL,
                               card_num=card_num,
                               uow=uow,
                               amount=balance + 1,
                               session_manager=session_manager)
def test_withdrawal(amount, balance):
    card_num, account_id, last_record_index, session_key, uow, session_manager = setup_account_test(
        balance)
    account = handler.account_action(session_key=session_key,
                                     account_id=account_id,
                                     action=AccountRecord.WITHDRAWAL,
                                     card_num=card_num,
                                     uow=uow,
                                     amount=amount,
                                     session_manager=session_manager)

    assert account.get_balance() == balance - amount
    assert account.histories[-1].record_index == last_record_index + 1
def test_deposit(amount, balance):
    card_num, account_id, last_record_index, session_key, uow, session_manager = setup_account_test(
        balance)
    account = handler.account_action(session_key=session_key,
                                     account_id=account_id,
                                     action=AccountRecord.DEPOSIT,
                                     card_num=card_num,
                                     uow=uow,
                                     amount=amount,
                                     session_manager=session_manager)

    assert account.get_balance() == balance + amount
    assert account.histories[-1].record_index == last_record_index + 1