Skip to content

Commit

Permalink
update data selector tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-rp committed May 6, 2024
1 parent 714401b commit 13d900e
Show file tree
Hide file tree
Showing 5 changed files with 178 additions and 15 deletions.
3 changes: 3 additions & 0 deletions openapi_python_client/detectors/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""
Detection mechanisms
"""
Empty file.
7 changes: 4 additions & 3 deletions openapi_python_client/parser/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,10 @@ def from_operation(
{p.name: p for p in (Parameter.from_reference(param, context) for param in operation.parameters or [])}
)

# if there are no params in path, we expect a list for now, later we should probably see wether
# there is a path param at the end of the path
expect_list = len(path_level_parameters) == 0
# we expect a list if the last part of the path is not a param
# we may need to finetune this
parts = get_path_parts(path)
expect_list = not is_var_part(parts[-1])
parsed_responses = (
Response.from_reference(status_code, response_ref, context, expect_list=expect_list)
for status_code, response_ref in operation.responses.items()
Expand Down
153 changes: 152 additions & 1 deletion tests/cases/test_specs/content_path_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,39 @@ paths:
results:
type: array


/test_results_collection_with_inner_list_json_path/:
get:
operationId: test_results_collection_with_inner_list_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
items:
type: object
properties:
id:
type: integer
example: 3
tags:
type: array

/nested_results_collection_json_path/:
get:
operationId: nested_results_collection_json_path
Expand Down Expand Up @@ -125,4 +158,122 @@ paths:
nullable: true
address:
type: string
nullable: true
nullable: true

'/workspace/{workspace_id}/run/{transaction_id}':
get:
tags:
- runs-load-packages
summary: Get Workspace Run
description: Gets all pipeline runs for a pipeline
operationId: get_workspace_run_workspace__workspace_id__run__transaction_id__get
security:
- Auth: []
parameters:
- name: transaction_id
in: path
required: true
schema:
type: string
title: Transaction Id
- name: workspace_id
in: path
required: true
schema:
type: string
format: uuid
title: Workspace Id
- name: organization_id
in: query
required: false
schema:
anyOf:
- type: string
format: uuid
- type: 'null'
title: Organization Id
responses:
'200':
description: Successful Response
content:
application/json:
schema:
$ref: '#/components/schemas/RunSchema'


components:
schemas:
TraceSchema:
properties:
transaction_id:
type: string
title: Transaction Id
pipeline_name:
type: string
title: Pipeline Name
started_at:
type: string
format: date-time
title: Started At
finished_at:
anyOf:
- type: string
format: date-time
- type: 'null'
title: Finished At
engine_version:
type: integer
title: Engine Version
steps:
type: array
title: Steps
default: []
type: object
required:
- transaction_id
- pipeline_name
- started_at
- engine_version
- resolved_config_values
title: TraceSchema


RunSchema:
properties:
id:
type: string
format: uuid
title: Id
pipeline_id:
type: string
format: uuid
title: Pipeline Id
transaction_id:
type: string
title: Transaction Id
date_started:
type: string
format: date-time
title: Date Started
state:
type: string
title: State
trace:
$ref: '#/components/schemas/TraceSchema'
migrations_count:
type: integer
title: Migrations Count
failed_jobs:
type: integer
title: Failed Jobs
type: object
required:
- id
- pipeline_id
- transaction_id
- date_started
- state
- trace
- migrations_count
- failed_jobs
title: RunSchema
30 changes: 19 additions & 11 deletions tests/e2e/test_json_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


@pytest.fixture(scope="module")
def paginators() -> Dict[str, str]:
def data_selectors() -> 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)
Expand All @@ -20,21 +20,29 @@ def paginators() -> Dict[str, str]:
}


def test_unnested_collection_result(paginators: Dict[str, Any]) -> None:
assert paginators["unnested_collection_result"] == "$"
def test_unnested_collection_result(data_selectors: Dict[str, Any]) -> None:
assert data_selectors["unnested_collection_result"] == "$"


def test_results_collection_json_path(paginators: Dict[str, Any]) -> None:
assert paginators["results_collection_json_path"] == "results"
def test_results_collection_json_path(data_selectors: Dict[str, Any]) -> None:
assert data_selectors["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_results_collection_with_inner_list_json_path(data_selectors: Dict[str, Any]) -> None:
assert data_selectors["test_results_collection_with_inner_list_json_path"] == "results"


def test_single_object_unneested(paginators: Dict[str, Any]) -> None:
assert paginators["single_object_unnested"] == "$"
def test_nested_results_collection_json_path(data_selectors: Dict[str, Any]) -> None:
assert data_selectors["nested_results_collection_json_path"] == "content.results"


def test_single_object_nested(paginators: Dict[str, Any]) -> None:
assert paginators["single_object_nested"] == "result_object"
def test_single_object_unneested(data_selectors: Dict[str, Any]) -> None:
assert data_selectors["single_object_unnested"] == "$"


def test_single_object_nested(data_selectors: Dict[str, Any]) -> None:
assert data_selectors["single_object_nested"] == "result_object"


def test_platform_nested(data_selectors: Dict[str, Any]) -> None:
assert data_selectors["get_workspace_run_workspace_workspace_id_run_transaction_id_get"] == "$"

0 comments on commit 13d900e

Please sign in to comment.