Mock Data Creation for Development and Testing - bounswe/bounswe2025group10 GitHub Wiki

๐ŸŒฑ Mock Data Generation Guide

This page explains how to generate realistic, consistent mock data for local development or testing using our Django backend.


๐Ÿ”ง Command

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.


๐Ÿ“ฆ What Gets Populated

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)

โš ๏ธ Constraints & Safeguards

  • โœ… username and email are always unique (via Faker.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

๐Ÿ›  Configuration

To change dataset size or balance:

  1. Open api/management/commands/create_mock_data.py
  2. Edit the parameters in the generate_mock_data() function call inside the handle() 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,
)

๐Ÿณ Docker Workflow

From the host:

docker exec -it backend-web-1 bash
python manage.py migrate
python manage.py create_mock_data

๐Ÿงช Good to Know

  • 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.
โš ๏ธ **GitHub.com Fallback** โš ๏ธ