Skip to content

Add end-to-end tests for Django tutorial integration - #2324

Closed
okiemute04 wants to merge 3 commits into
django-commons:mainfrom
okiemute04:test-2213-tutorial-integration
Closed

Add end-to-end tests for Django tutorial integration#2324
okiemute04 wants to merge 3 commits into
django-commons:mainfrom
okiemute04:test-2213-tutorial-integration

Conversation

@okiemute04

Copy link
Copy Markdown

Description

Fixes #2213 - Add end-to-end tests that verify the Django Debug Toolbar works with the official Django tutorial.

Problem

The Django Debug Toolbar is an essential tool for beginners learning Django through the official tutorial. However, there's currently no automated testing to ensure that the toolbar doesn't break any tutorial functionality or that the tutorial steps work correctly with the toolbar enabled.

Solution

Created a complete Django tutorial project (polls app) and comprehensive end-to-end tests that verify the toolbar works at each stage of the tutorial.

Implementation Details:

  1. Complete Tutorial Project (tests/tutorial_project/)

    • Full polls app following official Django tutorial
    • Models (Question and Choice) with proper relationships
    • Admin interface customization
    • Class-based views (IndexView, DetailView, ResultsView)
    • Function-based vote view with error handling
    • Templates for all views
    • URL configurations matching the tutorial
  2. Comprehensive Tests covering tutorial Parts 1-4:

    • Part 1 (Models) : Creating questions and choices
    • Part 2 (Admin) : Admin interface accessibility
    • Part 3 (Views) : Index and detail views with toolbar presence
    • Part 4 (Forms) : Voting functionality and error handling

Testing

All 5 tests pass successfully:

$ pytest tests/test_tutorial_project_integration.py -v
================== test session starts ==================
collected 5 items

tests/test_tutorial_project_integration.py::TestTutorialProjectIntegration::test_part1_models PASSED [ 20%]
tests/test_tutorial_project_integration.py::TestTutorialProjectIntegration::test_part2_admin_access PASSED [ 40%]
tests/test_tutorial_project_integration.py::TestTutorialProjectIntegration::test_part3_views_with_toolbar PASSED [ 60%]
tests/test_tutorial_project_integration.py::TestTutorialProjectIntegration::test_part4_forms_and_voting PASSED [ 80%]
tests/test_tutorial_project_integration.py::TestTutorialProjectIntegration::test_invalid_vote_handling PASSED [100%]

================== 5 passed in 1.11s ====================

Key Test Coverage

  • Models: Verify Question and Choice creation, relationships, and string representations
  • Admin: Confirm admin interface loads (redirects to login as expected)
  • Toolbar Presence: Debug toolbar appears on all tutorial pages (index, detail, results)
  • Voting Flow: Complete voting process works with toolbar enabled
  • Error Handling: Proper error message when voting without selecting a choice
  • HTML Escaping: Handles escaped characters in error messages correctly

Benefits

  • Catches Regressions: Prevents changes that would break the tutorial experience
  • Beginner-Focused: Ensures new Django users have a smooth experience
  • Documentation: Tests serve as living documentation of expected behavior
  • Confidence: Provides assurance when making changes to the codebase
  • Maintainability: Makes it easier to refactor without breaking tutorial compatibility

Implementation Notes

  • Uses timezone-aware datetimes to avoid deprecation warnings
  • Properly handles HTML escaping in error messages (' vs ')
  • Sets up Django settings programmatically for tests
  • Adds tutorial project to Python path dynamically

Future Work

  • Could be extended to cover Parts 5-7 (testing, static files, custom admin)
  • Could add more edge cases (future questions, past questions, etc.)

Checklist

  • Added tests
  • Updated code
  • All tests pass
  • No breaking changes
  • Follows tutorial exactly

- Created complete polls app following official Django tutorial
- Added tests for Parts 1-4 (models, admin, views, forms, voting)
- Verified debug toolbar appears on all tutorial pages
- Tests cover edge cases and error handling
- Ensures beginners following tutorial won't encounter toolbar issues

Fixes django-commons#2213

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is already an example project in the package you should use that

Comment thread tests/tutorial_project/db.sqlite3 Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should not have been commited

@okiemute04 okiemute04 Mar 12, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review @JohananOppongAmoateng! I'll update the PR to:

  1. Remove the SQLite database file

  2. Remove the migration files

  3. Recreate the tests using the existing example project

- Remove database file
- Remove migration files
- Update gitignore
@okiemute04
okiemute04 force-pushed the test-2213-tutorial-integration branch from b034aa6 to c452fb1 Compare March 13, 2026 09:32
@okiemute04

Copy link
Copy Markdown
Author

@JohananOppongAmoateng I've removed the database and migration files as requested. Thanks so much!

@tim-schilling

Copy link
Copy Markdown
Member

Hi @okiemute04 I'm closing this PR as it seems to stray too far in the direction of using LLM output for every aspect of contributing. This is based on all the PRs (#2321, #2323, #2324) you've created. If you're willing to come back to interact with more of your self, we would be open to collaborating with you. I've written more about this challenge here.

@okiemute04

Copy link
Copy Markdown
Author

@tim-schilling Thank you so much for the honest feedback.... I understand the concern. I've been using AI tools to help structure my contributions, but I see now that it's made my work feel inauthentic. I genuinely want to contribute to this project and learn from the community and the process.

I'd like to rework these PRs with my own voice and understanding. Would it be acceptable to reopen them? I'm committed to doing the work myself and learning from the process. I am sorry, I take accountability, and I am willing to do the work and contribute authentically.

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.

Create end to end test that covers the official tutorial integration

3 participants