To test RESTful APIs, perform the following steps:
- 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", ...