0%

Prove the Database Behaves · capstone

Capstone project: Project: A Database Behavior Suite

Seven focused tests protect seven boundaries. Finish with one independent workflow that connects initialization, import retry, availability, checkout, and reopen durability without borrowing state from another test.

Complete test_import_retry_and_lending_flow(tmp_path) in tests/test_catalog.py. It receives its own complete-flow.db and CSV path. Write at least two valid unseen item rows, including text that would expose careless assumptions, such as Unicode or a name containing an SQL keyword. Call catalog_import.import_items_csv(database_path, csv_path) twice. Require (N, 0) from the first call and (0, N) from the exact retry.

Open the database and record all five item fields in ID order before continuing. Call catalog_db.list_available_items(connection) and compare its asset tags in public order. Insert and commit one member, then call catalog_db.checkout_item for one imported item. Close the connection.

Reopen the same path. Require that the checked-out item has disappeared from the available result, the loan contains every expected field, and the item rows still equal the values recorded immediately after the retry. This order matters: you first prove the repeated import did not change the catalog, then use that catalog in the broader flow.

Keep this eighth test independent. It must take tmp_path, create its own files, and make no assumption about which of the other seven tests ran first. Do not inspect program source, compare SQL , or call private . The suite is valuable because it describes public results and durable state while allowing the program’s internal organization to evolve.

Press Run. run_tests.py calls exactly pytest.main(["-q", "-p", "no:cacheprovider", "tests/test_catalog.py"]). The finished project should report:

Database tests passed: 8

Submit first runs the complete correct suite twice. It then checks every earlier behavior change and two exact-retry regressions, one per fresh project. Each run must collect normally and fail for a real assertion rather than an import accident. Generated databases, CSV files, and caches must stay outside the project tree. You now have eight compact tests that can be rerun after a query, , migration, or import changes.

Task

Complete test_import_retry_and_lending_flow(tmp_path) in tests/test_catalog.py. Import one unseen valid CSV twice, require (N, 0) then (0, N), reopen and record unchanged items, continue through public availability and checkout, then reopen again to prove the available result, durable loan, and item rows. Keep all eight tests independent and leave program unchanged.