Django 1.1 Testing and Debugging.pdf

所需积分/C币:10 2019-08-14 13:19:44 7.25MB PDF
29
收藏 收藏
举报

Table of Contents Preface 1 Chapter 1: Django Testing Overview 9 Getting started: Creating a new application 10 Understanding the sample unit test 10 Understanding the sample doctest 11 Running the sample tests 12 Breaking things on purpose 15 Test errors versus test failures 20 Command line options for running tests 23 Verbosity 24 Settings 27 Pythonpath 27 Traceback 27 Noinput 27 Version 28 Summary 28 Chapter 2: Does This Code Work? Doctests in Depth 29 The Survey application models 29 Testing the Survey model 31 Testing Survey model creation 31 Is that test useful? 34 Developing a custom Survey save method 35 Deciding what to test 39 Some pros and cons of doctests so far 40 Additional doctest caveats 44 Beware of environmental dependence 44 Beware of database dependence 47 Table of Contents [ ii ] Beware of test interdependence 52 Beware of Unicode 57 Summary 62 Chapter 3: Testing 1, 2, 3: Basic Unit Testing 63 Unit tests for the Survey save override method 63 Pros of the unit test version 65 Cons of the unit test version 69 Revisiting the doctest caveats 69 Environmental dependence 70 Database dependence 70 Test interdependence 75 Unicode 75 Providing data for unit tests 76 Providing data in test fixtures 76 Example test that needs test data 76 Using the admin application to create test data 78 Writing the function itself 83 Writing a test that uses the test data 85 Extracting the test data from the database 86 Getting the test data loaded during the test run 87 Creating data during test set up 92 Summary 96 Chapter 4: Getting Fancier: Django Unit Test Extensions 97 Organizing tests 98 Creating the survey application home page 101 Defining the survey application URLs 102 Developing views to serve pages 104 Creating templates for pages 106 Testing the survey home page 110 Creating the survey detail pages 117 Refining the survey detail view 117 Templates for the survey detail pages 118 Basic testing of the
Django 1.1 Testing and Debugging Copyright o 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 Ilowever, the information contained in this book is sold without warranty either express or implied Neither the author nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals However, Packt Publishing cannot guarantee the accuracy of this information First published: April 2010 Production reference: 1120410 Published by Packt Publishing Ltd 32 Lincoln road Olton Birmingham, B27 6PA, UK ISBN978-1-847197-56-6 www.packtpub.com CoverImagebyRajKataria(rajkatarial7@gmail.com) Credits Author Editorial team leader Karen M. Tracey Mithun Sehgal Reviewer Project Team Leader Benjamin A. slavin Priya Mukherji Acquisition Editor Project Coordinator Steven Wilding Leena purkait Development editor Proofreader Neha patwari Aaron nash echnical editor Production coordinator Conrad sardinha Shantanu Agade Indexers Cover Work Hemangini Bari Shantanu agade Rekha nair About the author 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 an 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 Many thanks to steven wilding and the entire packt publishing team for making this book possible Id also like to thank the Django community. The community is too large to name everyone individually, but Jacob Kaplan-Moss, Adrian Ilolovaty, Malcolm Tredinnick, and Russell Keith-Magee deserve special mention. I very much appreciate the tremendous amount of work you all have done to create an excellent framework and foster a helpful and welcoming community Finally thanks to my parents, brothers, and many friends who supported me throughout the writing process. Your encouraging words have been very helpful and much appreciated About the reviewer BEN SLAVIN is an entrepreneur technology strategist, and developer focused on high performance web applications. He has been using Django to build scalable, reliable websites and applications since 2006. As a Director of Technology and a CTO, Ben has successfully integrated Django into multiple businesses operations, reducing technology costs and improving productivity Residing in Washington, DC, Ben has built and operates the Heliograph Network, designed to improve the performance and reliability of web applications. You can findhimonlineathttp://benslavin.net. In memory of mello and Haley Table of contents Preface Chapter 1: Django Testing Overview Getting started: Creating a new application Understanding the sample unit test 9001 Understanding the sample doctest Running the sample tests 12 Breaking things on purpose 15 Test errors versus test failures 20 Command line options for running tests 23 Verbosity 24 Settings 27 Pythonpath 27 Traceback Noinput 27 Version 28 Summary 28 Chapter 2: Does This Code Work? Doctests in Depth 29 The Survey application models 29 Testing the Survey model 31 Testing Survey model creation 31 Is that test useful? 34 Developing a custom Survey save method 35 Deciding what to test 39 Some pros and cons of doctests so far 40 Additional doctest caveats 44 Beware of environmental dependence 44 Beware of database dependence 47

...展开详情
试读 127P Django 1.1 Testing and Debugging.pdf
立即下载 身份认证后 购VIP低至7折
一个资源只可评论一次,评论内容不能少于5个字
您会向同学/朋友/同事推荐我们的CSDN下载吗?
谢谢参与!您的真实评价是我们改进的动力~
  • 技术圈认证

  • 至尊王者

关注 私信
上传资源赚钱or赚积分
最新推荐
Django 1.1 Testing and Debugging.pdf 10积分/C币 立即下载
1/127
Django 1.1 Testing and Debugging.pdf第1页
Django 1.1 Testing and Debugging.pdf第2页
Django 1.1 Testing and Debugging.pdf第3页
Django 1.1 Testing and Debugging.pdf第4页
Django 1.1 Testing and Debugging.pdf第5页
Django 1.1 Testing and Debugging.pdf第6页
Django 1.1 Testing and Debugging.pdf第7页
Django 1.1 Testing and Debugging.pdf第8页
Django 1.1 Testing and Debugging.pdf第9页
Django 1.1 Testing and Debugging.pdf第10页
Django 1.1 Testing and Debugging.pdf第11页
Django 1.1 Testing and Debugging.pdf第12页
Django 1.1 Testing and Debugging.pdf第13页
Django 1.1 Testing and Debugging.pdf第14页
Django 1.1 Testing and Debugging.pdf第15页
Django 1.1 Testing and Debugging.pdf第16页
Django 1.1 Testing and Debugging.pdf第17页
Django 1.1 Testing and Debugging.pdf第18页
Django 1.1 Testing and Debugging.pdf第19页
Django 1.1 Testing and Debugging.pdf第20页

试读结束, 可继续阅读

10积分/C币 立即下载