Skip to content

Commit

Permalink
Fix for route validation when used with pyramid route_prefix_context (#…
Browse files Browse the repository at this point in the history
…101)

Only replace the path once
  • Loading branch information
damonhook committed Oct 30, 2020
1 parent ea6707f commit 103c671
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions pyramid_openapi3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ def check_all_routes(event: ApplicationCreated):
prefixes.append(path)

def remove_prefixes(path):
path = f"/{path}" if not path.startswith("/") else path
for prefix in prefixes:
path = path.replace(prefix, "")
return path
Expand Down
15 changes: 15 additions & 0 deletions pyramid_openapi3/tests/test_app_construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,21 @@ def test_prefixed_routes(app_config: Configurator) -> None:
app_config.make_wsgi_app()


def test_pyramid_prefixed_context_routes(app_config: Configurator) -> None:
"""Test case for prefixed routes using pyramid route_prefix_context."""
with app_config.route_prefix_context("/api/v1"):
app_config.add_route(name="foo", pattern="/foo")
app_config.add_route(name="bar", pattern="/bar")
app_config.add_view(
foo_view, route_name="foo", renderer="string", request_method="OPTIONS"
)
app_config.add_view(
bar_view, route_name="bar", renderer="string", request_method="GET"
)

app_config.make_wsgi_app()


def test_missing_routes(app_config: Configurator) -> None:
"""Test case showing app creation fails, when defined routes are missing."""
with pytest.raises(MissingEndpointsError) as ex:
Expand Down

0 comments on commit 103c671

Please # to comment.