Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Becoming an Enterprise Django Developer

You're reading from  Becoming an Enterprise Django Developer

Product type Book
Published in Jun 2022
Publisher Packt
ISBN-13 9781801073639
Pages 526 pages
Edition 1st Edition
Languages
Author (1):
Michael Dinder Michael Dinder
Profile icon Michael Dinder

Table of Contents (15) Chapters

Preface 1. Part 1 – Starting a Project
2. Chapter 1: Undertaking a Colossal Project 3. Chapter 2: Project Configuration 4. Chapter 3: Models, Relations, and Inheritance 5. Part 2 – Django Components
6. Chapter 4: URLs, Views, and Templates 7. Chapter 5: Django Forms 8. Chapter 6: Exploring the Django Admin Site 9. Chapter 7: Working with Messages, Email Notifications, and PDF Reports 10. Part 3 – Advanced Django Components
11. Chapter 8: Working with the Django REST Framework 12. Chapter 9: Django Testing 13. Chapter 10: Database Management 14. Other Books You May Enjoy

Testing HTTP view requests

In this section, we will expand on the basic test cases that we previously wrote to include HTTP view requests. When testing view classes, whether they are a method-based view or a class-based view, they will both use the same TestCase class that we have been using so far.

In the following subsections, we will perform two tests, one for a method-based view and the other for a class-based view.

Testing method-based views

In this exercise, we will test the practice_year_view() method, written in Chapter 4, URLs, Views, and Templates. What we are comparing in this test is whether the response code that gets returned equals the value of 200, which means a successful response.

Follow these steps to create your test case:

  1. In your /chapter_9/tests.py file, add the following YearRequestTestCase class and methods:
    # /becoming_a_django_entdev/chapter_9/tests.py
    ...
    from django.contrib.auth.models import AnonymousUser
    from django.test import ......
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}