-
-
Notifications
You must be signed in to change notification settings - Fork 762
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added unit test for multiple yaml case
- Loading branch information
1 parent
8bdda5a
commit 699d860
Showing
6 changed files
with
164 additions
and
0 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
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" |
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
28 changes: 28 additions & 0 deletions
28
tests/fixtures/multiple_yaml_same_basepath/openapi_bye.yaml
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,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
28
tests/fixtures/multiple_yaml_same_basepath/openapi_greeting.yaml
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,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
29
tests/fixtures/multiple_yaml_same_basepath/swagger_bye.yaml
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,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
25
tests/fixtures/multiple_yaml_same_basepath/swagger_greeting.yaml
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,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 |