Writing unit tests for a RESTful Web Service
Now, we will write our first round of unit tests related to the drone category class based views: DroneCategoryList and DroneCategoryDetail. Open the existing restful01/drones/tests.py file and replace the existing code with the following lines that declare many import statements and the DroneCategoryTests class. The code file for the sample is included in the hillar_django_restful_10_01 folder in the restful01/drones/tests.py file:
from django.utils.http import urlencode
from django.core.urlresolvers import reverse
from rest_framework import status
from rest_framework.test import APITestCase
from drones.models import DroneCategory
from drones import views
class DroneCategoryTests(APITestCase):
def post_drone_category(self, name):
url = reverse(views.DroneCategoryList.name)
data = {'name': name}
response = self.client.post(url, data, format='json')
return response
def test_post_and_get_drone_category...