From 79abfaeb2047cc7972017fe8165411d8e49a6f9d Mon Sep 17 00:00:00 2001 From: Carlton Gibson Date: Fri, 5 Aug 2022 18:41:22 +0200 Subject: [PATCH] Added a unit-test for the system check. --- setup.py | 2 +- tests/test_checks.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 tests/test_checks.py diff --git a/setup.py b/setup.py index 274e8f8..ae19f5d 100755 --- a/setup.py +++ b/setup.py @@ -25,7 +25,7 @@ setup( install_requires=["twisted[tls]>=22.4", "autobahn>=22.4.2", "asgiref>=3.5.2,<4"], python_requires=">=3.7", setup_requires=["pytest-runner"], - extras_require={"tests": ["hypothesis", "pytest", "pytest-asyncio"]}, + extras_require={"tests": ["hypothesis", "pytest", "pytest-asyncio", "django"]}, entry_points={ "console_scripts": ["daphne = daphne.cli:CommandLineInterface.entrypoint"] }, diff --git a/tests/test_checks.py b/tests/test_checks.py new file mode 100644 index 0000000..48b23bd --- /dev/null +++ b/tests/test_checks.py @@ -0,0 +1,21 @@ +import django +from django.conf import settings +from django.test.utils import override_settings + +from daphne.checks import check_daphne_installed + + +def test_check_daphne_installed(): + """ + Test check error is raised if daphne is not listed before staticfiles, and vice versa. + """ + settings.configure( + INSTALLED_APPS=["daphne.apps.DaphneConfig", "django.contrib.staticfiles"] + ) + django.setup() + errors = check_daphne_installed(None) + assert len(errors) == 0 + with override_settings(INSTALLED_APPS=["django.contrib.staticfiles", "daphne"]): + errors = check_daphne_installed(None) + assert len(errors) == 1 + assert errors[0].id == "daphne.E001"