flask-restplus-server-example
flask-restplus-server-example copied to clipboard
Namespace.parameters(locations=('json', 'files')) needs testing
It is reported that locations=('json', 'files')
in @Namespace.parameters
decorator breaks Swagger config:
@api.parameters(
parameters.CreateTeamParameters(),
locations=('json', 'files')
)
def post(self, ...):
...
The Swagger config results in:
"schema": {
"properties": {
"source_file": {
"type": "file"
},
...
},
"type": "object"
}
Instead of
"parameters": [
{
"in": "formData",
"name": "source_file",
"required": false,
"type": "file"
},
...
]
This might be related to #20.
/cc @DurandA
Hey @frol , I'd love to work on this, but need some guidance on starting this:
I am having a hard time running exsting tests with simple pytest tests
. I got folllowing issue:
➜ flask-restplus-server-example git:(master) ✗ pytest tests/test_app_creation.py
=========================================================================================================================================================================== test session starts ============================================================================================================================================================================
platform darwin -- Python 2.7.15, pytest-3.6.2, py-1.5.4, pluggy-0.6.0
rootdir: /Users/xuehaodavidhu/whut2eat/opensource/flask-restplus-server-example, inifile:
collected 10 items
tests/test_app_creation.py
.FF.....FF [100%]
================================================================================================================================================================================= FAILURES =================================================================================================================================================================================
__________________________________________________________________________________________________________________________________________________________ test_create_app_passing_flask_config_name[production] ___________________________________________________________________________________________________________________________________________________________
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x106375990>, flask_config_name = 'production'
@pytest.mark.parametrize('flask_config_name', ['production', 'development', 'testing'])
def test_create_app_passing_flask_config_name(monkeypatch, flask_config_name):
if flask_config_name == 'production':
from config import ProductionConfig
monkeypatch.setattr(ProductionConfig, 'SQLALCHEMY_DATABASE_URI', 'sqlite://')
monkeypatch.setattr(ProductionConfig, 'SECRET_KEY', 'secret')
> create_app(flask_config_name=flask_config_name)
tests/test_app_creation.py:22:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
flask_config_name = 'production', kwargs = {}, threading = <module 'threading' from '/usr/local/Cellar/python@2/2.7.15/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.pyc'>, app = <Flask 'app'>, env_flask_config_name = 'testing'
def create_app(flask_config_name=None, **kwargs):
"""
Entry point to the Flask RESTful Server application.
"""
# This is a workaround for Alpine Linux (musl libc) quirk:
# https://github.com/docker-library/python/issues/211
import threading
threading.stack_size(2*1024*1024)
app = Flask(__name__, **kwargs)
env_flask_config_name = os.getenv('FLASK_CONFIG')
if not env_flask_config_name and flask_config_name is None:
flask_config_name = 'local'
elif flask_config_name is None:
flask_config_name = env_flask_config_name
else:
if env_flask_config_name:
assert env_flask_config_name == flask_config_name, (
"FLASK_CONFIG environment variable (\"%s\") and flask_config_name argument "
"(\"%s\") are both set and are not the same." % (
env_flask_config_name,
> flask_config_name
)
)
E AssertionError: FLASK_CONFIG environment variable ("testing") and flask_config_name argument ("production") are both set and are not the same.
app/__init__.py:42: AssertionError
I assume we would need to set FLASK_CONFIG
to testing
, but that seem to have a conflict, and is blocking me from running the tests, is there any very obvious things I am misunderstanding here ?
but setting FLASK_CONFIG
to production
works fine, but curious why ?
@10000TB It seems that you have FLASK_CONFIG environment variable set to production
. Try unsetting it:
env FLASK_CONFIG= pytest tests/test_app_creation.py