Skip to content
This repository has been archived by the owner on Nov 19, 2023. It is now read-only.

Commit

Permalink
fix: Remove trailing slash from resolve logic
Browse files Browse the repository at this point in the history
It's unclear why this was put in, and it causes
problems for users. No significant tests failed
in a way that raises any red flags, so this
seems like it will be fine to remove.
  • Loading branch information
sondrelg committed Nov 26, 2022
1 parent ff283b5 commit ba788da
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 5 deletions.
2 changes: 1 addition & 1 deletion openapi_tester/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def resolve_path(self, endpoint_path: str, method: str) -> tuple[str, ResolverMa
Resolves a Django path.
"""
url_object = urlparse(endpoint_path)
parsed_path = url_object.path if url_object.path.endswith("/") else url_object.path + "/"
parsed_path = url_object.path
if not parsed_path.startswith("/"):
parsed_path = "/" + parsed_path
for key, value in self.field_key_map.items():
Expand Down
2 changes: 1 addition & 1 deletion openapi_tester/schema_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,4 +400,4 @@ def validate_response(
case_tester=case_tester or self.case_tester,
ignore_case=ignore_case,
validators=validators,
)
)
3 changes: 0 additions & 3 deletions tests/test_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,10 @@ def test_url_schema_loader():
@pytest.mark.parametrize("loader", loaders)
def test_loader_get_route(loader):
assert loader.resolve_path("/api/v1/items/", "get")[0] == "/api/{version}/items"
assert loader.resolve_path("/api/v1/items", "get")[0] == "/api/{version}/items"
assert loader.resolve_path("api/v1/items/", "get")[0] == "/api/{version}/items"
assert loader.resolve_path("api/v1/items", "get")[0] == "/api/{version}/items"
assert loader.resolve_path("/api/v1/snake-case/", "get")[0] == "/api/{version}/snake-case/"
assert loader.resolve_path("/api/v1/snake-case", "get")[0] == "/api/{version}/snake-case/"
assert loader.resolve_path("api/v1/snake-case/", "get")[0] == "/api/{version}/snake-case/"
assert loader.resolve_path("api/v1/snake-case", "get")[0] == "/api/{version}/snake-case/"
with pytest.raises(ValueError, match="Could not resolve path `test`"):
assert loader.resolve_path("test", "get")

Expand Down

0 comments on commit ba788da

Please sign in to comment.