Django 1.1 Testing and Debugging


Django 1.1 Testing and Debugging
eBook: $29.99
Formats: PDF, PacktLib, ePub and Mobi formats
$25.49
save 15%!
Print + free eBook + free PacktLib access to the book: $79.98    Print cover: $49.99
$49.99
save 37%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Overview
Table of Contents
Author
Reviews
Support
Sample Chapters

Develop Django applications quickly with fewer bugs through effective use of automated testing and debugging tools. Ensure your code is accurate and stable throughout development and production by using Django's test framework. Understand the working of code and its generated output with the help of debugging tools. Packed with detailed working examples that illustrate the techniques and tools for debugging

Book Details

Language : English
Paperback : 436 pages [ 235mm x 191mm ]
Release Date : April 2010
ISBN : 1847197566
ISBN 13 : 9781847197566
Author(s) : Karen M. Tracey
Topics and Technologies : All Books, App Testing, Web Development, Open Source, Web Development


Table of Contents

Preface
Chapter 1: Django Testing Overview
Chapter 2: Does This Code Work? Doctests in Depth
Chapter 3: Testing 1, 2, 3: Basic Unit Testing
Chapter 4: Getting Fancier: Django Unit Test Extensions
Chapter 5: Filling in the Blanks: Integrating Django and Other Test Tools
Chapter 6: Django Debugging Overview
Chapter 7: When the Wheels Fall Off: Understanding a Django Debug Page
Chapter 8: When Problems Hide: Getting More Information
Chapter 9: When You Don't Even Know What to Log: Using Debuggers
Chapter 10: When All Else Fails: Getting Outside Help
Chapter 11: When it's Time to Go Live: Moving to Production
Index
  • Chapter 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
  • Chapter 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
  • Chapter 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
  • Chapter 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
  • Chapter 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
  • Chapter 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
  • Chapter 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
  • Chapter 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
  • Chapter 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
  • Chapter 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
  • Chapter 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

Karen M. Tracey

    Karen has a PhD in Electrical/Computer Engineering from the University of Notre Dame. Her research there focused on distributed operating systems, which led to work in industry centered on communications protocols and middleware. Outside of work she has an interest in puzzles, which led her to take up crossword construction. She has published nearly 100 puzzles in The New York Times, The Los Angeles Times syndicate, The New York Sun, and USA Today. She amassed a database of thousands of puzzles to aid in constructing and cluing her own puzzles. The desire to put a web frontend on this database is what led her to Django. She was impressed by the framework and its community, and became an active core framework contributor. Karen is one of the most prolific posters on the Django users mailing list. Her experience in helping hundreds of people there guided her in choosing the best and most useful material to include in this book.            

The book doesn't just explain how to test, it also explains when and what to test too, so it serves as an ideal introduction into testing in general. Read more I recommend it for anyone who’s doing Django development out there and would like to improve the quality of their applications by adding (more) tests!. Read more

Code Downloads

Download the code and support files for this book.


Submit Errata

Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.


Errata

- 6 submitted: last submission 02 Aug 2013

Errata type: Others | Page number: 283 | Errata date: 05 Sep 2011 Add the following code to the log_view class class: __name__ = 'some name'  

Errata type: Code | Page number: 121 Line "It takes the same arguments as assertTempalteUsed." should read "It takes the same arguments as assertTemplateUsed." instead.  

Errata type: Code | Page number: 244 The line "...block inside an {% if sql_qureies %}..." should read as "...block inside an {% if sql_queries %}..." instead.  

Errata type: Typo | Page number: 334 The part "...then emtpy is set to..." should read "...then empty is set to..." instead.  

Errata type: Code | Page number: 64 "...create a TestCase within the suvery/tests.py file," should read "...create a TestCase within the survey/tests.py file,"...  

Errata type: Code | Page number: 122

In the code block, the first string in the ValidationError call has an extra comma in it. It should be: raise forms.ValidationError("Opens date cannot come "

Sample chapters

You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

Frequently bought together

Django 1.1 Testing and Debugging +    VMware ESXi Cookbook =
50% Off
the second eBook
Price for both: $43.05

Buy both these recommended eBooks together and get 50% off the cheapest eBook.

What you will learn from this book

Build a complete application in manageable pieces that can be written, tested, and debugged individually. Come to grips with the nuances of testing and the pros and cons of each type of test Simplify the task of testing web applications by using specific test extensions provided by Django. Integrate other test tools into Django's framework to obtain test coverage information and more easily test forms. Analyze the copious debug information provided by Django's debug error pages. Write your own add-on debugging aids. Easily acquire enormous and important information with the help of external tools such as the Django debug toolbar. Decipher code behavior by using logging and effectively debug problems in production, when debug error pages are not available. Learn what your code and other library support code actually does by skilled use of a debugger. Tackle problems external to your code with available fixes. Debug common problems that arise during the move from development to production.

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.

Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software