Django 1.1 Testing and Debugging
eBook - ePub

Django 1.1 Testing and Debugging

  1. 436 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Django 1.1 Testing and Debugging

Book details
Book preview
Table of contents
Citations

About This Book

In Detail

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.

A step-by-step guide to running tests using Django's test support and making best use of Django and Python debugging tools

Approach

This book teaches by example. It walks in detail through development of a sample application, illustrating each step via complete working code and either screenshots or console snippets. The cumbersome and time consuming task of debugging will be a cake walk with this book.

Who this book is for

If you are a Django application developer who wants to create robust applications quickly that work well and are easy to maintain in the long term, this book is for you. This book is the right pick if you want to be smartly tutored to make best use of Django's rich testing and debugging support and make testing an effortless task.Basic knowledge of Python, Django, and the overall structure of a database-driven web application is assumed. However, the code samples are fully explained so that even beginners who are new to the area can learn a great deal from this book.

Frequently asked questions

Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes, you can access Django 1.1 Testing and Debugging by Karen M. Tracey in PDF and/or ePUB format, as well as other popular books in Computer Science & Application Development. We have over one million books available in our catalogue for you to explore.

Information

Year
2010
ISBN
9781847197566
Edition
1

Django 1.1 Testing and Debugging

Karen M. Tracey


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 Don't 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

Django 1.1 Testing and Debugging

Copyright © 2010 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author nor Packt Publishing,...

Table of contents

  1. Django 1.1 Testing and Debugging