Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions backend/settings/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@
class Test(Base):
"""Test configuration."""

CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
"LOCATION": "test-cache",
},
}
DEBUG = False
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""Tests for the clear_cache Django management command."""

import pytest
from django.core.cache import cache
from django.core.management import call_command


class TestClearCacheCommand:
"""Test suite for the clear_cache management command."""

@pytest.fixture(autouse=True)
def _setup_cache(self):
cache.clear()
yield
cache.clear()

def _assert_cache_data(self, data):
for key, expected_value in data.items():
assert cache.get(key) == expected_value

def _assert_cache_no_data(self, data):
for key in data:
assert cache.get(key) is None

def test_clear_cache_command(self):
test_data = {
"test_key_1": "test_value_1",
"test_key_2": "test_value_2",
"test_key_3": {"nested": "data"},
}

for key, value in test_data.items():
cache.set(key, value)

self._assert_cache_data(test_data)

call_command("clear_cache")

self._assert_cache_no_data(test_data)

def test_clear_cache_command_empty_cache(self):
assert cache.get("any_key") is None

call_command("clear_cache")

assert cache.get("any_key") is None

def test_clear_cache_command_timeout(self):
cache.set("timeout_key", "timeout_value", timeout=3600)
assert cache.get("timeout_key") == "timeout_value"

call_command("clear_cache")

assert cache.get("timeout_key") is None