Skip to content

test: build booking fixtures with frappe_factory_bot factories - #393

Open
harshtandiya wants to merge 3 commits into
developfrom
chore/refactor-tests
Open

test: build booking fixtures with frappe_factory_bot factories#393
harshtandiya wants to merge 3 commits into
developfrom
chore/refactor-tests

Conversation

@harshtandiya

Copy link
Copy Markdown
Collaborator

What changed

Fixture setup in the backend suite is duplicated everywhere — test_buzz_coupon_code.py
has 74 raw frappe.get_doc({...}) call sites, test_event_booking.py 68 — and an informal
factory layer has already grown by accident. test_buzz_team.py is imported by ten other
test files for create_user / create_owned_team, and payload_for is a per-doctype
default_attributes table in all but name.

This adopts frappe_factory_bot properly, on one module first. buzz/api/booking/test_booking.py
is the tracer bullet: its setUpClass builds the whole association chain, so converting it
exercises every factory added here. −118/+31 lines in that file.

  • buzz/tests/factories/ — User, Buzz Team, Event Category, Event Host, Buzz Event,
    Event Ticket Type, Ticket Add-on.
  • CI installs the app via bench get-app in setup-bench. No install-app (it ships no
    DocTypes, only a Python import), and deliberately not in required_apps — production
    Buzz should not carry a test library.
  • A writing-tests skill documenting the conventions and the traps below.

Three Frappe-level traps, all found the hard way, all now in the skill:

  • A team inserted plainly as Administrator becomes Administrator's default team for every
    later run on that site — create_default_team_for takes the first enabled Owner
    membership, and process_booking commits, so the row survives rollback. setup_test_records()
    then fails with Venue Test Venue belongs to another team. Hence BuzzTeamFactory.create_owned_by().
  • User.throttle_user_creation throws past 60 new users an hour. Test users are not rolled
    back, so minting a fresh one per fixture trips it after a couple of runs. Hence
    UserFactory.create_once() for fixed identities.
  • Faker's unique only dedupes within a process. Prompt-autonamed rows are the primary key
    and outlive the run, so Event Category and Event Host suffix with frappe.generate_hash.

Not changed: frappe_factory_bot itself needed nothing — the flags passthrough already
carries both owner_user and ignore_permissions. Event Booking, Offline Payment Method and
Buzz Coupon Code get no factory yet; nothing here would exercise them, so they land with the
batch that does. The old helpers in test_buzz_team.py / test_forms.py stay — twelve files
still import them, and they retire as each module converts.

Testing

bench --site testbuzz.localhost run-tests --app buzz — 670 tests, 0 failures, green on
repeated back-to-back runs (the cross-run collisions above only surface on the second and
third run). Two consecutive full runs created 3 users total, so CI's fresh site is nowhere
near the throttle.

🤖 Generated with Claude Code

https://claude.ai/code/session_016dbs2RcPoTwFTM2JTE386q

Fixture setup in the backend suite is duplicated everywhere, and an informal
factory layer has already grown by accident: test_buzz_team.py is imported by
ten other test files for create_user / create_owned_team, and payload_for is a
per-doctype default_attributes table in all but name.

Adopt frappe_factory_bot properly, on one module first. buzz/api/booking/
test_booking.py is the tracer bullet: its setUpClass builds the whole
association chain, so converting it exercises every factory added here.

- Add buzz/tests/factories/ with factories for User, Buzz Team, Event Category,
  Event Host, Buzz Event, Event Ticket Type and Ticket Add-on.
- Install frappe_factory_bot in CI via bench get-app. No install-app: the app
  ships no DocTypes, only a Python import. Deliberately not in required_apps,
  since production does not need a test library.
- Add the writing-tests skill documenting the conventions and the traps below.

Three Frappe-level traps the factories have to work around, all found the hard
way and written into the skill:

- A team inserted plainly as Administrator becomes Administrator's default team
  for every later run on that site, because create_default_team_for takes the
  first enabled Owner membership and process_booking commits, so the row
  survives rollback. setup_test_records() then fails with "Venue Test Venue
  belongs to another team." Hence BuzzTeamFactory.create_owned_by().
- User.throttle_user_creation throws past 60 new users an hour. Test users are
  not rolled back, so minting a fresh one per fixture trips it after a couple of
  runs. Hence UserFactory.create_once() for fixed identities.
- Faker's unique only dedupes within a process. Prompt-autonamed rows are the
  primary key and outlive the run that made them, so Event Category and Event
  Host suffix with frappe.generate_hash instead.

No change to frappe_factory_bot was needed: the flags passthrough already
carries both owner_user and ignore_permissions.

Event Booking, Offline Payment Method and Buzz Coupon Code get no factory yet.
Nothing here would exercise them; they land with the batch that does.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016dbs2RcPoTwFTM2JTE386q
@harshtandiya harshtandiya added the skip-demo Skip adding a video / screenshot in PR description. Passes the failing CI for demo addition label Aug 27, 2026
@greptile-apps

greptile-apps Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR introduces reusable frappe_factory_bot fixtures and converts the booking API tests to use them.

  • Adds factories for users, teams, events, categories, hosts, ticket types, and add-ons.
  • Pins the test-only factory dependency to a reviewed commit during bench setup.
  • Documents fixture conventions and safeguards for repeatable Frappe tests.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
.github/actions/setup-bench/action.yml The previously mutable test dependency is now cloned and checked out at an immutable commit before bench installation.
buzz/api/booking/test_booking.py Booking test fixture setup is consolidated onto the new factories while preserving the tested booking and permission scenarios.
buzz/tests/factories/buzz_event_factory.py Adds a published online-event factory that creates or reuses the required team, category, and host associations.
buzz/tests/factories/buzz_team_factory.py Adds team fixtures with explicit reusable ownership to avoid persistent Administrator-owned test teams.
buzz/tests/factories/user_factory.py Adds reusable fixed-identity users to avoid repeated creation and Frappe throttling.
buzz/tests/factories/event_category_factory.py Adds collision-resistant prompt-named category fixtures.
buzz/tests/factories/event_host_factory.py Adds collision-resistant host fixtures associated with an appropriate team.
buzz/tests/factories/event_ticket_type_factory.py Adds free and paid ticket-type fixtures with optional event reuse.
buzz/tests/factories/ticket_add_on_factory.py Adds free and paid add-on fixtures with optional event reuse.

Reviews (3): Last reviewed commit: "ci: pin frappe_factory_bot to a reviewed..." | Re-trigger Greptile

Comment thread .github/actions/setup-bench/action.yml Outdated
harshtandiya and others added 2 commits August 28, 2026 17:37
The CI bench setup pulled the factory app from its default branch, so upstream
drift could break setup or factory imports without any Buzz change, and an
unreviewed revision would run in CI. The repo carries no tags and
`bench get-app --branch` forwards to `git clone --branch`, which rejects a SHA,
so clone and check out the commit first and hand bench the local path.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012BsQrw3T6rYENg46pDJivL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-demo Skip adding a video / screenshot in PR description. Passes the failing CI for demo addition

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant