summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Bangert <ben@groovie.org>2020-07-30 10:51:36 -0700
committerGitHub <noreply@github.com>2020-07-30 10:51:36 -0700
commiteac7fc413a583a1009541f5240380179b04fb18c (patch)
tree1096e653c9994350ca0c2fbcd1ed13c3661f0373
parent9cd647a12f38de5082f4c052c2f355858b65f724 (diff)
parentbb7694b2ca8ac55a2bb671cc4c91fd55b3b8cc18 (diff)
downloadroutes-eac7fc413a583a1009541f5240380179b04fb18c.tar.gz
Merge pull request #88 from the-code-robot/master
Add conditions to Mapper.extend.
-rw-r--r--routes/mapper.py6
-rw-r--r--setup.py2
-rw-r--r--tests/test_functional/test_explicit_use.py30
3 files changed, 35 insertions, 3 deletions
diff --git a/routes/mapper.py b/routes/mapper.py
index eb4060a..3de0cfe 100644
--- a/routes/mapper.py
+++ b/routes/mapper.py
@@ -490,7 +490,11 @@ class Mapper(SubMapperParent):
routepath = path_prefix + route.routepath
else:
routepath = route.routepath
- self.connect(route.name, routepath, **route._kargs)
+ self.connect(route.name,
+ routepath,
+ conditions=route.conditions,
+ **route._kargs
+ )
def make_route(self, *args, **kargs):
"""Make a new Route object
diff --git a/setup.py b/setup.py
index b0dd322..1e85b77 100644
--- a/setup.py
+++ b/setup.py
@@ -60,7 +60,7 @@ setup(name="Routes",
test_suite="nose.collector",
include_package_data=True,
zip_safe=False,
- tests_require=['nose', 'webtest', 'webob', 'coverage'],
+ tests_require=["soupsieve<2.0", 'nose', 'webtest', 'webob', 'coverage'],
install_requires=[
"six",
"repoze.lru>=0.3"
diff --git a/tests/test_functional/test_explicit_use.py b/tests/test_functional/test_explicit_use.py
index ccd3b7a..b1e1cd7 100644
--- a/tests/test_functional/test_explicit_use.py
+++ b/tests/test_functional/test_explicit_use.py
@@ -1,6 +1,6 @@
"""test_explicit_use"""
import os, sys, time, unittest
-from nose.tools import eq_, assert_raises
+from nose.tools import eq_, assert_raises, assert_is_none
from routes import *
from routes.route import Route
@@ -101,6 +101,34 @@ class TestUtils(unittest.TestCase):
map.extend(routes)
eq_(map.match('/foo'), {})
+ def test_add_routes_conditions_unmet(self):
+ map = Mapper(explicit=True)
+ map.minimization = False
+ routes = [
+ Route('foo', '/foo', conditions=dict(method=["POST"]))
+ ]
+ environ = {
+ 'HTTP_HOST': 'localhost.com',
+ 'PATH_INFO': '/foo',
+ 'REQUEST_METHOD': 'GET',
+ }
+ map.extend(routes)
+ assert_is_none(map.match('/foo', environ=environ))
+
+ def test_add_routes_conditions_met(self):
+ map = Mapper(explicit=True)
+ map.minimization = False
+ routes = [
+ Route('foo', '/foo', conditions=dict(method=["POST"]))
+ ]
+ environ = {
+ 'HTTP_HOST': 'localhost.com',
+ 'PATH_INFO': '/foo',
+ 'REQUEST_METHOD': 'POST',
+ }
+ map.extend(routes)
+ eq_(map.match('/foo', environ=environ), {})
+
def test_using_func(self):
def fred(view):
pass