Complete the code to check if a database record exists.
record = db.query("SELECT * FROM users WHERE id = [1]")
The query should filter by the unique user ID to find the correct record.
Complete the code to assert that the retrieved data matches expected values.
assert user_data['email'] == [1]
The expected email should be a string literal in quotes for the assertion to work.
Fix the error in the SQL query to ensure data integrity by checking for null values.
SELECT * FROM orders WHERE order_date IS [1]To ensure data integrity, we check that order_date is NOT NULL, meaning it has a valid value.
Fill both blanks to create a test that verifies the number of records matches the expected count.
assert len(db.query("SELECT * FROM products WHERE category = '[1]'")) [2] expected_count
The test checks that the number of products in the 'electronics' category equals the expected count.
Fill all three blanks to write a test that filters records and checks a condition on a field.
results = db.query("SELECT * FROM sales WHERE region = '[1]'") filtered = [r for r in results if r['amount'] [2] [3]] assert len(filtered) > 0
This test selects sales from the 'north' region and filters those with amount greater than 1000, asserting there is at least one such record.