-
-
Notifications
You must be signed in to change notification settings - Fork 270
Add test: test for clearing cache #1522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
arkid15r
merged 13 commits into
OWASP:main
from
bandhan-majumder:feature/test-clear-cache
Jun 1, 2025
Merged
Changes from 2 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
771da16
Add test: test for clearing cache
bandhan-majumder c8f6e36
Merge branch 'main' into feature/test-clear-cache
bandhan-majumder e4e4260
rabbit suggestions
bandhan-majumder 85f7d80
Merge branch 'main' into feature/test-clear-cache
bandhan-majumder b6d3b48
Merge branch 'main' into feature/test-clear-cache
bandhan-majumder f0134bb
Merge branch 'main' into feature/test-clear-cache
bandhan-majumder 2c529b0
Merge branch 'main' into feature/test-clear-cache
bandhan-majumder 86b2386
make check applied
bandhan-majumder 2905853
Merge branch 'main' into feature/test-clear-cache
bandhan-majumder 1f1f244
update into class
bandhan-majumder 769447a
Merge branch 'main' into feature/test-clear-cache
bandhan-majumder 9455c73
Update code
arkid15r 2cfbf3c
Apply suggestions
arkid15r File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
backend/tests/apps/common/management/commands/clear_cache_test.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| from django.core.cache import cache | ||
| from django.core.management import call_command | ||
| from django.test import override_settings | ||
| import pytest | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| @override_settings(CACHES={ | ||
| 'default': { | ||
| 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache', | ||
| 'LOCATION': 'test-cache', | ||
| } | ||
| }) | ||
| def setup_cache(): | ||
| cache.clear() | ||
| yield | ||
| cache.clear() | ||
|
|
||
|
|
||
| @override_settings(CACHES={ | ||
| 'default': { | ||
| 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache', | ||
| 'LOCATION': 'test-cache', | ||
| } | ||
| }) | ||
| def test_clear_cache_command(setup_cache): | ||
| cache.set('test_key_1', 'test_value_1') | ||
| cache.set('test_key_2', 'test_value_2') | ||
| cache.set('test_key_3', {'nested': 'data'}) | ||
|
|
||
| assert cache.get('test_key_1') == 'test_value_1' | ||
| assert cache.get('test_key_2') == 'test_value_2' | ||
| assert cache.get('test_key_3') == {'nested': 'data'} | ||
|
|
||
| call_command('clear_cache') | ||
|
|
||
| assert cache.get('test_key_1') is None | ||
| assert cache.get('test_key_2') is None | ||
| assert cache.get('test_key_3') is None | ||
|
|
||
|
|
||
| @override_settings(CACHES={ | ||
| 'default': { | ||
| 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache', | ||
| 'LOCATION': 'test-cache', | ||
| } | ||
| }) | ||
| def test_clear_cache_command_empty_cache(setup_cache): | ||
| cache.clear() | ||
| assert cache.get('any_key') is None | ||
|
|
||
| call_command('clear_cache') | ||
|
|
||
| assert cache.get('any_key') is None | ||
|
|
||
|
|
||
| @override_settings(CACHES={ | ||
| 'default': { | ||
| 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache', | ||
| 'LOCATION': 'test-cache', | ||
| } | ||
| }) | ||
| def test_clear_cache_command_with_timeout_keys(setup_cache): | ||
| cache.set('timeout_key', 'timeout_value', timeout=3600) # 1 hour timeout | ||
|
|
||
| assert cache.get('timeout_key') == 'timeout_value' | ||
|
|
||
| call_command('clear_cache') | ||
|
|
||
| assert cache.get('timeout_key') is None | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.