Mock Data Creation for Development and Testing - bounswe/bounswe2025group10 GitHub Wiki
This page explains how to generate realistic, consistent mock data for local development or testing using our Django backend.
We use a custom Django management command:
python manage.py create_mock_data
It will populate all major database tables with randomly generated data using the Faker library.
| Model | Notes |
|---|---|
| Users | Unique username + email, hashed password, image, bio |
| Posts | Linked to random users |
| Comments | Linked to users + posts, up to N per post |
| Tips | Random text + likes/dislikes |
| Waste Types | Canonical: Plastic, Paper, Glass, Metal |
| UserWastes | Per-user waste tracking across types |
| Achievements | Title + description + icon |
| UserAchievements | Random but unique (user, achievement) pairs |
| Challenges | Public or private; optionally with reward |
| UserChallenge | Public: joined by random users, Private: only creator |
| Reports | (Prepared but optional โ reports on comments) |
- โ
usernameandemailare always unique (viaFaker.unique) - โ
(user_id, achievement_id)and(user_id, challenge_id)pairs are deduplicated to respect DB constraints - โ
Timezone-aware datetimes for all
DateTimeFields - โ
No assumptions about prior database state โ safe to rerun after a
flush
To change dataset size or balance:
- Open
api/management/commands/create_mock_data.py - Edit the parameters in the
generate_mock_data()function call inside thehandle()method.
Example:
generate_mock_data(
num_users=100,
num_posts=1000,
num_max_comments_per_post=7,
num_tips=10,
num_max_wastes_per_user=50,
num_achievements=10,
num_challenges=200,
max_challenge_target_amount=50,
num_reports=50,
)
From the host:
docker exec -it backend-web-1 bash
python manage.py migrate
python manage.py create_mock_data
- If you re-run this without flushing the DB, you may hit uniqueness errors. Either drop/reset the DB or ensure uniqueness manually.
- You can adapt the script to generate edge cases, simulate real user behavior, or run partial generation.