E-book details

Django 1.1 Testing and Debugging. Building rigorously tested and bug-free Django applications

Django 1.1 Testing and Debugging. Building rigorously tested and bug-free Django applications

Karen M. Tracey, Karen Tracey, Jacob Kaplan-Moss

Ebook
Bugs are a time consuming burden during software development. Django's built-in test framework and debugging support help lessen this burden. This book will teach you quick and efficient techniques for using Django and Python tools to eradicate bugs and ensure your Django application works correctly. This book will walk you step by step through development of a complete sample Django application. You will learn how best to test and debug models, views, URL configuration, templates, and template tags. This book will help you integrate with and make use of the rich external environment of test and debugging tools for Python and Django applications. The book starts with a basic overview of testing. It will highlight areas to look out for while testing. You will learn about different kinds of tests available, and the pros and cons of each, and also details of test extensions provided by Django that simplify the task of testing Django applications. You will see an illustration of how external tools that provide even more sophisticated testing features can be integrated into Django's framework. On the debugging front, the book illustrates how to interpret the extensive debugging information provided by Django's debug error pages, and how to utilize logging and other external tools to learn what code is doing.
  • Django 1.1 Testing and Debugging
    • Table of Contents
    • Django 1.1 Testing and Debugging
    • Credits
    • About the Author
    • About the Reviewer
    • Preface
      • What this book covers
      • What you need for this book
      • Who this book is for
      • Conventions
      • Reader feedback
      • Customer support
        • Errata
        • Piracy
        • Questions
    • 1. Django Testing Overview
      • Getting started: Creating a new application
      • Understanding the sample unit test
      • Understanding the sample doctest
      • Running the sample tests
      • Breaking things on purpose
      • Test errors versus test failures
      • Command line options for running tests
        • Verbosity
        • Settings
        • Pythonpath
        • Traceback
        • Noinput
        • Version
      • Summary
    • 2. Does This Code Work? Doctests in Depth
      • The Survey application models
      • Testing the Survey model
        • Testing Survey model creation
        • Is that test useful?
        • Developing a custom Survey save method
        • Deciding what to test
        • Some pros and cons of doctests so far
      • Additional doctest caveats
        • Beware of environmental dependence
        • Beware of database dependence
        • Beware of test interdependence
        • Beware of Unicode
      • Summary
    • 3. Testing 1, 2, 3: Basic Unit Testing
      • Unit tests for the Survey save override method
        • Pros of the unit test version
        • Cons of the unit test version
      • Revisiting the doctest caveats
        • Environmental dependence
        • Database dependence
        • Test interdependence
        • Unicode
      • Providing data for unit tests
        • Providing data in test fixtures
          • Example test that needs test data
          • Using the admin application to create test data
        • Writing the function itself
          • Writing a test that uses the test data
          • Extracting the test data from the database
          • Getting the test data loaded during the test run
        • Creating data during test set up
      • Summary
    • 4. Getting Fancier: Django Unit Test Extensions
      • Organizing tests
      • Creating the survey application home page
        • Defining the survey application URLs
        • Developing views to serve pages
        • Creating templates for pages
        • Testing the survey home page
      • Creating the survey detail pages
        • Refining the survey detail view
        • Templates for the survey detail pages
        • Basic testing of the survey detail pages
      • Customizing the admin add and change survey pages
        • Developing a custom survey form
        • Configuring admin to use the custom form
        • Testing the admin customization
      • Additional test support
        • Supporting additional HTTP methods
        • Maintaining persistent state
        • E-mail services
        • Providing test-specific URL configuration
        • Response context and template information
      • Testing transactional behavior
      • Summary
    • 5. Filling in the Blanks: Integrating Django and Other Test Tools
      • Problems of integration
        • Specifying an alternative test runner
        • Creating a new management command
      • How much of the code are we testing?
        • Using coverage standalone
        • Integrating coverage into a Django project
      • The twill web browsing and testing tool
        • Using the twill command line program
        • Using twill in a TestCase
      • Summary
    • 6. Django Debugging Overview
      • Django debug settings
        • The DEBUG and TEMPLATE_DEBUG settings
        • The TEMPLATE_STRING_IF_INVALID setting
      • Debug error pages
      • Database query history
      • Debug support in the development server
      • Handling problems in production
        • Creating general error pages
        • Reporting production error information
          • Internal server error notifications
          • Page not found notifications
      • Summary
    • 7. When the Wheels Fall Off: Understanding a Django Debug Page
      • Starting the Survey voting implementation
        • Creating test data for voting
        • Defining a question form for voting
        • Debug page #1: TypeError at /
      • Elements of the debug page
        • Basic error information
        • Traceback
        • Request information
          • GET
          • POST
          • FILES
          • COOKIES
          • META
        • Settings
      • Understanding and fixing the TypeError
      • Handling multiple Survey questions
        • Creating the data for multiple questions
        • Coding support for multiple questions
        • Debug page #2: TemplateSyntaxError at /1/
        • Understanding and fixing the TemplateSyntaxError
      • Recording Survey responses
        • Coding support for recording Survey responses
        • Debug page #3: NoReverseMatch at /1/
        • Understanding and fixing the NoReverseMatch exception
        • Debug page #4: TemplateDoesNotExist at /thanks/1/
        • Understanding and fixing TemplateDoesNotExist
      • Handling invalid Survey submissions
        • Coding custom error message and placement
        • Debug page #5: Another TemplateSyntaxError
        • Fixing the second TemplateSyntaxError
      • Summary
    • 8. When Problems Hide: Getting More Information
      • Tracking SQL queries for a request
        • Settings for accessing query history in templates
        • SQL queries for the home page
        • Packaging the template query display for reuse
        • Testing the repackaged template code
        • SQL queries for the active Survey form display page
        • SQL queries for posting survey answers
      • The Django Debug Toolbar
        • Installing the Django Debug Toolbar
        • Debug toolbar appearance
        • The SQL panel
        • The Time panel
        • The Settings panel
        • The HTTP Headers panel
        • The Request Vars panel
        • The Templates panel
        • The Signals panel
        • The Logging panel
        • Redirect handling by the debug toolbar
      • Tracking internal code state
        • Resist the urge to sprinkle prints
        • Simple logging configuring for development
        • Deciding what to log
        • Decorators to log function entry and exit
        • Applying the decorators to the Survey code
        • Logging in the debug toolbar
      • Summary
    • 9. When You Dont Even Know What to Log: Using Debuggers
      • Implementing the Survey results display
      • Results display using pygooglechart
      • Getting started with the debugger
        • The list command
        • The where command
        • The args command
        • The whatis command
        • The print and pp commands
      • Debugging the pygooglechart results display
        • The step and next commands
        • The continue command
        • The jump command
        • The break command
        • The clear command
      • Fixing the pygooglechart results display
        • The up and down commands
        • The return command
      • Results display using matplotlib
      • Improving the matplotlib approach
        • Setting up static file serving
        • Dynamically generating image files
        • Dealing with race conditions
        • Using the debugger to force race situations
      • Notes on using graphical debuggers
      • Summary
    • 10. When All Else Fails: Getting Outside Help
      • Tracking down a problem in Django
        • Revisiting the Chapter 7 voting form
        • Is the right code actually running?
        • Is the code correct as per the documentation?
        • Searching for a matching problem report
        • Another way to search for a matching problem report
        • Determining the release that contains a fix
        • What if a fix hasn't been released yet?
        • What if a fix hasn't been committed yet?
        • What if a ticket has been closed without a fix?
      • Tracking down unreported problems
        • Where to ask questions
        • Tips on asking questions that will get good answers
        • Opening a new ticket to report a problem
      • Summary
    • 11. When it's Time to Go Live: Moving to Production
      • Developing an Apache/mod_wsgi configuration
        • Creating the WSGI script for the marketr project
        • Creating an Apache VirtualHost for the marketr project
        • Activating the new Apache configuration
        • Debugging the new Apache configuration
        • Configuring Apache to serve static files
      • Testing multithreaded behavior
        • Generating load with siege
        • Load testing the results recording code
        • Fixing the results recording code
        • Additional load testing notes
      • Using Apache/mod_wsgi during development
      • Summary
    • Index
  • Title: Django 1.1 Testing and Debugging. Building rigorously tested and bug-free Django applications
  • Author: Karen M. Tracey, Karen Tracey, Jacob Kaplan-Moss
  • Original title: Django 1.1 Testing and Debugging. Building rigorously tested and bug-free Django applications
  • ISBN: 9781847197573, 9781847197573
  • Date of issue: 2010-04-19
  • Format: Ebook
  • Item ID: e_3b5w
  • Publisher: Packt Publishing