| 1 |
import logging |
| 2 |
from functools import wraps |
| 3 |
|
| 4 |
from django.core.cache import cache |
| 5 |
from django.test.utils import override_settings |
| 6 |
|
| 7 |
logger = logging.getLogger(__name__) |
| 8 |
|
| 9 |
|
| 10 |
def all_final_sql_checks(func): |
| 11 |
""" |
| 12 |
Runs test as two sub-tests: |
| 13 |
one with CACHALOT_FINAL_SQL_CHECK setting True, one with False |
| 14 |
""" |
| 15 |
|
| 16 |
@wraps(func) |
| 17 |
def wrapper(self, *args, **kwargs): |
| 18 |
for final_sql_check in (True, False): |
| 19 |
with self.subTest(msg=f'CACHALOT_FINAL_SQL_CHECK = {final_sql_check}'): |
| 20 |
with override_settings( |
| 21 |
CACHALOT_FINAL_SQL_CHECK=final_sql_check |
| 22 |
): |
| 23 |
func(self, *args, **kwargs) |
| 24 |
cache.clear() |
| 25 |
|
| 26 |
return wrapper |
| 27 |
|
| 28 |
|
| 29 |
def no_final_sql_check(func): |
| 30 |
""" |
| 31 |
Runs test with CACHALOT_FINAL_SQL_CHECK = False |
| 32 |
""" |
| 33 |
@wraps(func) |
| 34 |
def wrapper(self, *args, **kwargs): |
| 35 |
with override_settings(CACHALOT_FINAL_SQL_CHECK=False): |
| 36 |
func(self, *args, **kwargs) |
| 37 |
|
| 38 |
return wrapper |
| 39 |
|
| 40 |
|
| 41 |
def with_final_sql_check(func): |
| 42 |
""" |
| 43 |
Runs test with CACHALOT_FINAL_SQL_CHECK = True |
| 44 |
""" |
| 45 |
@wraps(func) |
| 46 |
def wrapper(self, *args, **kwargs): |
| 47 |
with override_settings(CACHALOT_FINAL_SQL_CHECK=True): |
| 48 |
func(self, *args, **kwargs) |
| 49 |
|
| 50 |
return wrapper |