kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

Replace factory-boy/fake-factory test deps with plain fixtures

Open rtibbles opened this issue 5 months ago • 3 comments

Overview

fake-factory==0.5.7 (test group) is the abandoned former name of faker; its final release 9999.9.9 is a tombstone that raises on import. Dependabot keeps proposing that bump (#14918), which would break the test suite. It survives only as a transitive dep of factory-boy==2.7.0 (2016). Remove both.

Complexity: Low Target branch: develop

Context

  • factory-boy is used in 5 test files (kolibri/core/{auth,logger,public}/test/); the surface to replace is DjangoModelFactory, SubFactory, LazyFunction, Sequence, and PostGenerationMethodCall.

The Change

  • Remove factory-boy and fake-factory from the test dependency group.
  • Replace the 17 factory.DjangoModelFactory subclasses in kolibri/core/{auth,logger,public}/test/ with plain builder helpers that create instances directly (Model.objects.create(...)).
  • Move fixture creation from per-test setUp to class-level setUpTestData (created once per class, rolled back per test — faster).
  • Preserve the SubFactory relationships (e.g. log → user) as helper behaviour.
  • Preserve Sequence-based unique naming as helper behaviour.

Out of Scope

  • Changing test assertions or coverage — the rewrite is behaviour-preserving.
  • Other test-data libraries (e.g. mixer).

Acceptance Criteria

  • [ ] factory-boy and fake-factory removed from pyproject.toml test group and no longer present in uv.lock.
  • [ ] No import factory remains in the codebase.
  • [ ] The 5 affected test modules build fixtures via plain helpers in setUpTestData.
  • [ ] Affected test suites pass (kolibri/core/{auth,logger,public}/test/).
  • [ ] Dependabot PR #14918 closed as obsolete.

References

  • Blocked bump: #14918
  • fake-factory → faker rename: https://faker.readthedocs.io/en/master/#migration-from-fake-factory
  • Django setUpTestData: https://docs.djangoproject.com/en/3.2/topics/testing/tools/#django.test.TestCase.setUpTestData

AI usage

Drafted with Claude Code, which investigated the dependency and its test-suite usage. Direction (drop rather than upgrade; setUpTestData) and final wording are mine.

rtibbles avatar Jul 01 '26 02:07 rtibbles

Plan: Remove the abandoned fake-factory (transitive dep of factory-boy) from the test dependency group by replacing the 17 factory.DjangoModelFactory subclasses in kolibri/core/{auth,logger,public}/test/ with a small in-repo helper, with zero behavior change.

  • [ ] Shared ModelFactory base helper
  • [ ] Rewrite kolibri/core/auth/test/test_api.py factories
  • [ ] Rewrite kolibri/core/logger/test/factory_logger.py factories
  • [ ] Rewrite kolibri/core/auth/test/test_utils.py factories
  • [ ] Rewrite kolibri/core/public/test/test_api.py factories
  • [ ] Swap factory.django.mute_signals in test_picture_passwords.py
  • [ ] Remove the dependency
  • [ ] Full verification sweep

@rtibblesbot's comments are generated by an LLM, and should be evaluated accordingly

How was this generated?
  • Implemented code following the pre-approved plan using test-driven development (red-green-refactor)
  • Ran the project's full test suite and linter before committing
  • For UI changes: captured live screenshots to verify rendering
  • For backend changes: verified with example API/CLI output

rtibblesbot avatar Jul 01 '26 03:07 rtibblesbot

The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.

rtibblesbot avatar Jul 01 '26 06:07 rtibblesbot

The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.

rtibblesbot avatar Jul 01 '26 17:07 rtibblesbot