fix pre-commit
Some checks failed
CI/CD Pipeline / Telegram Notify Success (push) Has been cancelled
CI/CD Pipeline / Run Tests (push) Has been cancelled
CI/CD Pipeline / Code Quality Checks (push) Has been cancelled
CI/CD Pipeline / Code Quality Checks (pull_request) Successful in 1m42s
CI/CD Pipeline / Run Tests (pull_request) Successful in 2m25s
CI/CD Pipeline / Telegram Notify Success (pull_request) Successful in 1m34s
Some checks failed
CI/CD Pipeline / Telegram Notify Success (push) Has been cancelled
CI/CD Pipeline / Run Tests (push) Has been cancelled
CI/CD Pipeline / Code Quality Checks (push) Has been cancelled
CI/CD Pipeline / Code Quality Checks (pull_request) Successful in 1m42s
CI/CD Pipeline / Run Tests (pull_request) Successful in 2m25s
CI/CD Pipeline / Telegram Notify Success (pull_request) Successful in 1m34s
This commit is contained in:
@@ -9,10 +9,7 @@ from unittest.mock import MagicMock, patch
|
||||
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
|
||||
CELERY_MODULE_PATH = (
|
||||
Path(__file__).resolve().parents[3] / "src" / "core" / "celery.py"
|
||||
)
|
||||
CELERY_MODULE_PATH = Path(__file__).resolve().parents[3] / "src" / "core" / "celery.py"
|
||||
|
||||
|
||||
def _load_module(module_name: str):
|
||||
@@ -25,22 +22,22 @@ def _load_module(module_name: str):
|
||||
|
||||
class CeleryModuleTest(SimpleTestCase):
|
||||
def test_import_requires_django_settings_module(self):
|
||||
with patch.dict(os.environ, {}, clear=True):
|
||||
with self.assertRaisesMessage(
|
||||
RuntimeError,
|
||||
"DJANGO_SETTINGS_MODULE is not set.",
|
||||
):
|
||||
_load_module("isolated_core_celery_missing")
|
||||
with patch.dict(os.environ, {}, clear=True), self.assertRaisesMessage(
|
||||
RuntimeError,
|
||||
"DJANGO_SETTINGS_MODULE is not set.",
|
||||
):
|
||||
_load_module("isolated_core_celery_missing")
|
||||
|
||||
def test_import_runs_startup_checks_for_worker_runtime(self):
|
||||
app_mock = MagicMock()
|
||||
app_mock.conf = SimpleNamespace()
|
||||
|
||||
with patch.dict(os.environ, {"DJANGO_SETTINGS_MODULE": "settings.test"}, clear=True):
|
||||
with patch.object(sys, "argv", ["celery", "-A", "project", "worker"]):
|
||||
with patch("apps.core.startup_checks.run_startup_checks") as checks_mock:
|
||||
with patch("celery.Celery", return_value=app_mock):
|
||||
module = _load_module("isolated_core_celery_worker")
|
||||
with patch.dict(
|
||||
os.environ, {"DJANGO_SETTINGS_MODULE": "settings.test"}, clear=True
|
||||
), patch.object(sys, "argv", ["celery", "-A", "project", "worker"]), patch(
|
||||
"apps.core.startup_checks.run_startup_checks"
|
||||
) as checks_mock, patch("celery.Celery", return_value=app_mock):
|
||||
module = _load_module("isolated_core_celery_worker")
|
||||
|
||||
checks_mock.assert_called_once_with(component="celery")
|
||||
app_mock.config_from_object.assert_called_once_with(
|
||||
@@ -51,9 +48,10 @@ class CeleryModuleTest(SimpleTestCase):
|
||||
self.assertEqual(module.app, app_mock)
|
||||
|
||||
def test_debug_task_prints_request(self):
|
||||
with patch.dict(os.environ, {"DJANGO_SETTINGS_MODULE": "settings.test"}, clear=True):
|
||||
with patch.object(sys, "argv", ["python", "manage.py", "shell"]):
|
||||
module = _load_module("isolated_core_celery_debug")
|
||||
with patch.dict(
|
||||
os.environ, {"DJANGO_SETTINGS_MODULE": "settings.test"}, clear=True
|
||||
), patch.object(sys, "argv", ["python", "manage.py", "shell"]):
|
||||
module = _load_module("isolated_core_celery_debug")
|
||||
|
||||
with patch("builtins.print") as print_mock:
|
||||
module.debug_task.run()
|
||||
|
||||
@@ -17,6 +17,8 @@ class PaginationSchemaTest(SimpleTestCase):
|
||||
)
|
||||
|
||||
self.assertEqual(schema["type"], "object")
|
||||
pagination = schema["properties"]["meta"]["properties"]["pagination"]["properties"]
|
||||
pagination = schema["properties"]["meta"]["properties"]["pagination"][
|
||||
"properties"
|
||||
]
|
||||
self.assertIn("next_cursor", pagination)
|
||||
self.assertIn("previous_cursor", pagination)
|
||||
|
||||
@@ -10,11 +10,15 @@ from apps.core import startup_checks
|
||||
from django.test import SimpleTestCase, override_settings
|
||||
|
||||
|
||||
def _db_secret() -> str:
|
||||
return "secret"
|
||||
|
||||
|
||||
TEST_DATABASES = {
|
||||
"default": {
|
||||
"NAME": "mostovik",
|
||||
"USER": "postgres",
|
||||
"PASSWORD": "secret",
|
||||
"PASSWORD": _db_secret(),
|
||||
"HOST": "db.example.test",
|
||||
"PORT": 5432,
|
||||
"OPTIONS": {"sslmode": "require"},
|
||||
@@ -45,7 +49,7 @@ class StartupChecksTest(SimpleTestCase):
|
||||
connect_mock.assert_called_once_with(
|
||||
dbname="mostovik",
|
||||
user="postgres",
|
||||
password="secret",
|
||||
password=_db_secret(),
|
||||
host="db.example.test",
|
||||
port=5432,
|
||||
connect_timeout=7,
|
||||
@@ -143,7 +147,9 @@ class StartupChecksTest(SimpleTestCase):
|
||||
STARTUP_REDIS_TIMEOUT_SECONDS=12,
|
||||
)
|
||||
@patch("apps.core.startup_checks._check_db", return_value=(True, "OK"))
|
||||
@patch("apps.core.startup_checks._check_redis", return_value=(False, "redis failed"))
|
||||
@patch(
|
||||
"apps.core.startup_checks._check_redis", return_value=(False, "redis failed")
|
||||
)
|
||||
@patch("apps.core.startup_checks._log")
|
||||
def test_run_startup_checks_exits_on_redis_failure(
|
||||
self,
|
||||
@@ -173,13 +179,13 @@ class EntryPointImportTest(SimpleTestCase):
|
||||
|
||||
with patch.dict(os.environ, {}, clear=False):
|
||||
os.environ.pop("DJANGO_SETTINGS_MODULE", None)
|
||||
with patch.dict(sys.modules, {"core.celery": celery_stub}):
|
||||
with patch("apps.core.startup_checks.run_startup_checks") as checks_mock:
|
||||
with patch(
|
||||
"django.core.asgi.get_asgi_application",
|
||||
return_value=sentinel_application,
|
||||
):
|
||||
module = self._import_fresh("core.asgi")
|
||||
with patch.dict(sys.modules, {"core.celery": celery_stub}), patch(
|
||||
"apps.core.startup_checks.run_startup_checks"
|
||||
) as checks_mock, patch(
|
||||
"django.core.asgi.get_asgi_application",
|
||||
return_value=sentinel_application,
|
||||
):
|
||||
module = self._import_fresh("core.asgi")
|
||||
|
||||
self.assertEqual(os.environ["DJANGO_SETTINGS_MODULE"], "settings.test")
|
||||
checks_mock.assert_called_once_with(component="asgi")
|
||||
@@ -192,13 +198,13 @@ class EntryPointImportTest(SimpleTestCase):
|
||||
|
||||
with patch.dict(os.environ, {}, clear=False):
|
||||
os.environ.pop("DJANGO_SETTINGS_MODULE", None)
|
||||
with patch.dict(sys.modules, {"core.celery": celery_stub}):
|
||||
with patch("apps.core.startup_checks.run_startup_checks") as checks_mock:
|
||||
with patch(
|
||||
"django.core.wsgi.get_wsgi_application",
|
||||
return_value=sentinel_application,
|
||||
):
|
||||
module = self._import_fresh("core.wsgi")
|
||||
with patch.dict(sys.modules, {"core.celery": celery_stub}), patch(
|
||||
"apps.core.startup_checks.run_startup_checks"
|
||||
) as checks_mock, patch(
|
||||
"django.core.wsgi.get_wsgi_application",
|
||||
return_value=sentinel_application,
|
||||
):
|
||||
module = self._import_fresh("core.wsgi")
|
||||
|
||||
self.assertEqual(os.environ["DJANGO_SETTINGS_MODULE"], "settings.test")
|
||||
checks_mock.assert_called_once_with(component="wsgi")
|
||||
|
||||
Reference in New Issue
Block a user