mirror of
https://github.com/LukeHagar/connexion.git
synced 2025-12-10 04:19:37 +00:00
Unit tests for file uploads
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
|
from StringIO import StringIO
|
||||||
|
|
||||||
|
|
||||||
def test_parameter_validation(simple_app):
|
def test_parameter_validation(simple_app):
|
||||||
@@ -109,6 +110,22 @@ def test_formdata_missing_param(simple_app):
|
|||||||
assert resp.status_code == 200
|
assert resp.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_formdata_file_upload(simple_app):
|
||||||
|
app_client = simple_app.app.test_client()
|
||||||
|
resp = app_client.post('/v1.0/test-formData-file-upload',
|
||||||
|
data={'formData': (StringIO('file contents'), 'filename.txt')})
|
||||||
|
assert resp.status_code == 200
|
||||||
|
response = json.loads(resp.data.decode())
|
||||||
|
assert response == {'filename.txt': 'file contents'}
|
||||||
|
|
||||||
|
|
||||||
|
def test_formdata_file_upload_missing_param(simple_app):
|
||||||
|
app_client = simple_app.app.test_client()
|
||||||
|
resp = app_client.post('/v1.0/test-formData-file-upload-missing-param',
|
||||||
|
data={'missing_formData': (StringIO('file contents'), 'example.txt')})
|
||||||
|
assert resp.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
def test_bool_as_default_param(simple_app):
|
def test_bool_as_default_param(simple_app):
|
||||||
app_client = simple_app.app.test_client()
|
app_client = simple_app.app.test_client()
|
||||||
resp = app_client.get('/v1.0/test-bool-param')
|
resp = app_client.get('/v1.0/test-bool-param')
|
||||||
|
|||||||
@@ -242,6 +242,16 @@ def test_formdata_missing_param():
|
|||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
|
||||||
|
def test_formdata_file_upload(formData):
|
||||||
|
filename = formData.filename
|
||||||
|
contents = formData.read()
|
||||||
|
return {filename: contents}
|
||||||
|
|
||||||
|
|
||||||
|
def test_formdata_file_upload_missing_param():
|
||||||
|
return ''
|
||||||
|
|
||||||
|
|
||||||
def test_bool_default_param(thruthiness):
|
def test_bool_default_param(thruthiness):
|
||||||
return thruthiness
|
return thruthiness
|
||||||
|
|
||||||
|
|||||||
30
tests/fixtures/simple/swagger.yaml
vendored
30
tests/fixtures/simple/swagger.yaml
vendored
@@ -334,6 +334,36 @@ paths:
|
|||||||
200:
|
200:
|
||||||
description: OK
|
description: OK
|
||||||
|
|
||||||
|
/test-formData-file-upload:
|
||||||
|
post:
|
||||||
|
summary: Test formData with file type, for file upload
|
||||||
|
operationId: fakeapi.hello.test_formdata_file_upload
|
||||||
|
consumes:
|
||||||
|
- multipart/form-data
|
||||||
|
parameters:
|
||||||
|
- name: formData
|
||||||
|
type: file
|
||||||
|
in: formData
|
||||||
|
required: true
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: OK
|
||||||
|
|
||||||
|
/test-formData-file-upload-missing-param:
|
||||||
|
post:
|
||||||
|
summary: Test formData with file type, missing parameter in handler
|
||||||
|
operationId: fakeapi.hello.test_formdata_file_upload_missing_param
|
||||||
|
consumes:
|
||||||
|
- multipart/form-data
|
||||||
|
parameters:
|
||||||
|
- name: missing_formData
|
||||||
|
type: file
|
||||||
|
in: formData
|
||||||
|
required: true
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: OK
|
||||||
|
|
||||||
/test-bool-param:
|
/test-bool-param:
|
||||||
get:
|
get:
|
||||||
summary: Test usage of boolean default value
|
summary: Test usage of boolean default value
|
||||||
|
|||||||
Reference in New Issue
Block a user