Closed igorsimb closed 2 months ago
main/forms.py (1)
`44-58`: Ensure that the `user` is always passed when instantiating `ScrapeIntervalForm`. The form now depends on the `user` being passed to function correctly. It would be prudent to add checks or documentation in all places where this form is instantiated to ensure that the `user` is always provided. This can prevent runtime errors from a missing `user` argument.tests/main/test_main_forms.py (2)
`48-67`: Parameterized tests in `TestTaskForm` enhance coverage and maintainability. The addition of parameterized tests for different interval values is a good practice as it ensures that various edge cases are automatically tested, making the tests easier to extend and maintain. --- `95-118`: > :memo: **NOTE** > This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [71-118] Role-based tests in `TestScrapeIntervalForm` correctly verify dropdown choices. The implementation of tests to verify the dropdown choices based on user roles is essential for ensuring that the form behaves as expected. Using a constant for defining choices is a good practice as it centralizes the choice definitions, making the tests more maintainable.main/templates/main/base.html (1)
`67-67`: Text change in login link improves language consistency. The update from "Логин" to "Войти" in the login link is a minor but meaningful change that improves the consistency or preference in language use within the application.main/views.py (3)
`57-57`: Correct implementation of user role-based form instantiation in `ItemListView`. Passing the `user` to `ScrapeIntervalForm` in the `ItemListView` ensures that the form's behavior is correctly adjusted based on the user's role, aligning with the PR's objectives. --- `186-192`: > :memo: **NOTE** > This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [189-279] Proper handling of form instantiation and error scenarios in `create_scrape_interval_task`. The view correctly handles the instantiation of `ScrapeIntervalForm` with the `user`, and includes comprehensive error handling and user feedback mechanisms. This ensures robustness and a good user experience. --- `297-303`: > :memo: **NOTE** > This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [300-327] Correct user role handling and form validation in `update_scrape_interval`. The view correctly handles the instantiation of `ScrapeIntervalForm` with the `user` and includes proper form validation and task argument updating. This ensures that the application behaves as expected based on user roles.tests/main/test_main_views.py (1)
`494-494`: Update in `valid_form_data` aligns tests with new form logic. The change from "seconds" to "hours" in the `valid_form_data` function ensures that the tests are consistent with the updated logic in `ScrapeIntervalForm`, reflecting the application's current behavior accurately.
Fixes #120 Note that any initialization of ScrapeIntervalForm now requires user parameter, e.g.:
scrape_interval_form = ScrapeIntervalForm(user=request.user)
Summary by CodeRabbit
New Features
ScrapeIntervalForm
to restrict time interval choices for non-staff and non-superusers.Bug Fixes
Tests