-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests and slight improvement to json path detection
- Loading branch information
Showing
4 changed files
with
179 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
openapi: 3.0.0 | ||
info: | ||
title: 'pagination' | ||
version: 1.0.0 | ||
description: 'different content path' | ||
servers: | ||
- url: 'https://pokeapi.co/' | ||
|
||
paths: | ||
|
||
/unnested_collection_result/: | ||
get: | ||
operationId: unnested_collection_result | ||
responses: | ||
'200': | ||
description: "OK" | ||
content: | ||
application/json: | ||
schema: | ||
type: array | ||
items: | ||
type: object | ||
properties: | ||
id: | ||
type: integer | ||
example: 3 | ||
|
||
/results_collection_json_path/: | ||
get: | ||
operationId: results_collection_json_path | ||
responses: | ||
'200': | ||
description: "OK" | ||
content: | ||
application/json: | ||
schema: | ||
type: object | ||
properties: | ||
count: | ||
type: integer | ||
example: 3 | ||
next: | ||
type: string | ||
nullable: true | ||
example: https://pokeapi.co/api/v2/pokemon/?offset=20&limit=20 | ||
previous: | ||
type: string | ||
nullable: true | ||
results: | ||
type: array | ||
|
||
/nested_results_collection_json_path/: | ||
get: | ||
operationId: nested_results_collection_json_path | ||
responses: | ||
'200': | ||
description: "OK" | ||
content: | ||
application/json: | ||
schema: | ||
type: object | ||
properties: | ||
count: | ||
type: integer | ||
example: 3 | ||
next: | ||
type: string | ||
nullable: true | ||
example: https://pokeapi.co/api/v2/pokemon/?offset=20&limit=20 | ||
previous: | ||
type: string | ||
nullable: true | ||
content: | ||
type: object | ||
properties: | ||
count: | ||
type: integer | ||
example: 3 | ||
results: | ||
type: array | ||
|
||
|
||
/single_object_unnested/: | ||
get: | ||
operationId: single_object_unnested | ||
responses: | ||
'200': | ||
description: "OK" | ||
content: | ||
application/json: | ||
schema: | ||
type: object | ||
properties: | ||
id: | ||
type: integer | ||
example: 3 | ||
name: | ||
type: string | ||
nullable: true | ||
address: | ||
type: string | ||
nullable: true | ||
|
||
|
||
|
||
/single_object_nested/: | ||
get: | ||
operationId: single_object_nested | ||
responses: | ||
'200': | ||
description: "OK" | ||
content: | ||
application/json: | ||
schema: | ||
type: object | ||
properties: | ||
result_object: | ||
type: object | ||
properties: | ||
id: | ||
type: integer | ||
example: 3 | ||
name: | ||
type: string | ||
nullable: true | ||
address: | ||
type: string | ||
nullable: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from typing import Dict, Any | ||
|
||
import pytest | ||
|
||
from tests.e2e.utils import get_source_from_open_api, get_dict_from_open_api | ||
from tests.cases import get_test_case_path | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def paginators() -> Dict[str, str]: | ||
case_path = get_test_case_path("content_path_specs.yml") | ||
# validate that source will work | ||
get_source_from_open_api(case_path) | ||
|
||
# get dict and save paginator info into dict | ||
rendered_dict = get_dict_from_open_api(case_path) | ||
return { | ||
entry["name"]: entry.get("endpoint").get("data_selector") # type: ignore | ||
for entry in rendered_dict["resources"] # type: ignore | ||
} | ||
|
||
|
||
def test_unnested_collection_result(paginators: Dict[str, Any]) -> None: | ||
assert paginators["unnested_collection_result"] == "$" | ||
|
||
|
||
def test_results_collection_json_path(paginators: Dict[str, Any]) -> None: | ||
assert paginators["results_collection_json_path"] == "results" | ||
|
||
|
||
def test_nested_results_collection_json_path(paginators: Dict[str, Any]) -> None: | ||
assert paginators["nested_results_collection_json_path"] == "content.results" | ||
|
||
|
||
def test_single_object_unneested(paginators: Dict[str, Any]) -> None: | ||
assert paginators["single_object_unnested"] == "$" | ||
|
||
|
||
def test_single_object_nested(paginators: Dict[str, Any]) -> None: | ||
assert paginators["single_object_nested"] == "result_object" |