Now, we will write the first round of unit tests. Specifically, we will write unit tests related to the game category class-based views: GameCategoryList
and GameCategoryDetail
. Open the existing games/test.py
file and replace the existing code with the following lines that declare many import
statements and the GameCategoryTests
class. The code file for the sample is included in the restful_python_chapter_04_04
folder, as shown:
from django.test import TestCase from django.core.urlresolvers import reverse from django.utils.http import urlencode from rest_framework import status from rest_framework.test import APITestCase from games.models import GameCategory class GameCategoryTests(APITestCase): def create_game_category(self, name): url = reverse('gamecategory-list') data = {'name': name} response = self.client.post(url, data, format='json') return response def test_create_and_retrieve_game_category...