Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: [英]哈利·J.W. 帕西瓦尔, 安道译

Rating No ratings yet

本书从最基础的知识开始,讲解Web 开发的整个流程,展示如何使用Python 做测试驱动开发。本书由三个部分组成。第一部分介绍了测试驱动开发和Django 的基础知识,并在每个阶段进行严格的单元测试。第二部分讨论了Web 开发要素,探讨了Web 开发过程中不可避免的问题,以及如何通过测试解决这些问题。第三部分探讨了一些高级话题,如模拟技术、集成第三方认证系统、Ajax、测试固件以及持续集成等。 第2 版全部使用Python 3,并针对新版Django 全面升级,介绍了由外而内的测试驱动开发流程。本书适合Web 开发人员阅读。

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
【One-Line Pitch】 A hands-on, project-based guide to Test-Driven Development (TDD) for web applications using Python, Django, Selenium, and JavaScript—ideal for developers who want to build robust, maintainable code by writing tests first and learning by doing. 【Book Arc】 - **Opening (~0%–9%)**: Introduces the "Testing Goat" philosophy—write a failing test before any code—and walks through installing Django, setting up a Git repository, and creating the first functional tests with Selenium and unit tests with Python’s `unittest` module. - **Early (~9%–26%)**: Builds a simple to-do list app step-by-step, covering URL routing, view functions, templates, and model design. Emphasizes small, incremental changes, refactoring, and using functional tests to catch regressions as the app grows. - **Early–Middle (~26%–35%)**: Shifts to web development essentials: styling with CSS and Bootstrap, Django template inheritance, and static file handling. Introduces deployment testing on a staging server, covering manual setup with Nginx, Python 3.6, and domain configuration. - **Middle (~35%–48%)**: Focuses on production readiness—switching to Gunicorn, configuring Nginx for static files, setting `DEBUG=False`, and using Systemd for process management. Also covers automating deployment with Fabric and refactoring tests into multiple files. - **Middle–Late (~48%–52%)**: Delves into database-level validation, moving logic from views into Django forms, and using `ModelForm` for cleaner code. Addresses advanced form handling, including uniqueness validation for duplicate to-do items, and introduces JavaScript testing with jQuery and fixtures. 【Key Takeaways】 - **TDD is a discipline, not a tool** (Opening): Write a failing test first, then implement the minimum code to pass it. This "Testing Goat" approach prevents over-engineering and keeps you focused on user needs. - **Functional tests vs. unit tests** (Early): Functional tests (via Selenium) verify the whole system from the user's perspective, while unit tests check specific components. Both are essential—functional tests guide the big picture, unit tests drive the details. - **Incremental design beats upfront planning** (Early): Start with a minimal app and let tests guide each new feature. Use YAGNI ("You Aren't Gonna Need It") to avoid speculative complexity, and refactor only when tests are green. - **Deployment is part of TDD** (Middle): Test deployment early on a staging server to catch environment-specific issues. Manual setup (Nginx, Gunicorn, virtualenv) teaches you the stack before automating it with tools like Fabric. - **Forms centralize validation** (Middle–Late): Move validation logic from views into Django forms (especially `ModelForm`) to reduce duplication and make tests cleaner. This also unlocks free benefits like HTML5 client-side validation. - **JavaScript needs its own test strategy** (Late): Use a basic test runner, jQuery, and `<div>` fixtures to unit-test JavaScript behavior. Manage global state and execution order carefully—these are the biggest challenges in JS testing. 【Reading Tips】 - **Skim the early setup chapters** (~0%–9%) if you already know Django basics; focus instead on the TDD workflow and how functional tests are structured. - **Deep-read the to-do list build** (~9%–26%)—this is the core of the book. Follow along by coding, not just reading; the value is in the repetition of test-fail-pass-refactor. - **Pay attention to deployment chapters** (~30%–43%) even if you use PaaS; understanding manual Nginx/Gunicorn setup clarifies what automation tools do under the hood. - **Treat Chapter 13–15 as a unit** (~43%–52%): They show a realistic refactoring journey from views to forms. Read them together to see how validation evolves. - **Skip the JavaScript chapter** (~52%) if you're not using client-side interactivity; it's useful but somewhat isolated from the Django core. 【Coverage Limits】 This guide synthesizes the book's structure and key themes from the provided excerpts, which cover roughly the first half of the book (up to ~52%). Later topics like mocking, third-party authentication, Ajax, test fixtures, and continuous integration are mentioned in the blurb but not detailed in the excerpts.
Excerpt 1
——O’Reilly Media, Inc. 的许可。 版权所有,未得书面许可,本书的任何部分和全部不得以任何形式重制。 图灵社区会员 JeremyTowne(1747552250@qq.com) 专享 尊重版权 O’Reilly Media 通过图书、杂志、在线服务、调查研究和会议等方式传播创新知识。 自 19...
View in text
Page 9
............................................................55 5.7 处理完POST请求后重定向 ...............................................................................
View in text
Page 11
......................................................130 9.5 手动部署代码 ...........................................................................................
View in text
Page 12
............................................................188 14.1.3 测试和定制表单验证................................................................................
View in text
Page 14
...........................................................................................248 18.4 一个极简的自定义用户模型 ...............................................
View in text
Page 8
............... 323 23.4 以完全隔离的方式重写视图测试 .......................................................................................323 23.4.1 为了新测试的健全性,保留之前的整合测试...
View in text
Page 17
...........................................................................385 附录 C 使用 Ansible 配置服务器 ...........................................................
View in text
Page 20
前,你无须了解这些工具。读完本书 后,你会充分了解这些工具,并掌握 TDD 理念。 在极限编程实践中,我们总是结对编程。写这本书时,我设想自己和以前的自己结成对 子,向以前的我解释如何使用这些工具,回答为什么要用这种特别的方式编写代码。所 以,如果我表现得有点儿屈尊俯就,那是因为我不是那么聪明,我要对自己很有耐心...
View in text
Tags
AI categories
Pythondjango
ISBN: 7115485577
Publish Year: 2018
Language: Chinese
File Format: PDF
File Size: 11.2 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…