Test-Driven Development with Python Obey the Testing Goat Using Django, Selenium, and JavaScript (Harry J.W. Percival)(Z-Library)
Python
No description
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, story-driven guide to web development using Test-Driven Development (TDD) with Python, Django, Selenium, and JavaScript, perfect for developers who want to build robust applications by writing tests first and "obeying the testing goat."
【Book Arc】
- **Opening (~0%–10%)**: Introduces the core philosophy of TDD—"do nothing until you have a test"—and sets up the project environment, including installing Django, Selenium, and creating the first functional test (FT) that drives development.
- **Early (~10%–23%)**: Walks through the first TDD cycle: writing a failing FT, creating a Django app, and using unit tests to build the home page. Emphasizes the importance of testing both the "what" (user behavior) and the "how" (code logic).
- **Early–Middle (~23%–39%)**: Focuses on saving user input to a database, introducing the Django test client, and handling POST requests. Covers the "redirect after POST" pattern and the concept of regression testing to prevent old bugs from reappearing.
- **Middle (~39%–48%)**: Explores working incrementally, adding URL parameters to support multiple to-do lists, and refactoring views to keep them simple. Highlights the value of removing redundant code and tests as the design evolves.
- **Late (~48%–52%)**: Shifts to "prettification"—layout and styling—and discusses what to test (or not) about front-end changes. Introduces Docker for running the app in a consistent environment and managing ports for testing.
【Key Takeaways】
- **TDD is a discipline, not a tool** (Early): The mantra "do nothing until you have a test" forces you to think about desired behavior before implementation, reducing bugs and guiding design. It's about a mindset shift, not just using testing libraries.
- **Functional tests (FTs) capture user stories** (Early): Writing FTs in plain language (e.g., "Edith types 'Buy peacock feathers'") ensures you're building what the user actually needs, not just what the code can do. They serve as living documentation.
- **Unit tests drive code structure** (Early): While FTs test behavior from the outside, unit tests (like calling view functions directly) help you design clean, modular code. The book deliberately shows the "manual" way before introducing the Django test client to build understanding.
- **The Django test client is pragmatic but has trade-offs** (Early): It simplifies testing views and templates, but it pushes you toward integration tests rather than fully isolated unit tests. The book acknowledges this and revisits the distinction later.
- **Always redirect after a POST** (Early): This pattern prevents duplicate submissions and keeps the URL clean. It's a simple rule that improves user experience and is easy to test with `assertRedirects`.
- **Refactoring is part of the TDD cycle** (Middle): As features grow, you'll simplify views and remove redundant tests. This keeps the codebase maintainable and ensures tests stay relevant—"doesn't that feel good?"
- **URL parameters enable scalable features** (Middle): Using `<int:list_id>` in URL patterns allows each user to have their own list, moving from a single shared list to a multi-user app. This is a natural step in incremental development.
- **Front-end testing has limits** (Late): When adding styling, you test that assets load correctly, not pixel-perfect layouts. The book advises using tools like Docker to ensure consistent environments, avoiding "works on my machine" issues.
【Reading Tips】
- **Skim the early setup chapters** (~0%–10%) if you're already familiar with Django and Selenium; the key insight is the TDD philosophy, not the installation steps.
- **Deep-read the TDD cycle chapters** (~10%–39%): Follow along with the code examples—type them out and run the tests yourself. The "red-green-refactor" rhythm is best learned by doing.
- **Pay attention to the "why" behind choices** (e.g., why not use the test client from the start): These explanations reveal the author's teaching strategy and deepen your understanding of testing trade-offs.
- **Don't skip the refactoring sections** (Middle): They show how TDD supports code evolution, which is as important as writing tests in the first place.
- **Use the book as a reference for testing patterns**: Even if you don't build a to-do app, the patterns (FTs, unit tests, redirects, URL params) are transferable to any Django project.
【Coverage Limits】
This guide covers the core TDD workflow, Django basics, and testing strategies from the excerpts, but does not cover advanced topics like JavaScript integration, deployment, or the later chapters on forms and validation in detail.
Page 13
340 A Second Attempt at Using the Form in Our Views 342 Using the Form in a View That Takes POST Requests 345 Using the Form to Display Errors in the Templat...
View in text
Excerpt 2
n. But my colleagues were pointing out that comments aren’t always as useful as you hope. For starters, it’s pointless to write a comment that just repeats w...
View in text
Excerpt 3
ecause we know for sure that the item_text key should be in there, and it’s better to fail hard if it isn’t. And that gets the test passing: Ran 5 tests in 0...
View in text
Excerpt 4
rtionError: 404 != 200 : Couldn't retrieve redirection page '/lists/the-only-list-in-the-world/': response code was 404 (expected 200) FAILED (failures=1, er...
View in text
Excerpt 5
cially when I’m refusing to “dictate” exactly how to do it. With that in mind, I wrote a very brief guide on GitHub. I didn’t want to include it in the book...
View in text
Excerpt 6
ss the lambda-ified version of assertEqual. We go into self.wait_for in base.py, where we’re calling (and returning) fn(), which refers to the passed lambda...
View in text
Excerpt 7
hip works. Another FT for Duplicate Items | 367 Figure 16-3. Hack it in manually—yay Conditionally Customising CSS Classes for Invalid Forms Speaking of hack...
View in text
Excerpt 8
our SpecRunner.html file: src/lists/static/tests/SpecRunner.html (ch17l030) <link rel="stylesheet" href="lib/jasmine-4.6.1/jasmine.css"> <!-- Bootstrap CSS -...
View in text
Tags
AI categories
ProgrammingPythonWeb Development
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…
Loading comments...
Reply to Comment
Edit Comment