Reader small image

You're reading from  Becoming an Enterprise Django Developer

Product typeBook
Published inJun 2022
Reading LevelIntermediate
PublisherPackt
ISBN-139781801073639
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Michael Dinder
Michael Dinder
author image
Michael Dinder

Michael Dinder works as a senior backend developer at Cart, Inc. Michael has helped to develop projects for large enterprises such as PayPal and other companies such as Corcoran Pacific Properties, and countless more either directly or indirectly. He has been programming for more than 15 years with a number of different languages and frameworks, with a focus on Python/Django for the past 5+ years.
Read more about Michael Dinder

Right arrow

Testing Django REST API endpoints

This section will introduce writing test cases that test Django REST framework endpoints. When testing any REST API endpoints created using the Django REST framework, we need to use the APITestCase class provided by the rest_framework.test library. We also should use the APIClient() class provided by that same library when requiring authentication, instead of using the Client() class as we did before.

In the following exercises, we will create one test class that performs two tests: the first will create an engine object and the other will update an object.

Creating an object test case

This test will use the POST request method to send data to the http://localhost:8000/chapter-8/engines/ endpoint and create an engine object in the database. Since we are loading a data fixture that contains only two engine objects with the IDs 1 and 2, we should expect the new object to be created at index 3, but your results may vary. We will refer back to...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Becoming an Enterprise Django Developer
Published in: Jun 2022Publisher: PacktISBN-13: 9781801073639

Author (1)

author image
Michael Dinder

Michael Dinder works as a senior backend developer at Cart, Inc. Michael has helped to develop projects for large enterprises such as PayPal and other companies such as Corcoran Pacific Properties, and countless more either directly or indirectly. He has been programming for more than 15 years with a number of different languages and frameworks, with a focus on Python/Django for the past 5+ years.
Read more about Michael Dinder