mirror of
https://github.com/django/daphne.git
synced 2024-11-11 02:26:35 +03:00
test mixed endpoints and some cleanup
This commit is contained in:
parent
f115f808c3
commit
a2458ac47c
|
@ -115,7 +115,6 @@ class CommandLineInterface(object):
|
||||||
action='store_true',
|
action='store_true',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
self.server = None
|
self.server = None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
@ -163,7 +163,6 @@ class Server(object):
|
||||||
self.factory.check_timeouts()
|
self.factory.check_timeouts()
|
||||||
reactor.callLater(2, self.timeout_checker)
|
reactor.callLater(2, self.timeout_checker)
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def build_endpoint_description_strings(
|
def build_endpoint_description_strings(
|
||||||
host=None,
|
host=None,
|
||||||
|
|
|
@ -2,16 +2,14 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from six import string_types
|
from six import string_types
|
||||||
import pkgutil
|
import logging
|
||||||
|
|
||||||
from ..server import Server
|
from ..server import Server
|
||||||
from ..cli import CommandLineInterface
|
from ..cli import CommandLineInterface
|
||||||
|
|
||||||
# this is the callable that will be tested here
|
# this is the callable that will be tested here
|
||||||
build = Server.build_endpoint_description_strings
|
build = Server.build_endpoint_description_strings
|
||||||
|
|
||||||
# patch out the servers run function
|
|
||||||
Server.run = lambda x: x
|
|
||||||
|
|
||||||
|
|
||||||
class TestEndpointDescriptions(TestCase):
|
class TestEndpointDescriptions(TestCase):
|
||||||
|
|
||||||
|
@ -74,6 +72,17 @@ class TestCLIInterface(TestCase):
|
||||||
# construct a string that will be accepted as the channel_layer argument
|
# construct a string that will be accepted as the channel_layer argument
|
||||||
_import_channel_layer_string = 'daphne.tests.asgi:channel_layer'
|
_import_channel_layer_string = 'daphne.tests.asgi:channel_layer'
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
logging.disable(logging.CRITICAL)
|
||||||
|
# patch out the servers run method
|
||||||
|
self._default_server_run = Server.run
|
||||||
|
Server.run = lambda x: x
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
logging.disable(logging.NOTSET)
|
||||||
|
# restore the original server run method
|
||||||
|
Server.run = self._default_server_run
|
||||||
|
|
||||||
def build_cli(self, cli_args=''):
|
def build_cli(self, cli_args=''):
|
||||||
# split the string and append the channel_layer positional argument
|
# split the string and append the channel_layer positional argument
|
||||||
if isinstance(cli_args, string_types):
|
if isinstance(cli_args, string_types):
|
||||||
|
@ -118,7 +127,7 @@ class TestCLIInterface(TestCase):
|
||||||
['tcp:port=8080:interface=example.com']
|
['tcp:port=8080:interface=example.com']
|
||||||
)
|
)
|
||||||
|
|
||||||
def testMixedCLIEndpoints(self):
|
def testCLIEndpointCreation(self):
|
||||||
self.checkCLI(
|
self.checkCLI(
|
||||||
'-p 8080 -u /tmp/daphne.sock',
|
'-p 8080 -u /tmp/daphne.sock',
|
||||||
[
|
[
|
||||||
|
@ -146,6 +155,26 @@ class TestCLIInterface(TestCase):
|
||||||
'File descriptor and unix socket bound, TCP ignored.'
|
'File descriptor and unix socket bound, TCP ignored.'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def testMixedCLIEndpointCreation(self):
|
||||||
|
|
||||||
|
self.checkCLI(
|
||||||
|
'-p 8080 -e unix:/tmp/daphne.sock',
|
||||||
|
[
|
||||||
|
'tcp:port=8080:interface=127.0.0.1',
|
||||||
|
'unix:/tmp/daphne.sock'
|
||||||
|
],
|
||||||
|
'Mix host/port args with endpoint args'
|
||||||
|
)
|
||||||
|
|
||||||
|
self.checkCLI(
|
||||||
|
'-p 8080 -e tcp:port=8080:interface=127.0.0.1',
|
||||||
|
[
|
||||||
|
'tcp:port=8080:interface=127.0.0.1',
|
||||||
|
] * 2,
|
||||||
|
'Do not try to de-duplicate endpoint description strings.'
|
||||||
|
'This would fail when running the server.'
|
||||||
|
)
|
||||||
|
|
||||||
def testCustomEndpoints(self):
|
def testCustomEndpoints(self):
|
||||||
self.checkCLI(
|
self.checkCLI(
|
||||||
'-e imap:',
|
'-e imap:',
|
||||||
|
|
Loading…
Reference in New Issue
Block a user