O'Reilly logo

Test-Driven Development with Django by Kevin Harvey

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding data via the API

In order to get to this point, I've skipped ahead a bit, repeating much of the same work on the Album endpoint for Tracks. Either take a peak in the repo, or better yet, attempt the following tasks on your own and come back to the source to compare:

  1. Write a functional test for listing Tracks
  2. Add serializers for Solos and Tracks
  3. Write a TrackViewSet to satisfy the functional test

If you'd like to grab the code from the repository:

$ git checkout ch7-3-track-view-and-serializer

Now we're ready to open up our API for new, incoming Solo data.

POSTing data in a test

Let's start by writing a new functional test for adding Solos via the API. We'll use APIClient.post to send a dict (as JSON) to '/api/solos/'. Create a new file solos/tests/test_api.py ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required