build endpoint description strings from runserver arguments before ca… (#434)

* build endpoint description strings from runserver arguments before calling dpahne server

* Update Daphne requirement
This commit is contained in:
Sean Mc Allister 2017-01-09 03:10:56 +01:00 committed by Andrew Godwin
parent 577dfa1eee
commit d9bff34428
3 changed files with 11 additions and 9 deletions

View File

@ -2,7 +2,7 @@ import datetime
import sys
import threading
from daphne.server import Server
from daphne.server import Server, build_endpoint_description_strings
from django.conf import settings
from django.core.management.commands.runserver import Command as RunserverCommand
from django.utils import six
@ -75,11 +75,13 @@ class Command(RunserverCommand):
# Launch server in 'main' thread. Signals are disabled as it's still
# actually a subthread under the autoreloader.
self.logger.debug("Daphne running, listening on %s:%s", self.addr, self.port)
# build the endpoint description string from host/port options
endpoints = build_endpoint_description_strings(host=self.addr, port=self.port)
try:
Server(
channel_layer=self.channel_layer,
host=self.addr,
port=int(self.port),
endpoints=endpoints,
signal_handlers=not options['use_reloader'],
action_logger=self.log_action,
http_timeout=self.http_timeout,

View File

@ -88,12 +88,12 @@ class RunServerTests(TestCase):
@mock.patch('channels.management.commands.runworker.Worker')
def test_runserver_basic(self, mocked_worker, mocked_server, mock_stdout):
# Django's autoreload util uses threads and this is not needed
# in the test envirionment.
# in the test environment.
# See:
# https://github.com/django/django/blob/master/django/core/management/commands/runserver.py#L105
call_command('runserver', '--noreload')
mocked_server.assert_called_with(
port=8000,
endpoints=['tcp:port=8000:interface=127.0.0.1'],
signal_handlers=True,
http_timeout=60,
host='127.0.0.1',
@ -114,7 +114,7 @@ class RunServerTests(TestCase):
with self.settings(DEBUG=True, STATIC_URL='/static/'):
call_command('runserver', '--noreload')
mocked_server.assert_called_with(
port=8000,
endpoints=['tcp:port=8000:interface=127.0.0.1'],
signal_handlers=True,
http_timeout=60,
host='127.0.0.1',
@ -126,7 +126,7 @@ class RunServerTests(TestCase):
call_command('runserver', '--noreload', 'localhost:8001')
mocked_server.assert_called_with(
port=8001,
endpoints=['tcp:port=8001:interface=127.0.0.1'],
signal_handlers=True,
http_timeout=60,
host='localhost',
@ -150,7 +150,7 @@ class RunServerTests(TestCase):
'''
call_command('runserver', '--noreload', '--noworker')
mocked_server.assert_called_with(
port=8000,
endpoints=['tcp:port=8000:interface=127.0.0.1'],
signal_handlers=True,
http_timeout=60,
host='127.0.0.1',

View File

@ -14,6 +14,6 @@ setup(
install_requires=[
'Django>=1.8',
'asgiref>=0.13',
'daphne>=0.14.1',
'daphne>=1.0.0',
]
)