Skip to content

OpenClassrooms educational project — improve a legacy Python web app by adding automated tests, fixing bugs, and tightening code quality (pytest, coverage, black/ruff).

Notifications You must be signed in to change notification settings

Mamath79/webapp-testing-debugging

 
 

Repository files navigation

Python Web App — Testing & Debugging (P11)

Educational project (OpenClassrooms) — improve a legacy Python web application by adding automated tests, fixing bugs, and hardening code quality & observability.


🎯 Objectives

  • ✅ Identify and fix functional/technical bugs
  • ✅ Add unit/integration tests to secure the main flows
  • ✅ Raise coverage and enforce style checks
  • ✅ Improve observability (structured logging, basic error monitoring)
  • ✅ Document setup, decisions, and known limitations

This repository is intended for learning and portfolio demonstration — not production‑ready as‑is.


🧱 Tech stack

  • Python 3.10+
  • Django 4.x (typical stack; adapt if your app uses Flask/FastAPI)
  • pytest + pytest‑django for tests
  • coverage for code coverage
  • black + ruff for formatting/linting
  • Optional: django‑debug‑toolbar, Sentry (or similar) for error tracking

📦 Project structure (example)

.
├─ manage.py
├─ requirements.txt
├─ app_name/                     # main Django app(s)
│  ├─ models.py
│  ├─ views.py
│  ├─ urls.py
│  ├─ forms.py
│  ├─ templates/
│  └─ tests/                     # pytest-style tests live here
├─ config/ (optional)            # settings module if split
│  ├─ settings.py
│  ├─ urls.py
│  └─ wsgi.py/asgi.py
└─ .github/workflows/ci.yml      # GitHub Actions (optional)

Your exact layout may differ; this README focuses on the testing & debugging work.


🚀 Quickstart (local)

1) Clone and create a virtual env

git clone <REPO_URL>
cd <REPO_DIR>
python3 -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt

2) Configure environment

Create a .env file (or export env vars) as needed by your settings:

DEBUG=True
SECRET_KEY=change-me
ALLOWED_HOSTS=127.0.0.1,localhost
DATABASE_URL=sqlite:///./db.sqlite3   # or standard Django DB vars

Do not commit real secrets. In production, set DEBUG=False and proper hosts.

3) Migrate & run

python manage.py migrate
python manage.py runserver 0.0.0.0:8000

Open http://127.0.0.1:8000/


🧪 Tests & coverage

Run tests:

pytest -q

Run coverage:

pytest --cov=. --cov-report=term-missing

Generate HTML report:

coverage html && open htmlcov/index.html  # macOS

If the app uses Django’s test runner, you can also run: python manage.py test.


🧹 Code quality

Format:

black .

Lint:

ruff check .

Type checks (optional):

mypy .

You can wire these into a pre‑commit hook:

pip install pre-commit
pre-commit install

🐞 Debugging toolkit

  • Logging: use Python’s logging with module‑level loggers; log exceptions with context
  • Debug toolbar: django-debug-toolbar in dev to inspect queries and timings
  • Error tracking: Sentry (or equivalent) for crash reports in staging/prod
  • DB inspections: enable connection.queries in dev only; add select‑related/prefetch to cut N+1s

🔧 Notable fixes & improvements (examples)

  • Fix CSRF issues on POST routes
  • Normalize URL patterns; add missing redirects
  • Harden forms/serializers validation
  • Replace raw SQL with ORM queries; parameterize to avoid injections
  • Add 404/500 custom handlers and friendly error pages
  • Optimize slow views (query counts, pagination)

See commit history and issue tracker for the concrete changes applied in this repo.


🛳️ Deployment (outline)

  • Use a managed SQL DB (PostgreSQL recommended)
  • Set DEBUG=False, ALLOWED_HOSTS, proper SECURE_* headers via proxy (Nginx/Traefik)
  • Run with gunicorn + reverse proxy; collect static files if needed:
python manage.py collectstatic --noinput
  • Configure logging to stdout/stderr; aggregate with your platform (CloudWatch, ELK)

📚 Documentation

  • Test strategy & coverage targets
  • Known limitations / TODOs
  • How to reproduce fixed bugs
  • Architecture notes (settings, apps, URLs, templates)

You can keep these in /docs or extend this README.


👤 Author

Mathieu Vieillefont
LinkedIn: https://www.linkedin.com/in/mathieu-vieillefont/
Email: mathieu.vieillefont@gmail.com


📄 License

Provided for educational purposes (OpenClassrooms). Add a license (e.g., MIT) if you plan to reuse.

About

OpenClassrooms educational project — improve a legacy Python web app by adding automated tests, fixing bugs, and tightening code quality (pytest, coverage, black/ruff).

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • HTML 98.7%
  • Python 1.3%