Testing authenticated view requests
In this section, we will be building on the same request test cases that we just built to remove the AnonymousUser
class and perform our own authentication, requiring only permitted users. We have a few view classes that we wrote in Chapter 8, Working with the Django REST Framework, that require user authentication. Let's create test scripts that allow us to authenticate with an actual user when performing an automated test. This is where loading the chapter_8/urls.py
file when preparing for this chapter comes into play. Django provides a class called Client
found in the django.test
library that lets us perform user authentication when testing a view class.
In the following subsection, we will implement the Client
class when performing authentication.
Using the Client() class
In this exercise, we will test the custom API endpoint written in Chapter 8, Working with the Django REST Framework, in the GetSellerHTMLView
class. This is the...