Skip to content

Commit 8751790

Browse files
committed
Scope test_superuser_sees_all_queryset to test-created corpuses
Two VisibleToUserTests.test_superuser_sees_all_queryset cases (in test_visibility_managers.py and test_resolvers.py) asserted a personal- corpus count of 4 (public + private + 2 personal) for the superuser, but the test DB has a pre-existing "My Documents" corpus owned by guardian's AnonymousUser (creator_id=1) created during fixture setup, making the actual count 5. Filter the assertion's queryset to corpuses created by the two test users so it is resilient to any fixture-level corpuses that exist at test DB init time. The unfiltered queryset is still used for the order_by check. Closes #1394
1 parent f40e91f commit 8751790

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Fixed
1111

12+
- **`test_superuser_sees_all_queryset` miscounts personal corpuses by 1** (Issue #1394, `opencontractserver/tests/test_visibility_managers.py`, `opencontractserver/tests/test_resolvers.py`): Two `VisibleToUserTests.test_superuser_sees_all_queryset` cases asserted that `Corpus.objects.visible_to_user(superuser).count() == 4` (public + private + 2 personal), but the actual count is 5 because the test DB starts with a pre-existing personal corpus owned by django-guardian's `AnonymousUser` (created during fixture setup before/around the username-based skip in `opencontractserver/users/signals.py::user_created_signal`). The assertion is now scoped to corpuses created by the test's two users (`creator__in=[self.user, self.superuser]`), making it resilient to any fixture-level corpuses that exist at test DB init time. Production code is unchanged.
1213
- **Merged `frontend` Codecov flag drops to ~33% on every commit where Frontend CI's CT job fails** (`frontend/package.json` `test:coverage:ct`): the script chained `playwright test ... && mkdir -p ... && nyc report ...`, so a failing CT run short-circuited before `nyc report` could turn the per-test JSON files in `.nyc_output` into an `lcov.info`. The downstream `Upload CT Coverage to Codecov` step (`if: success() || failure()`) then errored with "No coverage reports found" and `frontend-component` did not upload for that SHA. Codecov's server-side aggregation of the `frontend` flag was left with only `frontend-unit` (~23%) and `frontend-e2e` (~24%), pulling the merged number down to ~33% even though the previous commit was at ~67% — observed on six consecutive main commits 2026-04-26T01:02..02:58Z (`2d7033f8`..`be5bcfc8`) before recovering on `30298391`. Mirrored the existing `test:e2e:coverage` pattern (`; CT_EXIT=$?; nyc report ... || echo "No coverage data to report"; exit $CT_EXIT`) so `nyc report` runs regardless of test outcome and the lcov ships even on red CT runs. `frontend-component` will still report a slightly lower number when tests fail (failed tests register fewer hits), but it will report — keeping the merged `frontend` flag's denominator stable.
1314
- **`User.__init__` shared-state mutation re-introduced by branch merge** (`opencontractserver/users/models.py:172-180` removed): PR #1374 (commit `50ed6740`) deleted the `User.__init__` override that mutated `Field.validators[0]` on every instantiation, but a subsequent merge (`b68c1cb4 → 6d2cddbf`) resurrected the override along with its mypy-narrowing changes. The current main on commit `6d2cddbf` therefore reproduced the original `#1358` bug: `User(...)` rebound `username_field.validators[0]` and clobbered any third-party validator prepended to the list. Removed the `__init__` override entirely; the class-body declaration `validators=[UserUnicodeUsernameValidator()]` on the `username` field (still present from PR #1374) is the canonical and only declaration. Also dropped the now-unused `Field` import. Regression coverage from PR #1374 (`opencontractserver/tests/test_user_username_validator.py`) was already on main and is what surfaced the regression in CI.
1415

opencontractserver/tests/test_resolvers.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,14 @@ def test_superuser_sees_all_queryset(self):
5959
"""Superusers should see all objects ordered by creation."""
6060
result = Corpus.objects.visible_to_user(self.superuser)
6161

62+
# Filter to corpuses created by this test's users to make the assertion
63+
# resilient to fixture-level personal corpuses (e.g. the one auto-created
64+
# for guardian's AnonymousUser during DB setup). See issue #1394.
65+
scoped = result.filter(creator__in=[self.user, self.superuser])
66+
6267
# Should see both test corpora + 2 personal corpuses (one per user)
6368
# Each user (user, superuser) gets a personal corpus auto-created
64-
self.assertEqual(result.count(), 4) # public + private + 2 personal
69+
self.assertEqual(scoped.count(), 4) # public + private + 2 personal
6570
# Should be ordered by created
6671
self.assertEqual(result.query.order_by, ("created",))
6772

opencontractserver/tests/test_visibility_managers.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,14 @@ def test_superuser_sees_all_queryset(self):
7171
"""Superusers should see all objects ordered by creation."""
7272
result = Corpus.objects.visible_to_user(self.superuser)
7373

74+
# Filter to corpuses created by this test's users to make the assertion
75+
# resilient to fixture-level personal corpuses (e.g. the one auto-created
76+
# for guardian's AnonymousUser during DB setup). See issue #1394.
77+
scoped = result.filter(creator__in=[self.user, self.superuser])
78+
7479
# Should see both test corpora + 2 personal corpuses (one per user)
7580
# Each user (user, superuser) gets a personal corpus auto-created
76-
self.assertEqual(result.count(), 4) # public + private + 2 personal
81+
self.assertEqual(scoped.count(), 4) # public + private + 2 personal
7782
# Should be ordered by created
7883
self.assertEqual(result.query.order_by, ("created",))
7984

0 commit comments

Comments
 (0)