-
Notifications
You must be signed in to change notification settings - Fork 1
Remove redundant UUID in post endpoint #6
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
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
This PR refactors the book creation system by removing manual UUID generation and allowing MongoDB to handle ID generation using native ObjectIds. The change separates the API logic from the database setup script by creating distinct helper functions for different use cases.
- Replaces manual UUID generation with MongoDB's native ObjectId for the POST /books endpoint
- Splits the single insert helper into two specialized functions: one for API operations and one for file-based data synchronization
- Updates API documentation to reflect ObjectId format instead of UUID format
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| app/routes.py | Updates POST /books route to use ObjectId and handle response formatting |
| app/datastore/mongo_helper.py | Separates insert logic into API-specific and file-sync functions |
| scripts/create_books.py | Updates to use the new upsert function for file synchronization |
| openapi.yml | Updates API documentation to reflect ObjectId format |
| tests/*.py | Updates test mocks and assertions to match new ObjectId-based flow |
Comments suppressed due to low confidence (3)
tests/test_mongo_helper.py:25
- The test is calling
assert_called_once()on line 24 and thenassert_called_once_with()on line 25. The first assertion is redundant since the second assertion already verifies the method was called once with specific arguments.
mock_books_collection.insert_one.assert_called_once_with(new_book)
tests/test_app.py:95
- The test verifies that
update_onewas called but doesn't verify the arguments. Since the route code callsupdate_onewith specific parameters (filter and update operation), the test should verify these arguments to ensure the correct database operation is performed.
mock_collection.update_one.assert_called_once()
tests/test_api_security.py:96
- Similar to the previous test, this assertion verifies that
update_onewas called but doesn't verify the arguments. The test should verify the filter and update parameters to ensure the correct database operation is performed.
mock_collection.update_one.assert_called_once()
Description
This PR removes the use of manually generated UUIDs in the POST /books endpoint, allowing MongoDB to handle _id generation via its native ObjectId.
Key Changes:
Fixes # (issue number if applicable)
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Automated tests, manual testing inc. verifying script idempotency, CI/CD pipeline
Checklist: