From the course: Securing Django Applications

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Unit testing idempotent actions that should only happen once

Unit testing idempotent actions that should only happen once - Django Tutorial

From the course: Securing Django Applications

Start my 1-month free trial

Unit testing idempotent actions that should only happen once

- [Instructor] Let's open the test file and write a test case for the cooldown throttling period. We already have the Django cache imported, and we have our package create view test case with some sample data. So before we start testing, we need to setup what are the expectations here, which is that after we make a request, we're going to be seeing that one additional object was created. So before the request, we want to make sure that the cache key package created has not been set. Now, we're going to make our first request, which is to create a new package, going to use that sample data. And we're going to make sure that right after this first request, the cache key has been set, and then we're going to make sure that the response was also 201 to indicate that the object was created. And then we're going to make sure that the number of objects in the database has actually been updated. Now in our second request, we're…

Contents