mirror of
https://github.com/django/daphne.git
synced 2025-07-14 18:02:17 +03:00
Posting tests
This commit is contained in:
parent
15cbc69e36
commit
48db541d54
|
@ -1,12 +1,12 @@
|
||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
|
from argparse import ArgumentError, Namespace
|
||||||
|
|
||||||
from .access import AccessLogGenerator
|
from .access import AccessLogGenerator
|
||||||
from .endpoints import build_endpoint_description_strings
|
from .endpoints import build_endpoint_description_strings
|
||||||
from .server import Server
|
from .server import Server
|
||||||
from .utils import import_by_path
|
from .utils import import_by_path
|
||||||
from argparse import ArgumentError, Namespace
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -198,8 +198,6 @@ class CommandLineInterface(object):
|
||||||
if args.proxy_headers:
|
if args.proxy_headers:
|
||||||
return "X-Forwarded-Port"
|
return "X-Forwarded-Port"
|
||||||
|
|
||||||
def run(self, args):
|
|
||||||
|
|
||||||
def run(self, args):
|
def run(self, args):
|
||||||
"""
|
"""
|
||||||
Pass in raw argument list and it will decode them
|
Pass in raw argument list and it will decode them
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# coding: utf8
|
# coding: utf8
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
from argparse import ArgumentError
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
from daphne.cli import CommandLineInterface
|
from daphne.cli import CommandLineInterface
|
||||||
|
@ -235,3 +236,61 @@ class TestCLIInterface(TestCase):
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_default_proxyheaders(self):
|
||||||
|
"""
|
||||||
|
Passing `--proxy-headers` without a parameter will use the
|
||||||
|
`X-Forwarded-For` header.
|
||||||
|
"""
|
||||||
|
self.assertCLI(
|
||||||
|
["--proxy-headers"],
|
||||||
|
{
|
||||||
|
"proxy_forwarded_address_header": "X-Forwarded-For",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_custom_proxyhost(self):
|
||||||
|
"""
|
||||||
|
Passing `--proxy-headers-host` will set the used host header to
|
||||||
|
the passed one, and `--proxy-headers` is mandatory.
|
||||||
|
"""
|
||||||
|
self.assertCLI(
|
||||||
|
["--proxy-headers", "--proxy-headers-host", "blah"],
|
||||||
|
{
|
||||||
|
"proxy_forwarded_address_header": "blah",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
with self.assertRaises(expected_exception=ArgumentError) as exc:
|
||||||
|
self.assertCLI(
|
||||||
|
["--proxy-headers-host", "blah"],
|
||||||
|
{
|
||||||
|
"proxy_forwarded_address_header": "blah",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
self.assertEqual(exc.exception.argument_name, "--proxy-headers-host")
|
||||||
|
self.assertEqual(
|
||||||
|
exc.exception.message,
|
||||||
|
"--proxy-headers has to be passed for this parameter.")
|
||||||
|
|
||||||
|
def test_custom_proxyport(self):
|
||||||
|
"""
|
||||||
|
Passing `--proxy-headers-port` will set the used port header to
|
||||||
|
the passed one, and `--proxy-headers` is mandatory.
|
||||||
|
"""
|
||||||
|
self.assertCLI(
|
||||||
|
["--proxy-headers", "--proxy-headers-port", "blah2"],
|
||||||
|
{
|
||||||
|
"proxy_forwarded_port_header": "blah2",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
with self.assertRaises(expected_exception=ArgumentError) as exc:
|
||||||
|
self.assertCLI(
|
||||||
|
["--proxy-headers-port", "blah2"],
|
||||||
|
{
|
||||||
|
"proxy_forwarded_address_header": "blah2",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
self.assertEqual(exc.exception.argument_name, "--proxy-headers-port")
|
||||||
|
self.assertEqual(
|
||||||
|
exc.exception.message,
|
||||||
|
"--proxy-headers has to be passed for this parameter.")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user