-
Book Overview & Buying
-
Table Of Contents
Becoming an Enterprise Django Developer
By :
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.
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:
/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 ......