Add missing test coverage for full text search filter#9949
Add missing test coverage for full text search filter#9949browniebroke merged 2 commits intoencode:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds PostgreSQL-aware CI configuration and introduces new tests to cover DRF’s SearchFilter full-text search (@-prefixed fields), aligning the test suite with upcoming Postgres-specific search behavior (referenced in #9385).
Changes:
- Add PostgreSQL-backed full-text search tests for
SearchFilterusing a newrequires_postgrespytest marker. - Update test configuration to support
DATABASE_URLviadj-database-url, and auto-skip Postgres-only tests when not on PostgreSQL. - Update GitHub Actions workflow to run the test matrix against a Postgres service.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
tests/test_filters.py |
Adds Postgres-only full-text search test coverage and a construct_search regression test for @ prefix. |
tests/conftest.py |
Adds DATABASE_URL support and a collection-time skip mechanism for Postgres-only tests. |
pyproject.toml |
Adds dj-database-url test dependency and registers the requires_postgres marker. |
.github/workflows/main.yml |
Runs CI tests against a Postgres service and sets DATABASE_URL in the job environment. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| databases = { | ||
| 'default': dj_database_url.config(), | ||
| 'secondary': dj_database_url.config(), |
There was a problem hiding this comment.
When DATABASE_URL is set, both the default and secondary database aliases are configured with the exact same connection info. On PostgreSQL, Django will attempt to create a separate test database per alias, and identical NAME/settings can cause test database creation/teardown to collide. Configure secondary as a TEST mirror of default (or give it a distinct TEST/NAME) so multi-db tests can run reliably on Postgres.
| databases = { | |
| 'default': dj_database_url.config(), | |
| 'secondary': dj_database_url.config(), | |
| default_database = dj_database_url.config() | |
| secondary_database = default_database.copy() | |
| secondary_database['TEST'] = {'MIRROR': 'default'} | |
| databases = { | |
| 'default': default_database, | |
| 'secondary': secondary_database, |
| run: python -m pip install --upgrade tox | ||
|
|
||
| - name: Create unaccent extension | ||
| run: PGPASSWORD=postgres psql -h localhost -U postgres -d postgres -c 'CREATE EXTENSION IF NOT EXISTS unaccent;' |
There was a problem hiding this comment.
This CI step creates the unaccent extension in the postgres database, but Django/pytest will run tests against a newly created test database (e.g. test_postgres), which will not automatically inherit extensions from the original DB. If unaccent is needed for tests, create it in the test DB during test setup (e.g. in a pytest fixture after DB creation) or create it in a template DB used for test DB creation.
| run: PGPASSWORD=postgres psql -h localhost -U postgres -d postgres -c 'CREATE EXTENSION IF NOT EXISTS unaccent;' | |
| run: | | |
| PGPASSWORD=postgres psql -h localhost -U postgres -d template1 -c 'CREATE EXTENSION IF NOT EXISTS unaccent;' | |
| PGPASSWORD=postgres psql -h localhost -U postgres -d postgres -c 'CREATE EXTENSION IF NOT EXISTS unaccent;' |
Description
unaccenttoSearchFilter#9385 as well