Develop powerful, fully-featured Django applications by writing tests first
Test-Driven Development (TDD) simplifies the trickiest of software tasks with its unique ability to peel back problems into layers. The testing tools available in Python and Django make test writing a joy, and the full coverage test suite that results from TDD is a boon to any project.
This guide to developing with Django takes a test-first approach: write a test, then write enough production code to get it to pass. You'll quickly get hands-on experience, writing tests for a database-driven application with the TDD methodology. Use this book to build the skills and habits that make testing a regular part of your workflow.
What You Will Learn
- Codify user stories as browser-based tests to ensure their completion
- Write isolated unit tests that not only confirm your application, but also explain it
- Use the red-green-refactor TDD cycle to create and refine your code by changing tests first
- Test integrations with external APIs by testing their documentation
- Mock out calls to external services and internal functions
- Explore the basics of documentation-driven API design
- Other testing tools available in popular Python packages such as Django REST framework and VCR.py
Table of Contents
Test-Driven Development with Django
- Table of Contents
- Test-Driven Development with Django
- About the Author
- About the Reviewers
1. Keeping Your Promises
- What is Test-Driven Development?
- How does TDD help in building better software?
- Doesn't it take longer?
- Can't I just write the tests later?
2. Your First Test-Driven Application
- Where do we begin?
- Functional versus unit tests
- The project – jmad.us
- Setting up your environment
- Starting the project
- Setting up a Django app for unit tests
- Finally writing application code
3. Ironclad Code
- Using the Python Debugger in tests
- Using RequestFactory
- Managing test data
- DRY testing
- RequestFactory versus TestClient
- 4. Building Out and Refactoring
- 5. User Stories As Code
6. No App Is an Island
- What is a mock?
- Using the API in our application
- Mocking – when and why
7. Share and Share Alike
- It's an API world, we're just coding in it
- Introducing Django REST framework
- Adding data via the API
8. Promises Kept
How far we've come
- So, how did it go?
- What haven't we done?
- What shall we build next?
- To tend or not to tend?
- Fight through the gotchas
- How far we've come
- Title: Test-Driven Development with Django
- Release date: July 2015
- Publisher(s): Packt Publishing
- ISBN: 9781785281167