✅ Add test coverage for seed.py management command
- Dominant language
- Python
- Stars
- 2k
- Forks
- 984
- Avg merge
- 2h 54m
- Merged PRs (30d)
- 14
Description
Here’s a GitHub issue you can use to track adding test cases for the seed script:
**Description:**
The `apps/base/management/commands/seed.py` script currently has **0% test coverage**. This script defines a custom Django management command `seed` that delegates execution to the `runscript` command with optional arguments.
We need to add unit tests to ensure proper functionality and prevent regressions.
---
**📂 File:**
`apps/base/management/commands/seed.py`
---
**🔧 Functions to Cover:**
1. `add_arguments`
* **Approach:**
Mock `argparse.ArgumentParser` and assert that `add_argument("-nc", ...)` is called correctly.
2. `handle`
* **Approach:**
Use `unittest.mock.patch` to mock `call_command`.
Test both default behavior (no `-nc`) and custom values (e.g., `--nc 5`) to ensure `call_command("runscript", "seed", "--script-args", )` is called as expected.
---
**✅ Acceptance Criteria:**
* [ ] Test that `-nc` argument is registered in `add_arguments`
* [ ] Test default behavior of `handle` when `-nc` is not provided
* [ ] Test custom behavior of `handle` when `-nc` is specified
* [ ] Achieve > 95% coverage for `seed.py` via `coverage run` and `coverage report`
---
**📌 Notes:**
* Tests should go in a corresponding test file (e.g., `tests/test_seed_command.py` or similar).
* Use Django's `override_settings` and `call_command` utilities as needed.
* Add the test module to the test discovery if not already picked up.
Contributor guide
Assessment
This issue has not been assessed yet.