Creating test cases for components in application factory and Blueprints
Application factory functions and Blueprints help solve circular import problems by managing the context loading and allowing the Flask app
instance to be accessible across the application without tapping the __main__
top-level module. Since every component and layer is in its proper place, it is easier to set up the testing environment.
Our applications in Chapters 2 and 3 have essential Flask components that need testing, such as the repository transaction built by the SQLAlchemy, exceptions, and standard API functions. All these components are built by the create_app()
factory and Blueprints.
Let us start formulating test cases for SQLAlchemy repository transactions.
Testing ORM transactions
The Online Shipping app in Chapter 2 uses the standard SQLAlchemy ORM to implement the CRUD transactions. Integration testing can help test the repository layer of our application. Let us examine the following...