-
Notifications
You must be signed in to change notification settings - Fork 1
Add scripts to populate and delete books #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…books.pt/test_create_cooks.py
…clean up stale sys.modules
…ext and fix logic; convert to integration test
… broken JSON file
…nd integration tests for delete_all_books and main
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds utility scripts and Makefile commands for seeding and clearing the books database, along with updated tests and documentation.
- Introduces
load_books_jsonhelper and accompanying tests inutils/db_helpers.py - Adds
scripts/create_books.pyandscripts/delete_books.pywith Makefile targets (db-seed,db-clean,db-setup) - Updates documentation (
scripts/README.md,README.md) and CI/test runner (run_tests.sh, Makefile)
Reviewed Changes
Copilot reviewed 23 out of 26 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| utils/db_helpers.py | Added JSON loader with error handling and debug print |
| scripts/create_books.py | Script to upsert books, core logic in populate_books & entry |
| scripts/delete_books.py | Script to delete all books (delete_all_books + CLI runner) |
| scripts/README.md | Usage instructions for the new data management scripts |
| Makefile | New targets for database commands and formatting/linting |
| README.md | Updated getting started steps and project name |
Comments suppressed due to low confidence (3)
scripts/create_books.py:14
- [nitpick] Docstring mentions a bulk write operation, but the implementation performs individual upsert calls in a loop. Update the description to reflect this.
Upserts a list of books into a collection using a bulk write operation.
scripts/README.md:41
- The path
scripts/books.jsonis incorrect; it should referencescripts/test_data/sample_books.jsonor the correct JSON file location.
| `make db-seed` | Populates the database with the contents of `scripts/books.json`. |
README.md:1
- [nitpick] The project title was changed to
S_BookAPIV.2, which may be a typo. Consider using the correct repository name.
# S_BookAPIV.2
newmaldenite
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only thing I could see that looked a bit funny was that the delete_all_books helper function has a docstring that says 'deletes documents' so might need to be consistent there but all looks good :)
Description
Trello card: https://trello.com/c/5laHOgpv
Adds utility scripts and Makefile commands to manage the book database for local development.
What's included:
delete_books.py: Deletes all books from MongoDB directly. Exits gracefully if the collection is already empty.create_books.py: Loads books frombooks.json, skipping duplicates.make db-clean– delete all booksmake db-seed– populate from JSONmake db-setup– clean + seedscripts/README.mdwith usage instructions.Prerequisite:
Ensure MongoDB is running locally before running the scripts.
Type of change
How Has This Been Tested?
CI/CD with GitHub Actions, following Red-Green-Refactor TDD approach, 100% code coverage, tested against a real MongoDB instance.
Checklist