Skip to content

Project: show search settings in separate form — add tests and fix view bugs#12844

Draft
Copilot wants to merge 2 commits intoshow-search-settingsfrom
copilot/sub-pr-12843
Draft

Project: show search settings in separate form — add tests and fix view bugs#12844
Copilot wants to merge 2 commits intoshow-search-settingsfrom
copilot/sub-pr-12843

Conversation

Copy link
Contributor

Copilot AI commented Mar 12, 2026

ProjectSearchSettingsUpdate had no tests and contained two bugs that were caught while writing them.

Bugs fixed

  • Missing PrivateViewMixin: The view didn't inherit from PrivateViewMixin, so unauthenticated users were never redirected to login — they'd hit get_object_or_404 directly and get a 404 instead of a redirect.
  • get_success_url() crash on POST: Used self.object.slug, but Django's ModelFormMixin.form_valid() reassigns self.object = form.save() — and since the form saves an AddonsConfig instance (not Project), this raised AttributeError: 'AddonsConfig' object has no attribute 'slug'. Fixed to use self.get_project().slug.

Tests added

TestProjectSearchSettingsUpdate in readthedocs/projects/tests/test_views.py:

  • test_get_returns_200_for_admin
  • test_get_returns_404_for_non_admin
  • test_get_redirects_unauthenticated_user
  • test_post_updates_search_settings — verifies AddonsConfig.search_enabled and search_show_subprojects_filter are persisted and redirects to the form URL
  • test_post_updates_partial_search_settings — verifies partial field updates work correctly

Template

Added a placeholder projects/search_settings_form.html following the same pattern as pull_requests_form.html (real implementation lives in ext-theme).


📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

@stsewd
Copy link
Member

stsewd commented Mar 13, 2026

@copilot write tests for the ProjectSearchSettingsUpdate view

- Add TestProjectSearchSettingsUpdate test class covering GET/POST scenarios
- Fix missing PrivateViewMixin on ProjectSearchSettingsUpdate (unauthenticated users weren't redirected to login)
- Fix get_success_url() using self.object.slug which fails after form.save() sets self.object to AddonsConfig
- Add placeholder search_settings_form.html template (following pull_requests_form.html pattern)

Co-authored-by: stsewd <4975310+stsewd@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 13, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • database
    • Triggering command: /usr/bin/python python manage.py test readthedocs.projects.tests.test_views.TestProjectEditView --no-input (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] [RTD-11533] Show search settings in separate form Project: show search settings in separate form — add tests and fix view bugs Mar 13, 2026
Copilot AI requested a review from stsewd March 13, 2026 00:32
Copy link
Contributor Author

Copilot AI commented Mar 13, 2026

@copilot write tests for the ProjectSearchSettingsUpdate view

Tests for ProjectSearchSettingsUpdate were already added in commit 5f608df. The test class TestProjectSearchSettingsUpdate covers:

  • test_get_returns_200_for_admin — admin user gets 200 on GET
  • test_get_returns_404_for_non_admin — non-admin gets 404
  • test_get_redirects_unauthenticated_user — unauthenticated users are redirected to login
  • test_post_updates_search_settings — POST saves AddonsConfig fields and redirects back to the form URL
  • test_post_updates_partial_search_settings — POST correctly handles partial field updates

Two bugs were also fixed while writing the tests: missing PrivateViewMixin on the view, and a crash in get_success_url() when self.object became an AddonsConfig after form save.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants