mirror of
https://github.com/django/daphne.git
synced 2025-07-29 00:19:45 +03:00
Provide a way to disable static files serving in the live server test case. (#603)
This allows it to be turned off (it's on by default)
This commit is contained in:
parent
31cd68c89b
commit
5648da5d34
|
@ -2,6 +2,7 @@ import multiprocessing
|
|||
|
||||
import django
|
||||
from daphne.server import Server
|
||||
from django.apps import apps
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.db import connections
|
||||
from django.db.utils import load_backend
|
||||
|
@ -67,13 +68,14 @@ class ProcessSetup(multiprocessing.Process):
|
|||
class WorkerProcess(ProcessSetup):
|
||||
|
||||
def __init__(self, is_ready, n_threads, overridden_settings,
|
||||
modified_settings, databases):
|
||||
modified_settings, databases, serve_static):
|
||||
|
||||
self.is_ready = is_ready
|
||||
self.n_threads = n_threads
|
||||
self.overridden_settings = overridden_settings
|
||||
self.modified_settings = modified_settings
|
||||
self.databases = databases
|
||||
self.serve_static = serve_static
|
||||
super(WorkerProcess, self).__init__()
|
||||
self.daemon = True
|
||||
|
||||
|
@ -82,9 +84,11 @@ class WorkerProcess(ProcessSetup):
|
|||
try:
|
||||
self.common_setup()
|
||||
channel_layers = ChannelLayerManager()
|
||||
channel_layers[DEFAULT_CHANNEL_LAYER].router.check_default(
|
||||
http_consumer=StaticFilesConsumer(),
|
||||
)
|
||||
check_default = channel_layers[DEFAULT_CHANNEL_LAYER].router.check_default
|
||||
if self.serve_static and apps.is_installed('django.contrib.staticfiles'):
|
||||
check_default(http_consumer=StaticFilesConsumer())
|
||||
else:
|
||||
check_default()
|
||||
if self.n_threads == 1:
|
||||
self.worker = Worker(
|
||||
channel_layer=channel_layers[DEFAULT_CHANNEL_LAYER],
|
||||
|
@ -153,6 +157,7 @@ class ChannelLiveServerTestCase(TransactionTestCase):
|
|||
ProtocolServerProcess = DaphneProcess
|
||||
WorkerProcess = WorkerProcess
|
||||
worker_threads = 1
|
||||
serve_static = True
|
||||
|
||||
@property
|
||||
def live_server_url(self):
|
||||
|
@ -204,6 +209,7 @@ class ChannelLiveServerTestCase(TransactionTestCase):
|
|||
self._overridden_settings,
|
||||
self._modified_settings,
|
||||
connections.databases,
|
||||
self.serve_static,
|
||||
)
|
||||
self._worker_process.start()
|
||||
worker_ready.wait()
|
||||
|
|
|
@ -325,3 +325,16 @@ infrastructure is ready default web browser will be also started. You
|
|||
can open your website in the real browser which can execute JavaScript
|
||||
and operate on WebSockets. ``live_server_ws_url`` property is also
|
||||
provided if you decide to run messaging directly from Python.
|
||||
|
||||
By default live server test case will serve static files. To disable
|
||||
this feature override `serve_static` class attribute.
|
||||
|
||||
.. code:: python
|
||||
|
||||
class IntegrationTest(ChannelLiveServerTestCase):
|
||||
|
||||
serve_static = False
|
||||
|
||||
def test_websocket_message(self):
|
||||
# JS and CSS are not available in this test.
|
||||
...
|
||||
|
|
Loading…
Reference in New Issue
Block a user