Improving testing coverage

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): ...

Get Building RESTful Python Web Services now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.