From 051ff2b325529a3d4953228df1d4de7d30236a23 Mon Sep 17 00:00:00 2001 From: Suby Raman Date: Mon, 13 Feb 2017 11:50:09 -0500 Subject: [PATCH] remove repr stuff --- sanic/router.py | 22 ---------------------- tests/test_views.py | 18 +++++++++++++----- 2 files changed, 13 insertions(+), 27 deletions(-) diff --git a/sanic/router.py b/sanic/router.py index 621d3733..c115b362 100644 --- a/sanic/router.py +++ b/sanic/router.py @@ -69,28 +69,6 @@ class Router: self.routes_always_check = [] self.hosts = None - def __str__(self): - """ - The typical user inspecting the router will likely want to see - the routes available. Provide a simple representation. - """ - def _route_to_str(uri, route): - out = 'name={0.name}, methods={0.methods}, URI={1}>\n'.format( - route, uri) - - if route.handler.__doc__: - out += '{}\n'.format(route.handler.__doc__) - - out += '\n' - - return out - - out = '' - for uri, route in self.routes_all.items(): - out += _route_to_str(uri, route) - - return out - def parse_parameter_string(self, parameter_string): """ Parse a parameter string into its constituent name, type, and pattern diff --git a/tests/test_views.py b/tests/test_views.py index afa52d8b..ec0b91b8 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -223,7 +223,8 @@ def test_composition_view_rejects_duplicate_methods(): assert str(e.value) == 'Method GET is already registered.' -def test_composition_view_runs_methods_as_expected(): +@pytest.mark.parametrize('method', HTTP_METHODS) +def test_composition_view_runs_methods_as_expected(method): app = Sanic('test_composition_view') view = CompositionView() @@ -232,22 +233,29 @@ def test_composition_view_runs_methods_as_expected(): app.add_route(view, '/') - for method in ['GET', 'POST', 'PUT']: + if method in ['GET', 'POST', 'PUT']: request, response = sanic_endpoint_test(app, uri='/', method=method) assert response.text == 'first method' - for method in ['DELETE', 'PATCH']: + if method in ['DELETE', 'PATCH']: request, response = sanic_endpoint_test(app, uri='/', method=method) assert response.text == 'second method' -def test_composition_view_rejects_invalid_methods(): +@pytest.mark.parametrize('method', HTTP_METHODS) +def test_composition_view_rejects_invalid_methods(method): app = Sanic('test_composition_view') view = CompositionView() view.add(['GET', 'POST', 'PUT'], lambda x: text('first method')) app.add_route(view, '/') - for method in ['DELETE', 'PATCH']: + + if method in ['GET', 'POST', 'PUT']: + request, response = sanic_endpoint_test(app, uri='/', method=method) + assert response.status == 200 + assert response.text == 'first method' + + if method in ['DELETE', 'PATCH']: request, response = sanic_endpoint_test(app, uri='/', method=method) assert response.status == 405