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 - Django Tutorial
From the course: Securing Django Applications
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Using ApacheBench to simulate a flood of requests5m 13s
-
(Locked)
How to ensure actions happen only once2m 51s
-
(Locked)
Unit testing idempotent actions that should only happen once2m 21s
-
(Locked)
Using background queues to throttle floods of requests3m 43s
-
(Locked)
Unit testing background queue flood prevention2m 28s
-
-
-
-
-