7 / 65 · 15 SQL & Database Testing · SELECT Queries for Verification← prev⊞ allnext →☰ Read as one page
1.7Practical Exercise
Write SQL verification queries for the following scenarios:
- After creating a user via API, verify the user exists in the database with correct name, email, and default role
- After placing an order, verify the order total matches the sum of line items
- After soft-deleting a user, verify the deleted_at timestamp is set and the user still exists in the table
- Find all users who registered in the last 24 hours (for post-deployment verification)
- Find any orders with negative totals (should not exist)
- Integrate one of these queries into a pytest test using psycopg2