def _account_with_amount(amount): account = Account() transaction = Transaction() transaction.type = Operations.CREDIT transaction.amount = amount account.process(transaction) return account
def test_debit_without_balance(): account = Account() transaction = Transaction() transaction.type = Operations.DEBIT transaction.amount = 50 with pytest.raises(NoAvailableFounds): account.process(transaction) assert account.balance() == 0, "Should be 0"
def test_account_with_none_transaction_type(): account = Account() transaction = Transaction() transaction.type = None transaction.amount = 50 with pytest.raises(OperationNotImplemented): account.process(transaction) assert account.balance() == 0, "Should be 0"
def create_app(test_config=None): # create and configure the app app = Flask(__name__, instance_relative_config=True) ma = Marshmallow(app) app.ma = ma app.account = Account() CORS(app, resources={r"/*": {"origins": "*"}}) error_handlers.register_error_handlers(app) transaction_resource(app) account_resource(app) if test_config is None: # load the instance config, if it exists, when not testing app.config.from_pyfile('config.py', silent=True) else: # load the test config if passed in app.config.from_mapping(test_config) # ensure the instance folder exists try: os.makedirs(app.instance_path) except OSError: pass return app
def test_add_credit_to_account(): account = Account() transaction = Transaction() transaction.type = Operations.CREDIT transaction.amount = 50 account.process(transaction) assert account.balance() == 50, "Should be 50" assert len(account.transactions()) == 1, "Should not be empty"
def test_account_without_operations(): account = Account() assert account.balance() == 0, "Should be 0" assert account.transactions() is not None, "Should not be none" assert isinstance(account.transactions(), list), "Should be a list" assert len(account.transactions()) == 0, "Should be an empty list"
def test_account_with_invalid_transaction(): account = Account() with pytest.raises(InvalidTransaction): account.process(None) assert account.balance() == 0, "Should be 0"