Skip to content

Commit

Permalink
tests - extra changes
Browse files Browse the repository at this point in the history
  • Loading branch information
commonism committed Sep 29, 2023
1 parent 8b4ad67 commit a13e86e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
5 changes: 4 additions & 1 deletion aiopenapi3/extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def __init__(
Union[Tuple[Union[re.Pattern, str], Optional[List[Union[re.Pattern, str]]]], Union[re.Pattern, str]]
],
) -> None:
assert isinstance(operations, list), type(operations)
self.operations = operations
super().__init__()

Expand All @@ -38,7 +39,7 @@ def _reduced_paths(self, ctx: "Document.Context") -> dict:
if path_key not in reduced:
reduced[path_key] = {k: v for k, v in path_value.items() if k in keep_keys}
reduced[path_key][operation_key] = operation_value
else:
elif isinstance(operation, tuple) and len(operation) == 2:
pattern, operation_patterns = operation
for path_key in ctx.document["paths"].keys():
if (isinstance(pattern, str) and pattern == path_key) or (
Expand All @@ -55,6 +56,8 @@ def _reduced_paths(self, ctx: "Document.Context") -> dict:
for op_pattern in operation_patterns
)
}
else:
raise TypeError(operation)

Check warning on line 60 in aiopenapi3/extra.py

View check run for this annotation

Codecov / codecov/patch

aiopenapi3/extra.py#L60

Added line #L60 was not covered by tests
return reduced

def parsed(self, ctx: "Document.Context") -> "Document.Context":
Expand Down
42 changes: 40 additions & 2 deletions tests/extra_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,12 @@ def test_reduced(with_extra_reduced, httpx_mock, compressor):
assert "A" in api.components.responses
assert "A" in api.components.requestBodies

# (str, methods)
api = OpenAPI.load_file(
"http://127.0.0.1/api.yaml",
with_extra_reduced,
session_factory=httpx.Client,
plugins=[compressor({"/A/{Path}": None})],
plugins=[compressor([("/A/{Path}", None)])],
loader=FileSystemLoader(Path("tests/fixtures")),
)

Expand All @@ -151,15 +152,52 @@ def test_reduced(with_extra_reduced, httpx_mock, compressor):
assert payload.a == 1
assert headers["X-A"] == "A"

# (re, methods)
api = OpenAPI.load_file(
"http://127.0.0.1/api.yaml",
with_extra_reduced,
session_factory=httpx.Client,
plugins=[compressor({re.compile("/B"): None})],
plugins=[compressor([(re.compile("/B"), None)])],
loader=FileSystemLoader(Path("tests/fixtures")),
)
assert "/A/{Path}" not in api.paths.paths
assert "A" not in api.components.parameters
assert "A" not in api.components.schemas
assert "A" not in api.components.responses
assert "A" not in api.components.requestBodies

# operationId str
api = OpenAPI.load_file(
"http://127.0.0.1/api.yaml",
with_extra_reduced,
session_factory=httpx.Client,
plugins=[compressor(["A"])],
loader=FileSystemLoader(Path("tests/fixtures")),
)
assert "/A/{Path}" in api.paths.paths
assert "A" in api.components.parameters
assert "AA" in api.components.schemas
assert "A" in api.components.schemas

assert "A0" in api.components.schemas
assert "A1" in api.components.schemas
assert "A" in api.components.responses
assert "A" in api.components.requestBodies

# operationId re
api = OpenAPI.load_file(
"http://127.0.0.1/api.yaml",
with_extra_reduced,
session_factory=httpx.Client,
plugins=[compressor([re.compile(r"[A]{1}$")])],
loader=FileSystemLoader(Path("tests/fixtures")),
)
assert "/A/{Path}" in api.paths.paths
assert "A" in api.components.parameters
assert "AA" in api.components.schemas
assert "A" in api.components.schemas

assert "A0" in api.components.schemas
assert "A1" in api.components.schemas
assert "A" in api.components.responses
assert "A" in api.components.requestBodies
1 change: 1 addition & 0 deletions tests/fixtures/extra-reduced.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ paths:

/B:
get:
operationId: B
responses:
"200":
description: "ok"
Expand Down

0 comments on commit a13e86e

Please sign in to comment.