Skip to content

Commit

Permalink
Merge pull request #536 from xiaclo/master
Browse files Browse the repository at this point in the history
fix(DefaultRouter): Regression with mixed static and dynamic route segments
  • Loading branch information
kgriffs committed May 1, 2015
2 parents 3b8f118 + efc871d commit 0af00af
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
10 changes: 3 additions & 7 deletions falcon/routing/compiled.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def line(text, indent_offset=0):
# /foo/{id}/bar
# /foo/{name}/bar
#
assert len(nodes) == 1
assert len([node for node in nodes if node.is_var]) == 1
found_simple = True

else:
Expand Down Expand Up @@ -308,10 +308,6 @@ def __init__(self, raw_segment, method_map=None, resource=None):
else:
self.is_var = False

@property
def is_simple_var(self):
return self.is_var and not self.is_complex

def matches(self, segment):
"""Returns True if this node matches the supplied template segment."""

Expand All @@ -334,7 +330,7 @@ def conflicts_with(self, segment):
# complex, simple ==> True
# complex, complex ==> False
# complex, string ==> False
# string, simple ==> True
# string, simple ==> False
# string, complex ==> False
# string, string ==> False
#
Expand Down Expand Up @@ -362,4 +358,4 @@ def conflicts_with(self, segment):
# /foo/all
return True

return other.is_simple_var
return False
22 changes: 16 additions & 6 deletions tests/test_default_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,18 @@ def setup_routes(router_interface):
router_interface.add_route(
'/repos/{org}/{repo}/compare/all', {}, ResourceWithId(11))
router_interface.add_route(
'/emojis/signs/{id}', {}, ResourceWithId(12))
'/emojis/signs/0', {}, ResourceWithId(12))
router_interface.add_route(
'/emojis/signs/{id}', {}, ResourceWithId(13))
router_interface.add_route(
'/repos/{org}/{repo}/compare/{usr0}:{branch0}...{usr1}:{branch1}/part',
{}, ResourceWithId(13))
{}, ResourceWithId(14))
router_interface.add_route(
'/repos/{org}/{repo}/compare/{usr0}:{branch0}',
{}, ResourceWithId(14))
{}, ResourceWithId(15))
router_interface.add_route(
'/repos/{org}/{repo}/compare/{usr0}:{branch0}/full',
{}, ResourceWithId(15))
{}, ResourceWithId(16))


@ddt.ddt
Expand All @@ -59,6 +61,7 @@ def before(self):
@ddt.data(
'/teams/{collision}',
'/repos/{org}/{repo}/compare/{simple-collision}',
'/emojis/signs/1',
)
def test_collision(self, template):
self.assertRaises(
Expand All @@ -80,6 +83,13 @@ def test_missing(self):
'/repos/racker/falcon/compare/johndoe:master...janedoe:dev/bogus')
self.assertIs(resource, None)

def test_literal_segment(self):
resource, method_map, params = self.router.find('/emojis/signs/0')
self.assertEqual(resource.resource_id, 12)

resource, method_map, params = self.router.find('/emojis/signs/1')
self.assertEqual(resource.resource_id, 13)

def test_dead_segment(self):
resource, method_map, params = self.router.find('/teams')
self.assertIs(resource, None)
Expand Down Expand Up @@ -121,7 +131,7 @@ def test_multivar(self):
self.assertEqual(resource.resource_id, 11)
self.assertEqual(params, {'org': 'racker', 'repo': 'falcon'})

@ddt.data(('', 5), ('/full', 10), ('/part', 13))
@ddt.data(('', 5), ('/full', 10), ('/part', 14))
@ddt.unpack
def test_complex(self, url_postfix, resource_id):
uri = '/repos/racker/falcon/compare/johndoe:master...janedoe:dev'
Expand All @@ -137,7 +147,7 @@ def test_complex(self, url_postfix, resource_id):
'branch1': 'dev'
})

@ddt.data(('', 14), ('/full', 15))
@ddt.data(('', 15), ('/full', 16))
@ddt.unpack
def test_complex_alt(self, url_postfix, resource_id):
uri = '/repos/falconry/falcon/compare/johndoe:master'
Expand Down

0 comments on commit 0af00af

Please sign in to comment.