October 2016
Intermediate to advanced
418 pages
9h 52m
English
Now, we will write additional unit tests to improve the testing coverage. Specifically, we will write unit tests related to the player class based views: PlayerList and PlayerDetail. Open the existing games/test.py file and insert the following lines after the last line that declares imports. We need a new import statement and we will declare the new PlayerTests class. The code file for the sample is included in the restful_python_chapter_04_05 folder:
from games.models import Player
class PlayerTests(APITestCase):
def create_player(self, name, gender):
url = reverse('player-list')
data = {'name': name, 'gender': gender}
response = self.client.post(url, data, format='json')
return response
def test_create_and_retrieve_player(self): ...