Skip to content

Commit

Permalink
Added unit test for multiple yaml case
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardofesta committed Sep 27, 2022
1 parent 8bdda5a commit 699d860
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 0 deletions.
49 changes: 49 additions & 0 deletions tests/api/test_bootstrap_multiple_spec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import json

import pytest
from connexion import App

from conftest import TEST_FOLDER

SPECS = [
pytest.param(
[
{"specification": "swagger_greeting.yaml", "name": "greeting"},
{"specification": "swagger_bye.yaml", "name": "bye"},
],
id="swagger",
),
pytest.param(
[
{"specification": "openapi_greeting.yaml", "name": "greeting"},
{"specification": "openapi_bye.yaml", "name": "bye"},
],
id="openapi",
),
]


@pytest.mark.parametrize("spec", SPECS)
def test_app_with_multiple_definition(multiple_yaml_same_basepath_dir, spec):
# Create the app with a relative path and run the test_app testcase below.
app = App(
__name__,
port=5001,
specification_dir=".."
/ multiple_yaml_same_basepath_dir.relative_to(TEST_FOLDER),
debug=True,
)

for s in spec:
app.add_api(**s)

app_client = app.app.test_client()

post_greeting = app_client.post("/v1.0/greeting/jsantos") # type: flask.Response
assert post_greeting.status_code == 200
greeting_response = json.loads(post_greeting.data.decode("utf-8"))
assert greeting_response["greeting"] == "Hello jsantos"

get_bye = app_client.get("/v1.0/bye/jsantos") # type: flask.Response
assert get_bye.status_code == 200
assert get_bye.data == b"Goodbye jsantos"
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ def json_validation_spec_dir():
return FIXTURES_FOLDER / "json_validation"


@pytest.fixture
def multiple_yaml_same_basepath_dir():
return FIXTURES_FOLDER / "multiple_yaml_same_basepath"


@pytest.fixture(scope="session")
def json_datetime_dir():
return FIXTURES_FOLDER / "datetime_support"
Expand Down
28 changes: 28 additions & 0 deletions tests/fixtures/multiple_yaml_same_basepath/openapi_bye.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
openapi: 3.0.0
info:
title: '{{title}}'
version: '1.0'
paths:
'/bye/{name}':
get:
summary: Generate goodbye
description: Generates a goodbye message.
operationId: fakeapi.hello.get_bye
responses:
'200':
description: goodbye response
content:
text/plain:
schema:
type: string
default:
description: unexpected error
parameters:
- name: name
in: path
description: Name of the person to say bye.
required: true
schema:
type: string
servers:
- url: /v1.0
28 changes: 28 additions & 0 deletions tests/fixtures/multiple_yaml_same_basepath/openapi_greeting.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
openapi: 3.0.0
info:
title: '{{title}}'
version: '1.0'
paths:
'/greeting/{name}':
post:
summary: Generate greeting
description: Generates a greeting message.
operationId: fakeapi.hello.post_greeting
responses:
'200':
description: greeting response
content:
'*/*':
schema:
type: object
parameters:
- name: name
in: path
description: Name of the person to greet.
required: true
schema:
type: string


servers:
- url: /v1.0
29 changes: 29 additions & 0 deletions tests/fixtures/multiple_yaml_same_basepath/swagger_bye.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
swagger: "2.0"

info:
title: "{{title}}"
version: "1.0"

basePath: /v1.0

paths:
/bye/{name}:
get:
summary: Generate goodbye
description: Generates a goodbye message.
operationId: fakeapi.hello.get_bye
produces:
- text/plain
responses:
'200':
description: goodbye response
schema:
type: string
default:
description: "unexpected error"
parameters:
- name: name
in: path
description: Name of the person to say bye.
required: true
type: string
25 changes: 25 additions & 0 deletions tests/fixtures/multiple_yaml_same_basepath/swagger_greeting.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
swagger: "2.0"

info:
title: "{{title}}"
version: "1.0"

basePath: /v1.0

paths:
/greeting/{name}:
post:
summary: Generate greeting
description: Generates a greeting message.
operationId: fakeapi.hello.post_greeting
responses:
200:
description: greeting response
schema:
type: object
parameters:
- name: name
in: path
description: Name of the person to greet.
required: true
type: string

0 comments on commit 699d860

Please sign in to comment.