How to do it...

To test RESTful APIs, perform the following steps:

  1. Create a tests module in your music app. In the tests module, create a test_api.py file with the SongTests class. The class will have setUpClass() and tearDownClass() methods, as follows:
# myproject/apps/music/tests/test_api.pyfrom django.contrib.auth.models import Userfrom django.urls import reversefrom rest_framework import statusfrom rest_framework.test import APITestCasefrom ..models import Songclass SongTests(APITestCase):    @classmethod    def setUpClass(cls):        super().setUpClass()        cls.superuser = User.objects.create_superuser(            username="admin", password="admin",              email="admin@example.com"        )        cls.song = Song.objects.create(            artist="Lana Del Rey", title="Video Games - Remastered", ...

Get Django 3 Web Development Cookbook - Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.