Skip to content

Commit

Permalink
Add ref_path to tests.utils
Browse files Browse the repository at this point in the history
Copied from apispec
  • Loading branch information
lafrech committed Mar 29, 2019
1 parent 134f9c3 commit 9fe36fc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
8 changes: 4 additions & 4 deletions tests/test_blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from flask_rest_api import Api, Blueprint, Page
from flask_rest_api.exceptions import InvalidLocationError

from .utils import ref_path


LOCATIONS_MAPPING = (
('querystring', 'query',),
Expand Down Expand Up @@ -223,20 +225,18 @@ def many_true():
response = paths['/test/schema_many_false']['get']['responses']['200']
if openapi_version == '2.0':
schema = response['schema']
assert schema == {'$ref': '#/definitions/Doc'}
else:
schema = (
response['content']['application/json']['schema'])
assert schema == {'$ref': '#/components/schemas/Doc'}
assert schema == {'$ref': ref_path(api.spec) + 'Doc'}

response = paths['/test/schema_many_true']['get']['responses']['200']
if openapi_version == '2.0':
schema = response['schema']['items']
assert schema == {'$ref': '#/definitions/Doc'}
else:
schema = (
response['content']['application/json']['schema']['items'])
assert schema == {'$ref': '#/components/schemas/Doc'}
assert schema == {'$ref': ref_path(api.spec) + 'Doc'}

@pytest.mark.parametrize('openapi_version', ('2.0', '3.0.2'))
def test_blueprint_pagination(self, app, schemas, openapi_version):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from flask_rest_api import Api, Blueprint, Page
from flask_rest_api.pagination import PaginationParameters

from .utils import ref_path

CUSTOM_PAGINATION_PARAMS = (2, 5, 10)

Expand Down Expand Up @@ -171,7 +172,7 @@ def func(pagination_parameters):
assert get['responses']['200']['headers'] == {
'X-Custom-Pagination-Header': {
'description': 'Pagination metadata',
'schema': {'$ref': '#/components/schemas/PaginationHeader'},
'schema': {'$ref': ref_path(api.spec) + 'PaginationHeader'},
}
}

Expand Down
6 changes: 6 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,9 @@ def get_schemas(spec):
if spec.openapi_version.major < 3:
return spec.to_dict().get('definitions')
return spec.to_dict()['components'].get('schemas')


def ref_path(spec):
if spec.openapi_version.version[0] < 3:
return "#/definitions/"
return "#/components/schemas/"

0 comments on commit 9fe36fc

Please sign in to comment.