Skip to content

Commit

Permalink
449 path format (#450)
Browse files Browse the repository at this point in the history
* added test for path formatted parameters

* re-added removed test, as it would generate valid flask route
  • Loading branch information
kcacciatore authored and hjacobs committed May 10, 2017
1 parent c30ba1f commit 1f34e35
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
6 changes: 6 additions & 0 deletions tests/api/test_responses.py
Expand Up @@ -18,6 +18,12 @@ def test_app(simple_app):
swagger_icon = app_client.get('/v1.0/ui/images/favicon.ico') # type: flask.Response
assert swagger_icon.status_code == 200

post_greeting_url = app_client.post('/v1.0/greeting/jsantos/the/third/of/his/name', data={}) # type: flask.Response
assert post_greeting_url.status_code == 200
assert post_greeting_url.content_type == 'application/json'
greeting_response_url = json.loads(post_greeting_url.data.decode('utf-8'))
assert greeting_response_url['greeting'] == 'Hello jsantos thanks for the/third/of/his/name'

post_greeting = app_client.post('/v1.0/greeting/jsantos', data={}) # type: flask.Response
assert post_greeting.status_code == 200
assert post_greeting.content_type == 'application/json'
Expand Down
3 changes: 3 additions & 0 deletions tests/fakeapi/hello.py
Expand Up @@ -38,6 +38,9 @@ def post_greeting(name, **kwargs):
data = {'greeting': 'Hello {name}'.format(name=name)}
return data

def post_greeting_url(name, remainder, **kwargs):
data = {'greeting': 'Hello {name} thanks for {remainder}'.format(name=name,remainder=remainder)}
return data

def post_goodday(name):
data = {'greeting': 'Hello {name}'.format(name=name)}
Expand Down
23 changes: 22 additions & 1 deletion tests/fixtures/simple/swagger.yaml
Expand Up @@ -23,7 +23,28 @@ paths:
description: Name of the person to greet.
required: true
type: string

/greeting/{name}/{remainder}:
post:
summary: Generate greeting and collect the remainder of the url
description: Generates a greeting message and includes the rest of the url.
operationId: fakeapi.hello.post_greeting_url
responses:
'200':
description: greeting response with url
schema:
type: object
parameters:
- name: name
in: path
description: Name of the person to greet.
required: true
type: string
- name: remainder
in: path
description: the rest of the url
required: true
type: string
format: path
/greetings/{name}:
get:
summary: Generate greeting
Expand Down
1 change: 1 addition & 0 deletions tests/test_flask_utils.py
Expand Up @@ -9,6 +9,7 @@ def test_flaskify_path():
assert flask_utils.flaskify_path("foo/{a}/{b}", {'a': 'integer'}) == "foo/<int:a>/<b>"
assert flask_utils.flaskify_path("foo/{a}/{b}", {'a': 'number'}) == "foo/<float:a>/<b>"
assert flask_utils.flaskify_path("foo/{a}/{b}", {'a': 'path'}) == "foo/<path:a>/<b>"
assert flask_utils.flaskify_path("foo/{a}", {'a': 'path'}) == "foo/<path:a>"


def test_flaskify_endpoint():
Expand Down

0 comments on commit 1f34e35

Please sign in to comment.