test(fixtures): factory_boy factories + delegate make_* helpers (#1272)#1319
Open
jonfroehlich wants to merge 1 commit into
Open
test(fixtures): factory_boy factories + delegate make_* helpers (#1272)#1319jonfroehlich wants to merge 1 commit into
jonfroehlich wants to merge 1 commit into
Conversation
First PR slice of #1272 (testing leverage): introduce factory_boy/Faker fixtures as the single source of truth for building model instances, and rewrite the DatabaseTestCase make_* helpers as thin wrappers over them. - Add factory_boy==3.3.3 + Faker==40.23.0 (Testing section of requirements). - New website/tests/factories.py: Person/Project/Video/Publication/Talk/ Poster/NewsItem/Award/ProjectRole factories. Filesystem-light by default (tiny in-memory GIF/stub PDF) so the suite stays fast and skips Person.save()'s Star Wars fallback. No auto-authors: artifacts are authorless unless authors=[...] is passed, preserving the ~200 existing make_publication call sites and keeping authorless paths testable. - base.py make_* helpers now delegate to the factories while preserving their original keyword API (the year=YYYY shorthand, with_thumbnail). - New website/tests/test_factories.py guards the factories: each builds a saved instance, the ProjectRole/M2M/SortedManyToMany graph composes, and the no-auto-authors contract holds. - Move _GIF_1PX to factories.py (its single home); repoint the one importer. Follow-ups (separate PRs, per the issue): seed_dev_data command + curated seed_media/, then pull_prod_subset.sh; #1278 items 4/5/6. Full suite: 211 passing. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This was referenced Jun 17, 2026
Member
Author
|
Merge follow-up: this branch was cut before the docs were touched, so on merge one line in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
First PR slice of #1272 (testing leverage — realistic test data). Introduces
factory_boy+Fakerfixtures as the single source of truth for building model instances, and rewrites theDatabaseTestCase.make_*helpers as thin wrappers over them.What's in this slice
factory_boy==3.3.3+Faker==40.23.0added torequirements.txt(new Testing section).website/tests/factories.py— factories forPerson,Project,Video,Publication,Talk,Poster,NewsItem,Award,ProjectRole.website/tests/base.py—make_*helpers now delegate to the factories, preserving their original keyword API (notably theyear=YYYYshorthand andwith_thumbnail) so the ~200 existing call sites stay unchanged.website/tests/test_factories.py— 10 tests guarding the factories themselves._GIF_1PXmoved tofactories.py(single home); the one importer (test_easter_egg_picker.py) repointed.Two design decisions
base.pyalready used. Keeps the DB suite fast and skipsPerson.save()'s Star Wars fallback (which reads a real file off disk). Curated realseed_media/is deferred to the layer-2 follow-up where exercising real thumbnail/crop/PDF paths actually matters.Publication/Talk/Posterfactories create authorless artifacts unlessauthors=[...]is passed. This keeps the existingmake_publicationcall sites behavior-identical (they add authors explicitly) and preserves authorless-path coverage. The issue's example showed auto-3-authors; diverging is documented in the factory docstring.seed_dev_datacan passauthors=PersonFactory.create_batch(n).Why
Foundation for #1278 item 5 (backfill high-risk untested code) and #1272 layer 2 (realistic local dev data). Building the connected
ProjectRole/M2M/SortedManyToManyFieldgraph is now one line instead of twenty, so future test-writing and data-seeding get much cheaper. No production behavior changes — pure test infrastructure.Testing
python manage.py test website --settings=makeabilitylab.settings_test.factory_boy/Fakerfresh fromrequirements.txt.Follow-ups (separate PRs, per the issue)
seed_dev_datamanagement command + curatedseed_media/scripts/pull_prod_subset.shNote for local dev
A
requirements.txtchange needs a rebuild to persist locally:./run-docker-local-dev.sh --build. (Ipip install'd into the running container to validate this branch.)🤖 Generated with Claude Code