27 lines
986 B
Python
27 lines
986 B
Python
import os
|
|
import tempfile
|
|
|
|
from django.test import SimpleTestCase, override_settings
|
|
|
|
from config import health
|
|
|
|
|
|
class AppLogSizeWarningTests(SimpleTestCase):
|
|
"""با چرخشِ بیرونی برنامه app.log را پاک نمیکند؛ اگر آرشیوِ شبانه بخوابد /api/health باید بگوید."""
|
|
|
|
def _with_log(self, size, rotation):
|
|
d = tempfile.mkdtemp()
|
|
with open(os.path.join(d, 'app.log'), 'wb') as f:
|
|
f.truncate(size)
|
|
with override_settings(LOG_DIR=d, LOG_FILE_ROTATION=rotation):
|
|
return health._app_log_warnings()
|
|
|
|
def test_big_log_with_external_rotation_warns(self):
|
|
self.assertEqual(len(self._with_log(health.APP_LOG_MAX_BYTES + 1, 'external')), 1)
|
|
|
|
def test_small_log_is_quiet(self):
|
|
self.assertEqual(self._with_log(1024, 'external'), [])
|
|
|
|
def test_size_rotation_never_warns(self):
|
|
self.assertEqual(self._with_log(health.APP_LOG_MAX_BYTES + 1, 'size'), [])
|