sanic/tests
Jeong YunWon a15ee3ad06 Fix sanic_endpoint_test working with redirects
Before fix, it raises error like:

```
tests/test_utils.py F

================================= FAILURES =================================
______________________________ test_redirect _______________________________

app = <sanic.sanic.Sanic object at 0x1045fda20>, method = 'get', uri = '/1', gather_request = True, debug = False
server_kwargs = {}, request_args = (), request_kwargs = {}
_collect_request = <function sanic_endpoint_test.<locals>._collect_request at 0x1045ec950>
_collect_response = <function sanic_endpoint_test.<locals>._collect_response at 0x1045ec7b8>

    def sanic_endpoint_test(app, method='get', uri='/', gather_request=True,
                            debug=False, server_kwargs={},
                            *request_args, **request_kwargs):
        results = []
        exceptions = []

        if gather_request:
            def _collect_request(request):
                results.append(request)
            app.request_middleware.appendleft(_collect_request)

        async def _collect_response(sanic, loop):
            try:
                response = await local_request(method, uri, *request_args,
                                               **request_kwargs)
                results.append(response)
            except Exception as e:
                exceptions.append(e)
            app.stop()

        app.run(host=HOST, debug=debug, port=PORT,
                after_start=_collect_response, **server_kwargs)

        if exceptions:
            raise ValueError("Exception during request: {}".format(exceptions))

        if gather_request:
            try:
>               request, response = results
E               ValueError: too many values to unpack (expected 2)

sanic/utils.py:47: ValueError

During handling of the above exception, another exception occurred:

utils_app = <sanic.sanic.Sanic object at 0x1045fda20>

    def test_redirect(utils_app):
        """Test sanic_endpoint_test is working for redirection"""
>       request, response = sanic_endpoint_test(utils_app, uri='/1')

tests/test_utils.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

app = <sanic.sanic.Sanic object at 0x1045fda20>, method = 'get', uri = '/1', gather_request = True, debug = False
server_kwargs = {}, request_args = (), request_kwargs = {}
_collect_request = <function sanic_endpoint_test.<locals>._collect_request at 0x1045ec950>
_collect_response = <function sanic_endpoint_test.<locals>._collect_response at 0x1045ec7b8>

    def sanic_endpoint_test(app, method='get', uri='/', gather_request=True,
                            debug=False, server_kwargs={},
                            *request_args, **request_kwargs):
        results = []
        exceptions = []

        if gather_request:
            def _collect_request(request):
                results.append(request)
            app.request_middleware.appendleft(_collect_request)

        async def _collect_response(sanic, loop):
            try:
                response = await local_request(method, uri, *request_args,
                                               **request_kwargs)
                results.append(response)
            except Exception as e:
                exceptions.append(e)
            app.stop()

        app.run(host=HOST, debug=debug, port=PORT,
                after_start=_collect_response, **server_kwargs)

        if exceptions:
            raise ValueError("Exception during request: {}".format(exceptions))

        if gather_request:
            try:
                request, response = results
                return request, response
            except:
                raise ValueError(
                    "Request and response object expected, got ({})".format(
>                       results))
E               ValueError: Request and response object expected, got ([{}, {}, {}, <ClientResponse(http://127.0.0.1:42101/3) [200 OK]>
E               <CIMultiDictProxy('Content-Type': 'text/plain; charset=utf-8', 'Content-Length': '2', 'Connection': 'keep-alive', 'Keep-Alive': 'timeout=1')>
E               ])

sanic/utils.py:52: ValueError
```
2017-02-05 13:57:04 +09:00
..
performance Make golang performance test return JSON instead of string 2016-12-24 10:28:34 +01:00
static Rewrite static files tests 2016-12-24 18:18:56 -08:00
test_bad_request.py Change HttpParserError process 2016-12-18 09:25:39 +09:00
test_blueprints.py . 2017-01-29 23:21:00 -08:00
test_config.py added tests and small fixes for config 2016-12-16 18:46:07 +01:00
test_cookies.py Merge branch 'master' into cookie-usability 2017-01-25 21:24:30 -08:00
test_custom_protocol.py Add test and example for custom protocol 2016-12-26 23:41:10 +09:00
test_dynamic_routes.py Add logic to make dynamic route merging work 2017-01-29 15:16:07 -06:00
test_exceptions_handler.py html and tests pass 2017-01-12 19:54:34 -05:00
test_exceptions.py set error handler debug from run debug arg 2017-01-24 17:24:06 -08:00
test_logging.py Move serve_multiple, fix tests (#357) 2017-01-27 19:34:21 -06:00
test_middleware.py Use `isinstance( instead of issubclass(type(` 2017-01-27 11:11:29 +01:00
test_multiprocessing.py Move serve_multiple, fix tests (#357) 2017-01-27 19:34:21 -06:00
test_payload_too_large.py Change Payload Too Large process 2016-12-04 10:50:32 +09:00
test_redirect.py Fix sanic_endpoint_test working with redirects 2017-02-05 13:57:04 +09:00
test_request_data.py Adding a new line 2016-11-23 11:03:00 -06:00
test_request_timeout.py Fix test_request_timeout.py 2016-12-06 10:44:08 +09:00
test_requests.py Fix sanic_endpoint_test working with redirects 2017-02-05 13:57:04 +09:00
test_response.py Add test for PR: #215 2016-12-24 18:47:15 -08:00
test_routes.py Merge pull request #320 from r0fls/method-decorators 2017-01-20 14:38:34 -06:00
test_server_events.py Update request.form to work with __getitem__ 2017-01-11 16:55:34 -06:00
test_signal_handlers.py remove loop as argument and update examples 2017-01-26 17:38:46 -08:00
test_static.py Updates static tests to test for issue #374 2017-02-01 09:00:57 -06:00
test_utf8.py Reformatted code to use spaces instead of tabs 2016-10-14 19:53:49 -07:00
test_vhosts.py allow using a list of hosts on a route 2017-01-18 19:41:32 -08:00
test_views.py Switch them to verifying headers instead 2017-01-27 22:13:16 -06:00