summaryrefslogtreecommitdiff
path: root/tests/test_config/test_routes.py
diff options
context:
space:
mode:
authorMichael Merickel <michael@merickel.org>2018-10-15 01:55:54 -0500
committerMichael Merickel <michael@merickel.org>2018-10-15 09:24:07 -0500
commit0c29cf2df41600d3906d521c72991c7686018b71 (patch)
treeff907f90ec9467e12874c9b2c961549d0e7caf74 /tests/test_config/test_routes.py
parent851c368e3c158e264358de10446f5b5de240e534 (diff)
downloadpyramid-0c29cf2df41600d3906d521c72991c7686018b71.tar.gz
pyramid-0c29cf2df41600d3906d521c72991c7686018b71.tar.bz2
pyramid-0c29cf2df41600d3906d521c72991c7686018b71.zip
format source using black
Diffstat (limited to 'tests/test_config/test_routes.py')
-rw-r--r--tests/test_config/test_routes.py55
1 files changed, 38 insertions, 17 deletions
diff --git a/tests/test_config/test_routes.py b/tests/test_config/test_routes.py
index 870abe0ee..0999f8072 100644
--- a/tests/test_config/test_routes.py
+++ b/tests/test_config/test_routes.py
@@ -4,14 +4,17 @@ from . import dummyfactory
from . import DummyContext
from pyramid.compat import text_
+
class RoutesConfiguratorMixinTests(unittest.TestCase):
def _makeOne(self, *arg, **kw):
from pyramid.config import Configurator
+
config = Configurator(*arg, **kw)
return config
def _assertRoute(self, config, name, path, num_predicates=0):
from pyramid.interfaces import IRoutesMapper
+
mapper = config.registry.getUtility(IRoutesMapper)
routes = mapper.get_routes()
route = routes[0]
@@ -33,6 +36,7 @@ class RoutesConfiguratorMixinTests(unittest.TestCase):
def test_get_routes_mapper_already_registered(self):
from pyramid.interfaces import IRoutesMapper
+
config = self._makeOne()
mapper = object()
config.registry.registerUtility(mapper, IRoutesMapper)
@@ -53,8 +57,9 @@ class RoutesConfiguratorMixinTests(unittest.TestCase):
def test_add_route_discriminator(self):
config = self._makeOne()
config.add_route('name', 'path')
- self.assertEqual(config.action_state.actions[-1]['discriminator'],
- ('route', 'name'))
+ self.assertEqual(
+ config.action_state.actions[-1]['discriminator'], ('route', 'name')
+ )
def test_add_route_with_factory(self):
config = self._makeOne(autocommit=True)
@@ -68,13 +73,13 @@ class RoutesConfiguratorMixinTests(unittest.TestCase):
config.add_route('name', 'path/{foo}', static=True)
mapper = config.get_routes_mapper()
self.assertEqual(len(mapper.get_routes()), 0)
- self.assertEqual(mapper.generate('name', {"foo":"a"}), '/path/a')
+ self.assertEqual(mapper.generate('name', {"foo": "a"}), '/path/a')
def test_add_route_with_factory_dottedname(self):
config = self._makeOne(autocommit=True)
config.add_route(
- 'name', 'path',
- factory='tests.test_config.dummyfactory')
+ 'name', 'path', factory='tests.test_config.dummyfactory'
+ )
route = self._assertRoute(config, 'name', 'path')
self.assertEqual(route.factory, dummyfactory)
@@ -116,8 +121,9 @@ class RoutesConfiguratorMixinTests(unittest.TestCase):
def test_add_route_with_path_info_highorder(self):
config = self._makeOne(autocommit=True)
- config.add_route('name', 'path',
- path_info=text_(b'/La Pe\xc3\xb1a', 'utf-8'))
+ config.add_route(
+ 'name', 'path', path_info=text_(b'/La Pe\xc3\xb1a', 'utf-8')
+ )
route = self._assertRoute(config, 'name', 'path', 1)
predicate = route.predicates[0]
request = self._makeRequest(config)
@@ -129,8 +135,9 @@ class RoutesConfiguratorMixinTests(unittest.TestCase):
def test_add_route_with_path_info_regex(self):
config = self._makeOne(autocommit=True)
- config.add_route('name', 'path',
- path_info=text_(br'/La Pe\w*', 'utf-8'))
+ config.add_route(
+ 'name', 'path', path_info=text_(br'/La Pe\w*', 'utf-8')
+ )
route = self._assertRoute(config, 'name', 'path', 1)
predicate = route.predicates[0]
request = self._makeRequest(config)
@@ -146,7 +153,7 @@ class RoutesConfiguratorMixinTests(unittest.TestCase):
route = self._assertRoute(config, 'name', 'path', 1)
predicate = route.predicates[0]
request = self._makeRequest(config)
- request.params = {'abc':'123'}
+ request.params = {'abc': '123'}
self.assertEqual(predicate(None, request), True)
request = self._makeRequest(config)
request.params = {}
@@ -154,9 +161,15 @@ class RoutesConfiguratorMixinTests(unittest.TestCase):
def test_add_route_with_custom_predicates(self):
import warnings
+
config = self._makeOne(autocommit=True)
- def pred1(context, request): pass
- def pred2(context, request): pass
+
+ def pred1(context, request):
+ pass
+
+ def pred2(context, request):
+ pass
+
with warnings.catch_warnings(record=True) as w:
warnings.filterwarnings('always')
config.add_route('name', 'path', custom_predicates=(pred1, pred2))
@@ -170,7 +183,7 @@ class RoutesConfiguratorMixinTests(unittest.TestCase):
route = self._assertRoute(config, 'name', 'path', 1)
predicate = route.predicates[0]
request = self._makeRequest(config)
- request.headers = {'Host':'example.com'}
+ request.headers = {'Host': 'example.com'}
self.assertEqual(predicate(None, request), True)
request = self._makeRequest(config)
request.headers = {}
@@ -222,6 +235,7 @@ class RoutesConfiguratorMixinTests(unittest.TestCase):
def test_add_route_no_path_no_pattern(self):
from pyramid.exceptions import ConfigurationError
+
config = self._makeOne()
self.assertRaises(ConfigurationError, config.add_route, 'name')
@@ -234,46 +248,52 @@ class RoutesConfiguratorMixinTests(unittest.TestCase):
def test_add_route_no_view_with_view_attr(self):
config = self._makeOne(autocommit=True)
from pyramid.exceptions import ConfigurationError
+
try:
config.add_route('name', '/pattern', view_attr='abc')
except ConfigurationError:
pass
- else: # pragma: no cover
+ else: # pragma: no cover
raise AssertionError
def test_add_route_no_view_with_view_context(self):
config = self._makeOne(autocommit=True)
from pyramid.exceptions import ConfigurationError
+
try:
config.add_route('name', '/pattern', view_context=DummyContext)
except ConfigurationError:
pass
- else: # pragma: no cover
+ else: # pragma: no cover
raise AssertionError
def test_add_route_no_view_with_view_permission(self):
config = self._makeOne(autocommit=True)
from pyramid.exceptions import ConfigurationError
+
try:
config.add_route('name', '/pattern', view_permission='edit')
except ConfigurationError:
pass
- else: # pragma: no cover
+ else: # pragma: no cover
raise AssertionError
def test_add_route_no_view_with_view_renderer(self):
config = self._makeOne(autocommit=True)
from pyramid.exceptions import ConfigurationError
+
try:
config.add_route('name', '/pattern', view_renderer='json')
except ConfigurationError:
pass
- else: # pragma: no cover
+ else: # pragma: no cover
raise AssertionError
+
class DummyRequest:
subpath = ()
matchdict = None
+
def __init__(self, environ=None):
if environ is None:
environ = {}
@@ -281,6 +301,7 @@ class DummyRequest:
self.params = {}
self.cookies = {}
+
class DummyAccept(object):
def __init__(self, *matches, **kw):
self.matches = list(matches)