mirror of
https://github.com/Dispatcharr/Dispatcharr.git
synced 2026-07-17 16:50:53 +00:00
- Added `dispatcharr.settings_test` for isolated testing, automatically creating an empty PostgreSQL test database and ensuring transaction isolation during tests. - Updated `manage.py` to switch to the test settings when running tests. - Enhanced the CONTRIBUTING.md file with detailed instructions on running the backend test suite and handling Celery tasks in tests. - Refactored test cases to use static methods for `worker_id` in `test_process_label.py` and adjusted assertions in `test_user_preferences.py` for better clarity and correctness.
29 lines
1.2 KiB
Python
29 lines
1.2 KiB
Python
from unittest.mock import patch
|
|
|
|
from django.test import SimpleTestCase
|
|
|
|
from dispatcharr.db.process_label import get_process_role
|
|
|
|
|
|
class ProcessLabelTests(SimpleTestCase):
|
|
def test_celery_worker_not_labeled_as_uwsgi(self):
|
|
role = get_process_role(
|
|
["/dispatcharrpy/bin/celery", "-A", "dispatcharr", "worker"]
|
|
)
|
|
self.assertEqual(role, "celery-worker")
|
|
|
|
def test_uwsgi_labeled_from_argv(self):
|
|
role = get_process_role(["/dispatcharrpy/bin/uwsgi", "--ini", "/app/docker/uwsgi.ini"])
|
|
self.assertEqual(role, "uwsgi")
|
|
|
|
def test_uwsgi_labeled_when_worker_module_present(self):
|
|
fake_uwsgi = type("uwsgi", (), {"worker_id": staticmethod(lambda: 2)})()
|
|
with patch.dict("sys.modules", {"uwsgi": fake_uwsgi}):
|
|
role = get_process_role(["/dispatcharrpy/bin/python", "-c", "pass"])
|
|
self.assertEqual(role, "uwsgi")
|
|
|
|
def test_uwsgi_master_not_labeled_as_uwsgi(self):
|
|
fake_uwsgi = type("uwsgi", (), {"worker_id": staticmethod(lambda: 0)})()
|
|
with patch.dict("sys.modules", {"uwsgi": fake_uwsgi}):
|
|
role = get_process_role(["/dispatcharrpy/bin/python", "-c", "pass"])
|
|
self.assertEqual(role, "django")
|