Skip to content

Add test coverage for masoniteorm make and seed console commands#155

Open
tmgbedu wants to merge 1 commit into
mainfrom
task/masoniteorm-commands-coverage-718
Open

Add test coverage for masoniteorm make and seed console commands#155
tmgbedu wants to merge 1 commit into
mainfrom
task/masoniteorm-commands-coverage-718

Conversation

@tmgbedu

@tmgbedu tmgbedu commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds unit tests for the previously untested Cleo database commands under fastapi_startkit/src/fastapi_startkit/masoniteorm/commands/, addressing the low Codecov coverage on that package (task #718).

Coverage for the masoniteorm/commands package rises to ~84% (from the make/seed commands being near 0%).

What's covered

  • test_make_commands.pydb:make:migration, db:make:model, seed (make seeder), observer
    • Verifies command wiring, argument/option parsing (--create, --table, --directory, --pep, --model), the generated file contents, and the "already exists" guard paths.
    • Each generator runs inside an isolated temp working directory so no files leak into the repo.
  • test_db_seed_command.pydb:seed
    • Exercises the default database-seed path, the table argument, and the --class variants (plain name, TableSeeder suffix, dotted path), plus --connection/--directory forwarding.
    • Uses a fake Seeder that records constructor args and awaited methods, mocking DB side effects.
  • test_migrate_commands.py — adds a db:migrate:refresh test asserting the reset + re-migrate path.

Testing

  • uv run pytest tests/masoniteorm/commands/ --cov=src/fastapi_startkit/masoniteorm/commands → 32 passed, 1 skipped
  • Full suite (excluding Postgres): uv run pytest --ignore=tests/masoniteorm/postgres → 1618 passed, 7 skipped

Notes

  • MakeModelDocstringCommand is left uncovered: its handle() relies on the legacy load_config() / a non-existent config option and is non-functional in the current framework (same situation as the already-skipped ShellCommand.handle() test).

Cover the previously untested Cleo commands in
masoniteorm/commands: db:make:migration, db:make:model, seed
(make seeder), observer, db:seed and db:migrate:refresh.

Generator commands are exercised in an isolated temp working
directory and assert on the emitted files and CLI output.
db:seed is tested with a fake Seeder that records constructor
args and awaited methods, mocking database side effects while
verifying argument/option parsing and the handle path.
@codecov

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@tmgbedu

tmgbedu commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

Code Review Verdict: APPROVE ✅ (posted as comment — GH blocks self-approval)

Test-only PR (279 additions, 0 deletions). Verified against real command implementations.

Correctness: Tests assert real behavior. DBSeedCommand's call-time from ..seeds import Seeder means the mock.patch('...seeds.Seeder', FakeSeeder) correctly intercepts; all seeder-file resolutions and output strings match real logic. Make commands run in isolated temp cwd and assert generated filenames + real file contents. MigrateRefresh asserts rollback + remigrate.

Side effects isolated: No live DB (Seeder mocked), no real file writes (temp cwd + cleanup). git status confirms no leaked artifacts.

Coverage/CI: Commands package 84%; full suite 1618 passed / 7 skipped; total 68.59% ≥ 68%. CI green (Pytest ✅ Ruff ✅ codecov/patch ✅).

MakeModelDocstringCommand exclusion — acceptable: handle() references an undeclared config option + legacy load_config, so it's non-functional (errors on any call). Consistent with the already-skipped ShellCommand.handle. Recommend a separate bug ticket to fix/remove it — out of scope here, not a blocker.

Minor (non-blocking): could add explicit tester.status_code == 0 asserts to harden exit-code checks.

Do NOT merge — approval only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant