-
Notifications
You must be signed in to change notification settings - Fork 1
Complete mongo db integration for put /books/{id}) #10
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
Complete mongo db integration for put /books/{id}) #10
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 completes the MongoDB integration for the PUT /books/{id} endpoint by implementing proper payload validation and replacing the existing in-memory approach with database operations. The changes introduce comprehensive validation logic and transition from updating objects in a Python list to using MongoDB's replace_one operation.
- Adds new validation helper function
validate_book_put_payload()to enforce strict field requirements - Implements
replace_book_by_id()helper to perform MongoDB document replacement - Updates the PUT endpoint to use MongoDB operations instead of in-memory list manipulation
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
app/datastore/mongo_helper.py |
Adds validation and replacement helper functions for PUT operations |
app/routes.py |
Refactors PUT endpoint to use MongoDB helpers and proper error handling |
tests/test_mongo_helper.py |
Comprehensive test coverage for new helper functions |
tests/test_app.py |
Updated integration tests for PUT endpoint with MongoDB mocking |
tests/test_api_security.py |
Security tests updated to work with MongoDB operations |
tests/test_app_utils_helper.py |
New utility function tests for hostname appending |
tests/test_data.py |
Common test constants extracted to shared module |
openapi.yml |
Updated API documentation with detailed error responses |
Comments suppressed due to low confidence (1)
tests/test_app_utils_helper.py:130
- Typo in comment: 'monkeypatcj' should be 'monkeypatch'.
monkeypatch.setattr(routes, "get_book_collection", lambda: fake_collection)
| expected_error_message = "Unexpected fields provided: rating" | ||
| assert error_dict["error"] == expected_error_message | ||
|
|
||
| def test_validate_payload_fails_with_multiple_extra_fields(): |
Copilot
AI
Aug 4, 2025
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.
Missing blank line before function definition. There should be two blank lines between function definitions at module level according to PEP 8.
| ), f"Link should end with the resource path '{expected_path}'" | ||
| headers_with_bad_body = { | ||
| "Content-Type": "application/json", | ||
| "X-API-KEY": "test-key-123" |
Copilot
AI
Aug 4, 2025
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.
Trailing whitespace after the string literal. This should be removed for consistency.
Fix test with correct assertion (replace_one()) Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
unpack with '_' vs kwargs, indicate intentional throwaway Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Use pymongo Collection type for book_collection annotation Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Description
Trello ticket: https://trello.com/c/O9jraVyM
This PR completes the MongoDB integration for the PUT /books/{id} endpoint by implementing proper payload validation and replacing the existing in-memory approach with database operations. The changes introduce comprehensive validation logic and transition from updating objects in a Python list to using MongoDB's replace_one operation.
Fixes # (issue number if applicable)
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Automated tests, manual testing, cURL, CI/CD pipeline
Checklist: