Provides a declarative and powerful way to test AbstractModelView
AbstractModelViewTest
class AbstractModelViewTest(ABC)
Abstract class for testing model views.
This class provides a common interface for testing various types of model views. It defines
several methods that must be implemented by subclasses, including on_successful_request
and
on_failed_request
, which handle the response from the server after a request is made.
Each test method within this class is automatically attached to the test case when instantiated
as a class attribute on a ModelViewSetTestCase
subclass. The test method names are dynamically
generated based on the class attribute name.
Attributes:
model_view
AbstractModelView - The model view to be tested.model_viewset_test_case
ModelViewSetTestCase - The test case to which this test belongs.
Notes:
This is an abstract base class and should not be instantiated directly. Instead, use one of its
subclasses like ListModelViewTest
, CreateModelViewTest
, RetrieveModelViewTest
,
UpdateModelViewTest
, or DeleteModelViewTest
.
handle_request
def handle_request(path_parameters: dict, query_parameters: dict,
headers: dict, payload: dict) -> django.http.HttpResponse
Handles the execution of an HTTP request.
This method constructs the HTTP request and sends it to the server, then returns the server's response.
Arguments:
path_parameters
dict - The path parameters for the request.query_parameters
dict - The query parameters for the request.headers
dict - The headers to include in the request.payload
dict - The payload to send with the request.
Returns:
django.http.HttpResponse
- The response from the request.
on_successful_request
@abstractmethod
def on_successful_request(response: django.http.HttpResponse,
path_parameters: dict, query_parameters: dict,
headers: dict, payload: dict)
Callback method to handle the response for a successful request.
This method should be overridden in subclasses to implement custom logic for
processing successful responses.
Arguments:
response
django.http.HttpResponse - The response from the server.path_parameters
dict - Path parameters used in the request.query_parameters
dict - Query parameters used in the request.headers
dict - Headers included in the request.payload
dict - Payload sent with the request.
on_failed_request
@abstractmethod
def on_failed_request(response: django.http.HttpResponse,
path_parameters: dict, query_parameters: dict,
headers: dict, payload: dict)
Callback method to handle the response for a failed request.
This method should be overridden in subclasses to implement custom logic for
processing failed responses.
Arguments:
response
django.http.HttpResponse - The response from the server.path_parameters
dict - Path parameters used in the request.query_parameters
dict - Query parameters used in the request.headers
dict - Headers included in the request.payload
dict - Payload sent with the request.