Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Namespace.parameters(locations=('json', 'files')) needs testing #32

Open
frol opened this issue Sep 28, 2016 · 3 comments
Open

Namespace.parameters(locations=('json', 'files')) needs testing #32

frol opened this issue Sep 28, 2016 · 3 comments

Comments

@frol
Copy link
Owner

frol commented Sep 28, 2016

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

@10000TB
Copy link
Contributor

10000TB commented Jun 30, 2018

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 ?

@10000TB
Copy link
Contributor

10000TB commented Jun 30, 2018

but setting FLASK_CONFIG to production works fine, but curious why ?

@frol
Copy link
Owner Author

frol commented Jun 30, 2018

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants