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 background queue flood prevention - Django Tutorial
From the course: Securing Django Applications
Unit testing background queue flood prevention
- [Narrator] Our first test case, we'll test the celery task that was created. In the setup method we have to first clear the cache, and then in our first test, we're going to be asserting that the cache does not have any key set, specifically the key for this user ID. And then we're going to call our background task, with that user ID and the text. And then we're going to be checking that the comment was created. We make sure the text is equal to example, and we also make sure that the cache was set for this cache key and that the cache value was set to the comment ID. For our next task, we're going to be marking out the retry function of create comment, and we're going to be making sure that retrying and queuing up this background task for later can be done. We have the create comment retry lock here, and our user ID will be the first user's ID. And then we're going to call create comment with that user ID, just…
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
-
-
-
-
-