Python Web Development: Test-Driven Approach cover

Python Web Development: Test-Driven Approach

Rating 3.9
Chapters
28
Series
Turing Programming Series
ISBN
9787115403278

Tags

Summary

This book is the Chinese translation of Test-Driven Development with Python (2015, Posts & Telecom Press, Turing Programming Series, translated by An Dao). In the tone of pair programming, the author Harry J. W. Percival leads the reader to build a real to-do list website from scratch, carrying through the Test Goat creed of "do nothing without a test": first write a failing test, then write the minimum code to make it pass, then refactor. The book is divided into three parts. Part I (Chapters 1–6) builds the foundation: writing functional tests with Selenium, writing unit tests with Python's standard unittest library and Django's built-in testing tools, clarifying the division of labour between functional and unit tests, and along the way introducing Django's models, views, templates, forms, ORM, and database migrations, while incorporating Git commits into the TDD cycle. Part II (Chapters 7–14) deals with the practical problems unavoidable in web development: beautifying pages with Bootstrap and template inheritance, managing static files, setting up a staging server, automating deployment with Fabric, doing input validation and form refactoring, exploring JavaScript and its testing, and safely putting new code into production. Part III (Chapters 15–22) moves into advanced topics: user authentication and integrating third-party login, using mocking to isolate external dependencies, test fixtures and logging for debugging, outside-in TDD, test isolation, and continuous integration. This is not a Python grammar book, nor is it content to list knowledge points; it aims to impart a repeatable set of engineering habits: making tests a design tool and giving refactoring a safety net. Readers will also pick up the basics of Django, Selenium, Git, jQuery, and Mock along the way.

Editor's review

很多讲测试的书停在概念和玩具示例上,这本书则把你按在一张真实的工位旁边:一起装 Django、一起写第一个会失败的 Selenium 测试、一起被“测试山羊”盯着不放。作者珀西瓦尔是 TDD 的长期布道者,也是 PythonAnywhere 的开发者,因此书中连注册域名、配 Nginx、用 Fabric 部署这类“脏活”都写得清清楚楚。 它的价值在三处。其一,先测试后编码的节奏贯穿全书,读者能亲身体会“红—绿—重构”为什么能降低心理压力,而不是被口号说服。其二,功能测试与单元测试的分层讲得极透,这两种测试各自管什么、什么时候该用 mock,都有可操作的判断标准。其三,把 Git、部署、持续集成这些工程实践编进同一条流水线,学完相当于走完一个小型项目的完整生命周期。 需要提醒的是,本版基于较早期的 Django 与 Python 3 环境,部分命令与库版本已显陈旧;如果只想要最新框架用法,可参考后来改名为《Python测试驱动开发》的第2版。但作为理解 TDD 思维方式的第一本书,它依然值得反复翻。

Who it's for

A good fit for

  • 已会写 Python、做过一两个小项目,想系统学习工程实践的开发者
  • 使用 Django 或其他框架做 Web 开发,却长期不敢重构代码的人
  • 计算机专业学生或转行者,希望用一个完整项目串起开发全流程
  • 对单元测试、功能测试、持续集成只闻其名、缺少实操经验的读者

Not a good fit for

  • 完全零基础、尚未掌握 Python 基本语法的初学者,读起来会两头顾不上
  • 只想查 Django API 用法、当作速查手册使用的读者
  • 严格跟随最新框架版本、需要即用型现代代码示例的团队
  • 只关心前端或纯算法、不打算接触 Web 后端工程的人

Reading tips

  1. 务必打开编辑器跟着敲代码,不要复制粘贴;书中特意强调手打能形成肌肉记忆并训练调试能力。
  2. 遇到测试失败先自己排查再看书,把“红—绿—重构”的循环亲手走完一轮,比读完十章更有用。
  3. 版本差异较大的章节,先按书中的思路理解意图,再对照当前 Django 文档调整具体写法。
  4. 读完第 14 章后,可把自己的小项目改造成 TDD 流程,用功能测试守住最关键的用户路径。

About the publisher

Posts & Telecom Press China · Founded in 1953

Posts & Telecom Press is known for its strengths in science and technology, computing, and information and communications titles, and has extended its publishing into photography, art, software learning, and inspirational growth, giving it a fairly diverse range. Its catalog includes computing and communications works such as Refactoring and Patterns (Revised Edition) and Huawei Switch Learning Guide (Second Edition), alongside bilingual collector's editions such as The Little Prince (Chinese-English-French illustrated collector's edition), The Great Gatsby, and Three Days to See. Beijing Ten Years: 1980-1990 and Ghost Blade: WLOP Personal Illustration Collection reflect its presence in photography and art. Its authors include Antoine de Saint-Exupéry, Helen Keller, Joshua Kerievsky, Wang Da, Zhang Zhaozeng, and WLOP.

Contents

  1. Preface
  2. Preparation and Prerequisites
  3. Part I TDD and Django Basics
  4. Chapter 1 Using Functional Tests to Help Install Django
  5. Chapter 2 Extending Functional Tests with the unittest Module
  6. Chapter 3 Using Unit Tests to Test a Simple Home Page
  7. Chapter 4 What's the Point of Writing These Tests
  8. Chapter 5 Saving User Input
  9. Chapter 6 Completing the Minimum Viable Website
  10. Part II Web Development Essentials
  11. Chapter 7 Beautifying the Site: Layout, Styling, and How to Test Them
  12. Chapter 8 Testing Deployment with a Staging Site
  13. Chapter 9 Automated Deployment with Fabric
  14. Chapter 10 Input Validation and How to Organize Tests
  15. Chapter 11 Simple Forms
  16. Chapter 12 Advanced Forms
  17. Chapter 13 Probing JavaScript
  18. Chapter 14 Deploying New Code
  19. Part III Advanced Topics
  20. Chapter 15 User Authentication, Integrating Third-Party Plugins, and the Use of JavaScript Mocking Techniques
  21. Chapter 16 Server-Side Authentication and Using Mocking in Python
  22. Chapter 17 Test Fixtures, Logging, and Server-Side Debugging
  23. Chapter 18 Completing the "My Lists" Page: Outside-In TDD
  24. Chapter 19 Test Isolation and "Listening to the Heart of the Tests"
  25. Chapter 20 Continuous Integration
  26. Chapter 21 Simple Social Features, Page Patterns, and Exercises
  27. Chapter 22 Fast and Slow Test Runs and Molten Lava
  28. Bibliography

FAQ

这本书只讲测试吗?
不止。测试是主线,但作者围绕它讲了 Git 版本控制、静态文件与 Bootstrap 美化、过渡服务器与自动部署、表单验证、JavaScript 及其单元测试、mock 技术、持续集成等整套 Web 开发实践,可以当作一个完整项目的实战课。
读之前需要什么基础?
需要能读懂并写出基本 Python 3 代码,最好了解函数、类与模块的概念。书中从零介绍 Django,但作者建议完全没接触过 Django 的读者先花几小时过一遍官方教程再回来。
这本书和第2版《Python测试驱动开发》是什么关系?
本书是 2015 年人民邮电出版社的中译本,译自原书第1版;2018 年的第2版改名为《Python测试驱动开发:使用Django、Selenium和JavaScript进行Web编程》,改用 Python 3 与新版 Django 重写。两本内容框架相近,选一本跟着做完整流程即可。
书中的代码版本太老还能照着做吗?
核心的 TDD 流程、测试分层思路和部署原理不会过时,可以照做;但 Django、Fabric、Selenium 等具体 API 与命令已有变化,建议对照对应版本的官方文档微调,遇到报错优先查文档而不是怀疑方法本身。
适合用来准备面试或转行吗?
适合作为项目经验的补充。它能帮你讲清楚测试策略、部署流程和重构取舍,但面试常考的框架细节、数据库与算法仍需另行准备,别把它当作唯一复习材料。

Comments

Find this book

This site is an index: you start “Search all sources” in your browser, and the entries it lists all point to third-party sites; please judge their availability yourself.

Top rated in the same category