Complete the code to create a test client for the Flask app.
with app.test_client() as [1]: response = client.get('/')
app instead of client as the variable name.request which is for incoming requests, not test client.The test_client() method returns a client object used to simulate requests. Naming it client is the common practice.
Complete the code to set up an in-memory SQLite database for testing.
app.config['SQLALCHEMY_DATABASE_URI'] = '[1]'
Using sqlite:///:memory: creates a temporary in-memory database ideal for fast tests.
Fix the error in the test setup by completing the code to create all tables before tests.
with app.app_context(): [1]
drop_all() which deletes tables.commit() without creating tables.Calling db.create_all() inside the app context creates all tables needed for tests.
Fill both blanks to add a new user and commit the change in the test database.
new_user = User(username='testuser') db.session.[1](new_user) db.session.[2]()
remove() or rollback() which undo changes.Use add() to add the new user to the session, then commit() to save changes.
Fill all three blanks to query a user by username and check the result in a test.
user = User.query.filter_by([1]=[2]).[3]()
all() which returns a list instead of one user.Use filter_by(username='testuser') and first() to get the first matching user.