Skip to content

Commit 8836109

Browse files
lunikaAntoLC
authored andcommitted
♻️(back) reset cache after every test
We move the cache reset in the global conf test to not have to think about reseting the cache when we implement test.
1 parent ba136ff commit 8836109

File tree

5 files changed

+8
-29
lines changed

5 files changed

+8
-29
lines changed

src/backend/core/tests/conftest.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@
22

33
from unittest import mock
44

5+
from django.core.cache import cache
6+
57
import pytest
68

79
USER = "user"
810
TEAM = "team"
911
VIA = [USER, TEAM]
1012

1113

14+
@pytest.fixture(autouse=True)
15+
def clear_cache():
16+
"""Fixture to clear the cache before each test."""
17+
cache.clear()
18+
19+
1220
@pytest.fixture
1321
def mock_user_teams():
1422
"""Mock for the "teams" property on the User model."""

src/backend/core/tests/documents/test_api_documents_ai_transform.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import random
66
from unittest.mock import MagicMock, patch
77

8-
from django.core.cache import cache
98
from django.test import override_settings
109

1110
import pytest
@@ -17,12 +16,6 @@
1716
pytestmark = pytest.mark.django_db
1817

1918

20-
@pytest.fixture(autouse=True)
21-
def clear_cache():
22-
"""Fixture to clear the cache before each test."""
23-
cache.clear()
24-
25-
2619
@pytest.fixture
2720
def ai_settings():
2821
"""Fixture to set AI settings."""

src/backend/core/tests/documents/test_api_documents_ai_translate.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import random
66
from unittest.mock import MagicMock, patch
77

8-
from django.core.cache import cache
98
from django.test import override_settings
109

1110
import pytest
@@ -17,12 +16,6 @@
1716
pytestmark = pytest.mark.django_db
1817

1918

20-
@pytest.fixture(autouse=True)
21-
def clear_cache():
22-
"""Fixture to clear the cache before each test."""
23-
cache.clear()
24-
25-
2619
@pytest.fixture
2720
def ai_settings():
2821
"""Fixture to set AI settings."""

src/backend/core/tests/test_api_utils_ai_document_rate_throttles.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44

55
from unittest.mock import patch
66

7-
from django.core.cache import cache
87
from django.test import override_settings
98

10-
import pytest
119
from rest_framework.response import Response
1210
from rest_framework.test import APIRequestFactory
1311
from rest_framework.views import APIView
@@ -25,12 +23,6 @@ def get(self, request, *args, **kwargs):
2523
return Response({"message": "Success"})
2624

2725

28-
@pytest.fixture(autouse=True)
29-
def clear_cache():
30-
"""Fixture to clear the cache before each test."""
31-
cache.clear()
32-
33-
3426
@override_settings(AI_DOCUMENT_RATE_THROTTLE_RATES={"minute": 3, "hour": 6, "day": 10})
3527
@patch("time.time")
3628
def test_api_utils_ai_document_rate_throttle_minute_limit(mock_time):

src/backend/core/tests/test_api_utils_ai_user_rate_throttles.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from unittest.mock import patch
66
from uuid import uuid4
77

8-
from django.core.cache import cache
98
from django.test import override_settings
109

1110
import pytest
@@ -29,12 +28,6 @@ def get(self, request, *args, **kwargs):
2928
return Response({"message": "Success"})
3029

3130

32-
@pytest.fixture(autouse=True)
33-
def clear_cache():
34-
"""Fixture to clear the cache before each test."""
35-
cache.clear()
36-
37-
3831
@override_settings(AI_USER_RATE_THROTTLE_RATES={"minute": 3, "hour": 6, "day": 10})
3932
@patch("time.time")
4033
def test_api_utils_ai_user_rate_throttle_minute_limit(mock_time):

0 commit comments

Comments
 (0)