enhancement(tests): introduce isolated backend test settings and improve test documentation

- 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.
This commit is contained in:
SergeantPanda 2026-06-23 20:54:12 -05:00
parent 7b6adf62d7
commit 53fa1e42a0
6 changed files with 85 additions and 6 deletions

View file

@ -17,13 +17,13 @@ class ProcessLabelTests(SimpleTestCase):
self.assertEqual(role, "uwsgi")
def test_uwsgi_labeled_when_worker_module_present(self):
fake_uwsgi = type("uwsgi", (), {"worker_id": lambda: 2})()
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": lambda: 0})()
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")