August 2016
Beginner to intermediate
717 pages
15h 24m
English
In this recipe, we will take a look at how to write unit tests. Unit tests are those that check whether the functions or methods return correct results. We again take the likes app and write tests checking whether posting to the json_set_like() view returns {"success"; false} in the response for unauthenticated users and returns {"action": "added", "count": 1, "obj": "Haus der Kulturen der Welt", "success": true} for authenticated users. We will use the Mock objects to simulate the HttpRequest and AnonymousUser objects.
Let's start with the locations and likes apps from the Implementing the Like widget recipe in Chapter 4, Templates and JavaScript.
Install the mock module in your virtual environment, as follows: ...
Read now
Unlock full access