python-openapi / openapi-core

Openapi-core is a Python library that adds client-side and server-side support for the OpenAPI v3.0 and OpenAPI v3.1 specification.
BSD 3-Clause "New" or "Revised" License
303 stars 132 forks source link

[Bug] 0.18.1 + all up to f5f5792a: pytest warnings + call trace #715

Closed kloczek closed 1 year ago

kloczek commented 1 year ago

Actual Behavior

Looks like pytest shows some warnings + call trace bout useALLOWED_HOSTS`. Here is pytest output:

```console + PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-openapi-core-0.18.1-3.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-openapi-core-0.18.1-3.fc35.x86_64/usr/lib/python3.8/site-packages + /usr/bin/pytest -ra -m 'not network' ==================================================================================== test session starts ==================================================================================== platform linux -- Python 3.8.18, pytest-7.4.3, pluggy-1.3.0 rootdir: /home/tkloczko/rpmbuild/BUILD/openapi-core-0.18.1 configfile: pyproject.toml plugins: timeout-2.2.0, anyio-4.0.0, asyncio-0.21.1, flake8-1.1.1, aiohttp-1.0.5 asyncio: mode=auto collected 1404 items tests/integration/test_minimal.py ............................................................ tests/integration/test_petstore.py .................x...................... tests/integration/contrib/aiohttp/test_aiohttp_project.py .. tests/integration/contrib/aiohttp/test_aiohttp_validation.py ...s..s.. tests/integration/contrib/django/test_django_project.py Bad Request: /v1/pets ..Bad Request: /v1/pets .Bad Request: /v1/pets .Unsupported Media Type: /v1/pets .Bad Request: /v1/pets ...Invalid HTTP_HOST header: 'testserver'. You may need to add 'testserver' to ALLOWED_HOSTS. Traceback (most recent call last): File "/usr/lib/python3.8/site-packages/django/core/handlers/exception.py", line 55, in inner response = get_response(request) File "/usr/lib/python3.8/site-packages/django/utils/deprecation.py", line 133, in __call__ response = self.process_request(request) File "/usr/lib/python3.8/site-packages/django/middleware/common.py", line 48, in process_request host = request.get_host() File "/usr/lib/python3.8/site-packages/django/http/request.py", line 150, in get_host raise DisallowedHost(msg) django.core.exceptions.DisallowedHost: Invalid HTTP_HOST header: 'testserver'. You may need to add 'testserver' to ALLOWED_HOSTS. Bad Request: /v1/pets/12 .Forbidden: /v1/pets/12 .Method Not Allowed: /v1/pets/12 ...Unsupported Media Type: /v1/tags .... tests/integration/contrib/falcon/test_falcon_project.py ..............x tests/integration/contrib/flask/test_flask_decorator.py .......... tests/integration/contrib/flask/test_flask_project.py .. tests/integration/contrib/flask/test_flask_validator.py . tests/integration/contrib/flask/test_flask_views.py ....... tests/integration/contrib/requests/test_requests_validation.py ....... tests/integration/contrib/starlette/test_starlette_project.py .............. tests/integration/contrib/starlette/test_starlette_validation.py .. tests/integration/contrib/werkzeug/test_werkzeug_validation.py ... tests/integration/schema/test_empty.py . tests/integration/schema/test_link_spec.py .... tests/integration/schema/test_path_params.py .. tests/integration/schema/test_spec.py .. tests/integration/unmarshalling/test_read_only_write_only.py .... tests/integration/unmarshalling/test_request_unmarshaller.py ............. tests/integration/unmarshalling/test_response_unmarshaller.py .......... tests/integration/unmarshalling/test_security_override.py ..... tests/integration/unmarshalling/test_unmarshallers.py ...............xxxxxxx........................................................................................................................................................................................................................xxxxxxx......................................................................................................................................................................................................................................................................................................................................................................xx.......................... tests/integration/validation/test_request_validators.py ....... tests/integration/validation/test_response_validators.py .......... tests/unit/test_shortcuts.py ...................................................................................................... tests/unit/test_util.py ................. tests/unit/casting/test_schema_casters.py ........ tests/unit/contrib/aiohttp/test_aiohttp_requests.py . tests/unit/contrib/aiohttp/test_aiohttp_responses.py . tests/unit/contrib/django/test_django.py ......... tests/unit/contrib/flask/test_flask_requests.py .... tests/unit/contrib/flask/test_flask_responses.py .. tests/unit/contrib/requests/test_requests_requests.py ...... tests/unit/contrib/requests/test_requests_responses.py .. tests/unit/deserializing/test_media_types_deserializers.py .............................. tests/unit/deserializing/test_styles_deserializers.py .............................................................. tests/unit/extensions/test_factories.py .. tests/unit/schema/test_schema_parameters.py ..................................................................................................................................................... tests/unit/security/test_providers.py ......... tests/unit/templating/test_media_types_finders.py ..... tests/unit/templating/test_paths_finders.py X...x...x............X...x...x............... tests/unit/templating/test_responses_finders.py ... tests/unit/templating/test_templating_util.py ....xx tests/unit/unmarshalling/test_path_item_params_validator.py ...... tests/unit/unmarshalling/test_schema_unmarshallers.py ......x. tests/unit/validation/test_schema_validators.py ................................................. ===================================================================================== warnings summary ====================================================================================== tests/integration/test_petstore.py: 14 warnings /home/tkloczko/rpmbuild/BUILDROOT/python-openapi-core-0.18.1-3.fc35.x86_64/usr/lib/python3.8/site-packages/openapi_core/validation/request/validators.py:194: DeprecationWarning: limit parameter is deprecated warnings.warn( tests/integration/test_petstore.py: 14 warnings /home/tkloczko/rpmbuild/BUILDROOT/python-openapi-core-0.18.1-3.fc35.x86_64/usr/lib/python3.8/site-packages/openapi_core/validation/validators.py:181: DeprecationWarning: Use of allowEmptyValue property is deprecated warnings.warn( tests/integration/test_petstore.py::TestPetstore::test_get_pets_allow_empty_value /home/tkloczko/rpmbuild/BUILDROOT/python-openapi-core-0.18.1-3.fc35.x86_64/usr/lib/python3.8/site-packages/openapi_core/validation/validators.py:196: DeprecationWarning: Use of allowEmptyValue property is deprecated warnings.warn( tests/integration/test_petstore.py::TestPetstore::test_delete_tags_with_requestbody tests/integration/test_petstore.py::TestPetstore::test_delete_tags_with_requestbody /home/tkloczko/rpmbuild/BUILDROOT/python-openapi-core-0.18.1-3.fc35.x86_64/usr/lib/python3.8/site-packages/openapi_core/validation/response/validators.py:177: DeprecationWarning: x-delete-confirm header is deprecated warnings.warn( tests/integration/contrib/aiohttp/test_aiohttp_project.py::TestPetPhotoView::test_get_valid tests/integration/contrib/aiohttp/test_aiohttp_project.py::TestPetPhotoView::test_post_valid /usr/lib/python3.8/site-packages/pytest_aiohttp/plugin.py:33: DeprecationWarning: 'loop' fixture is deprecated and scheduled for removal, please use 'event_loop' instead warnings.warn( tests/integration/contrib/aiohttp/test_aiohttp_project.py::TestPetPhotoView::test_get_valid tests/integration/contrib/aiohttp/test_aiohttp_project.py::TestPetPhotoView::test_post_valid /home/tkloczko/rpmbuild/BUILD/openapi-core-0.18.1/tests/integration/contrib/aiohttp/data/v3.0/aiohttpproject/__main__.py:10: DeprecationWarning: loop argument is deprecated app = web.Application(loop=loop) tests/integration/contrib/django/test_django_project.py::TestPetListView::test_get_no_required_param /usr/lib/python3.8/site-packages/django/conf/__init__.py:267: RemovedInDjango50Warning: The USE_L10N setting is deprecated. Starting with Django 5.0, localized formatting of data will always be enabled. For example Django will display numbers and dates using the format of the current locale. warnings.warn(USE_L10N_DEPRECATED_MSG, RemovedInDjango50Warning) tests/integration/contrib/requests/test_requests_validation.py::TestV31RequestsFactory::test_response_validator_path_pattern /usr/lib/python3.8/site-packages/responses/__init__.py:422: DeprecationWarning: Argument 'match_querystring' is deprecated. Use 'responses.matchers.query_param_matcher' or 'responses.matchers.query_string_matcher' warn( tests/integration/contrib/starlette/test_starlette_project.py::TestPetListEndpoint::test_post_media_type_invalid tests/integration/contrib/starlette/test_starlette_project.py::TestPetPhotoEndpoint::test_post_valid /usr/lib/python3.8/site-packages/httpx/_content.py:204: DeprecationWarning: Use 'content=<...>' to upload raw bytes/text content. warnings.warn(message, DeprecationWarning) tests/integration/contrib/starlette/test_starlette_project.py::TestPetPhotoEndpoint::test_get_valid tests/integration/contrib/starlette/test_starlette_project.py::TestPetPhotoEndpoint::test_post_valid /usr/lib/python3.8/site-packages/httpx/_client.py:799: DeprecationWarning: Setting per-request cookies=<...> is being deprecated, because the expected behaviour on cookie persistence is ambiguous. Set cookies directly on the client instance instead. warnings.warn(message, DeprecationWarning) -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html -------------------------------------------------- generated xml file: /home/tkloczko/rpmbuild/BUILD/openapi-core-0.18.1/reports/junit.xml -------------------------------------------------- ================================================================================== short test summary info ================================================================================== SKIPPED [1] tests/integration/contrib/aiohttp/test_aiohttp_validation.py:39: No validation for given handler. SKIPPED [1] tests/integration/contrib/aiohttp/test_aiohttp_validation.py:77: No validation for given handler. XFAIL tests/integration/test_petstore.py::TestPetstore::test_post_urlencoded - urlencoded object with oneof not supported XFAIL tests/integration/contrib/falcon/test_falcon_project.py::TestPetPhotoResource::test_post_valid - falcon request binary handler not implemented XFAIL tests/integration/unmarshalling/test_unmarshallers.py::TestOAS30RequestSchemaUnmarshallersFactory::test_string_format_binary_invalid - OAS 3.0 string type checker allows byte. See https://github.com/python-openapi/openapi-schema-validator/issues/64 XFAIL tests/integration/unmarshalling/test_unmarshallers.py::TestOAS30RequestSchemaUnmarshallersFactory::test_nultiple_types_undefined[types0-string] - Rraises TypeError not SchemaError. See ttps://github.com/python-openapi/openapi-schema-validator/issues/65 XFAIL tests/integration/unmarshalling/test_unmarshallers.py::TestOAS30RequestSchemaUnmarshallersFactory::test_nultiple_types_undefined[types1-2] - Rraises TypeError not SchemaError. See ttps://github.com/python-openapi/openapi-schema-validator/issues/65 XFAIL tests/integration/unmarshalling/test_unmarshallers.py::TestOAS30RequestSchemaUnmarshallersFactory::test_nultiple_types_undefined[types2-3.14] - Rraises TypeError not SchemaError. See ttps://github.com/python-openapi/openapi-schema-validator/issues/65 XFAIL tests/integration/unmarshalling/test_unmarshallers.py::TestOAS30RequestSchemaUnmarshallersFactory::test_nultiple_types_undefined[types3-True] - Rraises TypeError not SchemaError. See ttps://github.com/python-openapi/openapi-schema-validator/issues/65 XFAIL tests/integration/unmarshalling/test_unmarshallers.py::TestOAS30RequestSchemaUnmarshallersFactory::test_nultiple_types_undefined[types4-value4] - Rraises TypeError not SchemaError. See ttps://github.com/python-openapi/openapi-schema-validator/issues/65 XFAIL tests/integration/unmarshalling/test_unmarshallers.py::TestOAS30RequestSchemaUnmarshallersFactory::test_nultiple_types_undefined[types5-value5] - Rraises TypeError not SchemaError. See ttps://github.com/python-openapi/openapi-schema-validator/issues/65 XFAIL tests/integration/unmarshalling/test_unmarshallers.py::TestOAS30ResponseSchemaUnmarshallersFactory::test_string_format_binary_invalid - OAS 3.0 string type checker allows byte. See https://github.com/python-openapi/openapi-schema-validator/issues/64 XFAIL tests/integration/unmarshalling/test_unmarshallers.py::TestOAS30ResponseSchemaUnmarshallersFactory::test_nultiple_types_undefined[types0-string] - Rraises TypeError not SchemaError. See ttps://github.com/python-openapi/openapi-schema-validator/issues/65 XFAIL tests/integration/unmarshalling/test_unmarshallers.py::TestOAS30ResponseSchemaUnmarshallersFactory::test_nultiple_types_undefined[types1-2] - Rraises TypeError not SchemaError. See ttps://github.com/python-openapi/openapi-schema-validator/issues/65 XFAIL tests/integration/unmarshalling/test_unmarshallers.py::TestOAS30ResponseSchemaUnmarshallersFactory::test_nultiple_types_undefined[types2-3.14] - Rraises TypeError not SchemaError. See ttps://github.com/python-openapi/openapi-schema-validator/issues/65 XFAIL tests/integration/unmarshalling/test_unmarshallers.py::TestOAS30ResponseSchemaUnmarshallersFactory::test_nultiple_types_undefined[types3-True] - Rraises TypeError not SchemaError. See ttps://github.com/python-openapi/openapi-schema-validator/issues/65 XFAIL tests/integration/unmarshalling/test_unmarshallers.py::TestOAS30ResponseSchemaUnmarshallersFactory::test_nultiple_types_undefined[types4-value4] - Rraises TypeError not SchemaError. See ttps://github.com/python-openapi/openapi-schema-validator/issues/65 XFAIL tests/integration/unmarshalling/test_unmarshallers.py::TestOAS30ResponseSchemaUnmarshallersFactory::test_nultiple_types_undefined[types5-value5] - Rraises TypeError not SchemaError. See ttps://github.com/python-openapi/openapi-schema-validator/issues/65 XFAIL tests/integration/unmarshalling/test_unmarshallers.py::TestOAS31SchemaUnmarshallersFactory::test_create_oas30_formatter_not_found[string-byte] - OpenAPI 3.1 schema validator uses OpenAPI 3.0 format checker.See https://github.com/python-openapi/openapi-core/issues/506 XFAIL tests/integration/unmarshalling/test_unmarshallers.py::TestOAS31SchemaUnmarshallersFactory::test_create_oas30_formatter_not_found[string-binary] - OpenAPI 3.1 schema validator uses OpenAPI 3.0 format checker.See https://github.com/python-openapi/openapi-core/issues/506 XFAIL tests/unit/templating/test_paths_finders.py::TestOperationSimpleServerServerNotFound::test_raises - returns default server XFAIL tests/unit/templating/test_paths_finders.py::TestPathSimpleServerServerNotFound::test_raises - returns default server XFAIL tests/unit/templating/test_paths_finders.py::TestOperationVariableServerServerNotFound::test_raises - returns default server XFAIL tests/unit/templating/test_paths_finders.py::TestPathVariableServerServerNotFound::test_raises - returns default server XFAIL tests/unit/templating/test_templating_util.py::TestSearch::test_special_chars_valid[/{test~id}/test-expected0] - Special characters of regex not supported. See https://github.com/python-openapi/openapi-core/issues/672 XFAIL tests/unit/templating/test_templating_util.py::TestSearch::test_special_chars_valid[/{test-id}/test-expected1] - Special characters of regex not supported. See https://github.com/python-openapi/openapi-core/issues/672 XFAIL tests/unit/unmarshalling/test_schema_unmarshallers.py::TestOAS30SchemaUnmarshallerUnmarshal::test_schema_format_validator_format_invalid - Not registered format raises FormatterNotFoundErrorSee https://github.com/python-openapi/openapi-core/issues/515 XPASS tests/unit/templating/test_paths_finders.py::TestSpecSimpleServerServerNotFound::test_raises returns default server XPASS tests/unit/templating/test_paths_finders.py::TestSpecVariableServerServerNotFound::test_raises returns default server =========================================================== 1375 passed, 2 skipped, 25 xfailed, 2 xpassed, 41 warnings in 12.91s ============================================================ ```

Expected Behavior

pytest should pass clean,

Steps to Reproduce

I'm packaging your module as an rpm package so I'm using the typical PEP517 based build, install and test cycle used on building packages from non-root account.

OpenAPI Core Version

0.18.1 + all commits up to f5f5792a

OpenAPI Core Integration

N/A

Affected Area(s)

Module testing using pytest.

References

N/A

Anything else we need to know?

Here is list of installed modules in build env

```console Package Version ----------------------------- --------- aiohttp 3.8.6 aioitertools 0.11.0 aiosignal 1.3.1 alabaster 0.7.13 annotated-types 0.6.0 anyio 4.0.0 appdirs 1.4.4 asgiref 3.7.2 async-timeout 4.0.3 attrs 23.1.0 Babel 2.13.1 backports.zoneinfo 0.2.1 blinker 1.6.2 build 1.0.3 certifi 2023.7.22 charset-normalizer 3.3.2 click 8.1.7 cppclean 0.13 distro 1.8.0 Django 4.2.6 djangorestframework 3.14.0 docutils 0.20.1 exceptiongroup 1.1.3 falcon 3.1.1 flake8 6.1.0 Flask 3.0.0 frozenlist 1.4.0 gpg 1.23.0 h11 0.14.0 httpcore 1.0.0 httpx 0.25.1 idna 3.4 imagesize 1.4.1 importlib-metadata 6.8.0 importlib-resources 6.1.0 iniconfig 2.0.0 installer 0.7.0 isodate 0.6.1 itsdangerous 2.1.2 Jinja2 3.1.2 jsonschema 4.19.1 jsonschema-path 0.3.1 jsonschema-specifications 2023.7.1 lazy-object-proxy 1.9.0 MarkupSafe 2.1.3 mccabe 0.7.0 more-itertools 10.1.0 multidict 6.0.4 openapi-schema-validator 0.6.2 openapi-spec-validator 0.7.1 packaging 23.2 parse 1.19.1 pathable 0.4.3 pkgutil_resolve_name 1.3.10 pluggy 1.3.0 poetry-core 1.8.1 pycodestyle 2.11.0 pydantic 2.4.2 pydantic_core 2.11.0 pydantic-extra-types 2.1.0 pyflakes 3.1.0 Pygments 2.16.1 pyproject_hooks 1.0.0 pytest 7.4.3 pytest-aiohttp 1.0.5 pytest-asyncio 0.21.1 pytest-flake8 1.1.1 python-dateutil 2.8.2 pytz 2023.3 PyYAML 6.0.1 referencing 0.30.2 requests 2.31.0 responses 0.24.0 rfc3339-validator 0.1.4 rpds-py 0.12.0 six 1.16.0 sniffio 1.3.0 snowballstemmer 2.2.0 Sphinx 7.1.2 sphinx-immaterial 0.11.8 sphinxcontrib-applehelp 1.0.4 sphinxcontrib-devhelp 1.0.5 sphinxcontrib-htmlhelp 2.0.4 sphinxcontrib-jsmath 1.0.1 sphinxcontrib-qthelp 1.0.3 sphinxcontrib-serializinghtml 1.1.9 sqlparse 0.4.4 starlette 0.32.0 strict-rfc3339 0.7 tomli 2.0.1 typing_extensions 4.8.0 urllib3 1.26.18 WebOb 1.8.7 Werkzeug 3.0.0 wheel 0.41.3 yarl 1.9.2 zipp 3.17.0 ```

I think that because 86f82182 (jsonschema-spec to jsonschema-path migration) it would be good to release new version.

Would you like to implement a fix?

None

p1c2u commented 1 year ago

hi @kloczek

thanks for the report. I will have a look.

p1c2u commented 1 year ago

Most warnings are resolved. The only left is inside falcon.media.handlers for cgi module.

kloczek commented 1 year ago

Thank you 👍