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):
"""
Ensure we can create a new Player and then retrieve it
"""
new_player_name = 'New Player'
new_player_gender = Player.MALE
response...