diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index b6082213..090add00 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -12,15 +12,12 @@ on: jobs: publish: runs-on: ubuntu-latest - strategy: - matrix: - python-version: [2.7, 3.6] steps: - uses: actions/checkout@v2 - - name: Set up Python ${{ matrix.python-version }} + - name: Set up Python uses: actions/setup-python@v2 with: - python-version: ${{ matrix.python-version }} + python-version: '3.x' - name: Install dependencies run: | python -m pip install --upgrade pip diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index 9d22fb30..f006456d 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [2.7, 3.5, 3.6, 3.7, 3.8, 3.9] + python-version: [3.5, 3.6, 3.7, 3.8, 3.9] fail-fast: false steps: - uses: actions/checkout@v2 diff --git a/.travis.yml b/.travis.yml index 5f2f80a8..83226eb0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,6 @@ language: python sudo: false matrix: include: - - python: 2.7 - python: 3.5 - python: 3.6 - python: 3.7 diff --git a/MANIFEST.in b/MANIFEST.in index e05e9132..a3c3251b 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -2,4 +2,3 @@ include LICENSE include README.rst include requirements.txt include requirements_dev.txt -include requirements_2.7.txt diff --git a/openapi_core/casting/schemas/util.py b/openapi_core/casting/schemas/util.py index bb000a77..16a1d42c 100644 --- a/openapi_core/casting/schemas/util.py +++ b/openapi_core/casting/schemas/util.py @@ -1,10 +1,9 @@ """OpenAPI core casting schemas util module""" from distutils.util import strtobool -from six import string_types def forcebool(val): - if isinstance(val, string_types): + if isinstance(val, str): val = strtobool(val) return bool(val) diff --git a/openapi_core/compat.py b/openapi_core/compat.py deleted file mode 100644 index 53eeadf7..00000000 --- a/openapi_core/compat.py +++ /dev/null @@ -1,12 +0,0 @@ -"""OpenAPI core python 2.7 compatibility module""" -try: - from functools import lru_cache -except ImportError: - from backports.functools_lru_cache import lru_cache - -try: - from functools import partialmethod -except ImportError: - from backports.functools_partialmethod import partialmethod - -__all__ = ['lru_cache', 'partialmethod'] diff --git a/openapi_core/contrib/django/requests.py b/openapi_core/contrib/django/requests.py index ace403ea..9058be51 100644 --- a/openapi_core/contrib/django/requests.py +++ b/openapi_core/contrib/django/requests.py @@ -1,7 +1,7 @@ """OpenAPI core contrib django requests module""" import re -from six.moves.urllib.parse import urljoin +from urllib.parse import urljoin from openapi_core.contrib.django.compat import ( get_request_headers, get_current_scheme_host, diff --git a/openapi_core/contrib/flask/requests.py b/openapi_core/contrib/flask/requests.py index d9b5d262..f6aeb972 100644 --- a/openapi_core/contrib/flask/requests.py +++ b/openapi_core/contrib/flask/requests.py @@ -1,7 +1,7 @@ """OpenAPI core contrib flask requests module""" import re -from six.moves.urllib.parse import urljoin +from urllib.parse import urljoin from openapi_core.validation.request.datatypes import ( RequestParameters, OpenAPIRequest, diff --git a/openapi_core/contrib/requests/requests.py b/openapi_core/contrib/requests/requests.py index 4d0490fe..26e87265 100644 --- a/openapi_core/contrib/requests/requests.py +++ b/openapi_core/contrib/requests/requests.py @@ -1,8 +1,9 @@ """OpenAPI core contrib requests requests module""" from __future__ import absolute_import +from urllib.parse import urlparse, parse_qs + from werkzeug.datastructures import ImmutableMultiDict from requests import Request -from six.moves.urllib.parse import urlparse, parse_qs from openapi_core.validation.request.datatypes import ( RequestParameters, OpenAPIRequest, diff --git a/openapi_core/deserializing/media_types/util.py b/openapi_core/deserializing/media_types/util.py index f1e6762d..195d00c5 100644 --- a/openapi_core/deserializing/media_types/util.py +++ b/openapi_core/deserializing/media_types/util.py @@ -1,13 +1,11 @@ from email.parser import Parser from json import loads - -from six import binary_type -from six.moves.urllib.parse import parse_qsl +from urllib.parse import parse_qsl def json_loads(value): # python 3.5 doesn't support binary input fix - if isinstance(value, (binary_type, )): + if isinstance(value, (bytes, )): value = value.decode() return loads(value) @@ -17,7 +15,7 @@ def urlencoded_form_loads(value): def data_form_loads(value): - if issubclass(type(value), binary_type): + if issubclass(type(value), bytes): value = value.decode('ASCII', errors='surrogateescape') parser = Parser() parts = parser.parsestr(value, headersonly=False) diff --git a/openapi_core/schema/schemas.py b/openapi_core/schema/schemas.py index 79a5d16d..9803a7f8 100644 --- a/openapi_core/schema/schemas.py +++ b/openapi_core/schema/schemas.py @@ -1,11 +1,9 @@ from __future__ import division -from six import iteritems - def get_all_properties(schema): properties = schema.get('properties', {}) - properties_dict = dict(iteritems(properties)) + properties_dict = dict(properties.items()) if 'allOf'not in schema: return properties_dict diff --git a/openapi_core/schema/servers.py b/openapi_core/schema/servers.py index 66854513..1050fdcb 100644 --- a/openapi_core/schema/servers.py +++ b/openapi_core/schema/servers.py @@ -1,7 +1,5 @@ from __future__ import division -from six import iteritems - def is_absolute(url): return url.startswith('//') or '://' in url @@ -13,7 +11,7 @@ def get_server_default_variables(server): defaults = {} variables = server / 'variables' - for name, variable in iteritems(variables): + for name, variable in variables.items(): defaults[name] = variable['default'] return defaults diff --git a/openapi_core/templating/paths/finders.py b/openapi_core/templating/paths/finders.py index 4daf6a3d..4d9116d2 100644 --- a/openapi_core/templating/paths/finders.py +++ b/openapi_core/templating/paths/finders.py @@ -1,8 +1,8 @@ """OpenAPI core templating paths finders module""" from __future__ import division +from urllib.parse import urljoin, urlparse from more_itertools import peekable -from six.moves.urllib.parse import urljoin, urlparse from openapi_core.schema.servers import is_absolute from openapi_core.templating.datatypes import TemplateResult diff --git a/openapi_core/testing/requests.py b/openapi_core/testing/requests.py index 7d3d0ed9..6a815ed7 100644 --- a/openapi_core/testing/requests.py +++ b/openapi_core/testing/requests.py @@ -1,5 +1,6 @@ """OpenAPI core testing requests module""" -from six.moves.urllib.parse import urljoin +from urllib.parse import urljoin + from werkzeug.datastructures import ImmutableMultiDict from openapi_core.validation.request.datatypes import ( diff --git a/openapi_core/unmarshalling/schemas/unmarshallers.py b/openapi_core/unmarshalling/schemas/unmarshallers.py index 9fd07893..2faf6165 100644 --- a/openapi_core/unmarshalling/schemas/unmarshallers.py +++ b/openapi_core/unmarshalling/schemas/unmarshallers.py @@ -9,8 +9,6 @@ is_object, is_number, is_string, ) from openapi_schema_validator._format import oas30_format_checker -from six import text_type, binary_type -from six import iteritems from openapi_core.extensions.models.factories import ModelFactory from openapi_core.schema.schemas import ( @@ -77,16 +75,16 @@ class StringUnmarshaller(PrimitiveTypeUnmarshaller): FORMATTERS = { None: Formatter.from_callables( - partial(is_string, None), text_type), + partial(is_string, None), str), 'password': Formatter.from_callables( - partial(oas30_format_checker.check, format='password'), text_type), + partial(oas30_format_checker.check, format='password'), str), 'date': Formatter.from_callables( partial(oas30_format_checker.check, format='date'), format_date), 'date-time': Formatter.from_callables( partial(oas30_format_checker.check, format='date-time'), parse_datetime), 'binary': Formatter.from_callables( - partial(oas30_format_checker.check, format='binary'), binary_type), + partial(oas30_format_checker.check, format='binary'), bytes), 'uuid': Formatter.from_callables( partial(oas30_format_checker.check, format='uuid'), format_uuid), 'byte': Formatter.from_callables( @@ -226,7 +224,7 @@ def _unmarshal_properties(self, value=NoValue, one_of_schema=None): prop_value = value[prop_name] properties[prop_name] = prop_value - for prop_name, prop in iteritems(all_props): + for prop_name, prop in all_props.items(): read_only = prop.getkey('readOnly', False) if self.context == UnmarshalContext.REQUEST and read_only: continue diff --git a/openapi_core/unmarshalling/schemas/util.py b/openapi_core/unmarshalling/schemas/util.py index 66654caa..31920c82 100644 --- a/openapi_core/unmarshalling/schemas/util.py +++ b/openapi_core/unmarshalling/schemas/util.py @@ -3,16 +3,14 @@ from copy import copy import datetime from distutils.util import strtobool -from six import string_types, text_type, integer_types +from functools import lru_cache from uuid import UUID from openapi_schema_validator import oas30_format_checker -from openapi_core.compat import lru_cache - def forcebool(val): - if isinstance(val, string_types): + if isinstance(val, str): val = strtobool(val) return bool(val) @@ -29,11 +27,11 @@ def format_uuid(value): def format_byte(value, encoding='utf8'): - return text_type(b64decode(value), encoding) + return str(b64decode(value), encoding) def format_number(value): - if isinstance(value, integer_types + (float, )): + if isinstance(value, (int, float)): return value return float(value) diff --git a/requirements.txt b/requirements.txt index b2d723d3..75a2cf77 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,8 +2,6 @@ isodate==0.6.0 dictpath==0.1.3 openapi-spec-validator openapi-schema-validator -six -lazy-object-proxy attrs parse==1.14.0 more-itertools>=5.0.0 diff --git a/requirements_2.7.txt b/requirements_2.7.txt deleted file mode 100644 index f4eb34c3..00000000 --- a/requirements_2.7.txt +++ /dev/null @@ -1,10 +0,0 @@ -isodate==0.6.0 -openapi-spec-validator -openapi-schema-validator -six -lazy-object-proxy -backports.functools-lru-cache -backports.functools-partialmethod -enum34 -attrs -more-itertools==5.0.0 diff --git a/requirements_dev.txt b/requirements_dev.txt index e5d462ef..e1cba1c0 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,12 +1,9 @@ -mock==2.0.0 -pytest==3.5.0 +pytest==5.4.3 pytest-flake8 pytest-cov==2.5.1 -falcon==2.0.0; python_version<"3.0" -falcon==3.0.0; python_version>="3.0" +falcon==3.0.0 flask -django==1.11.29; python_version<"3.0" -django==2.2.18; python_version>="3.0" +django==2.2.18 djangorestframework==3.9.4 requests==2.22.0 responses==0.10.12 diff --git a/setup.cfg b/setup.cfg index 4936a19d..f18bf7e1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -9,7 +9,6 @@ classifiers = Intended Audience :: Developers Topic :: Software Development :: Libraries :: Python Modules Operating System :: OS Independent - Programming Language :: Python :: 2.7 Programming Language :: Python :: 3.5 Programming Language :: Python :: 3.6 Programming Language :: Python :: 3.7 @@ -22,7 +21,7 @@ include_package_data = True packages = find: zip_safe = False test_suite = tests -python_requires = >= 2.7, != 3.0.*, != 3.1.*, != 3.2.*, != 3.3.*, != 3.4.* +python_requires = >= 3.5 setup_requires = setuptools install_requires = @@ -30,17 +29,12 @@ install_requires = dictpath openapi-spec-validator openapi-schema-validator - six - lazy-object-proxy attrs werkzeug parse more-itertools - backports.functools-lru-cache; python_version<"3.0" - backports.functools-partialmethod; python_version<"3.0" tests_require = - mock; python_version<"3.0" - pytest + pytest>=5.0.0 pytest-flake8 pytest-cov falcon @@ -53,8 +47,7 @@ exclude = tests [options.extras_require] -django = - django>=2.2; python_version>="3.0" +django = django>=2.2 flask = flask requests = requests diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 06d640c0..dfd769d3 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -1,8 +1,8 @@ from os import path +from urllib import request from openapi_spec_validator.schemas import read_yaml_file import pytest -from six.moves.urllib import request from yaml import safe_load diff --git a/tests/integration/contrib/django/conftest.py b/tests/integration/contrib/django/conftest.py index ce5074b3..dc172d00 100644 --- a/tests/integration/contrib/django/conftest.py +++ b/tests/integration/contrib/django/conftest.py @@ -1,10 +1,11 @@ -import mock -import pytest import os import sys +from unittest import mock + +import pytest -@pytest.yield_fixture(autouse=True, scope='module') +@pytest.fixture(autouse=True, scope='module') def django_setup(): directory = os.path.abspath(os.path.dirname(__file__)) django_project_dir = os.path.join(directory, 'data') diff --git a/tests/integration/contrib/django/test_django_rest_framework_apiview.py b/tests/integration/contrib/django/test_django_rest_framework_apiview.py index 3ccc39d2..89f5b61a 100644 --- a/tests/integration/contrib/django/test_django_rest_framework_apiview.py +++ b/tests/integration/contrib/django/test_django_rest_framework_apiview.py @@ -1,7 +1,5 @@ import pytest -from six import b - class TestDjangoRESTFrameworkAPIView(object): @@ -17,4 +15,4 @@ def test_get(self, api_request_factory): response = view(request, pk='4') - assert response.content == b('{"test": "test_val"}') + assert response.content == b'{"test": "test_val"}' diff --git a/tests/integration/contrib/falcon/test_falcon_middlewares.py b/tests/integration/contrib/falcon/test_falcon_middlewares.py index cbfce002..a6bc28d3 100644 --- a/tests/integration/contrib/falcon/test_falcon_middlewares.py +++ b/tests/integration/contrib/falcon/test_falcon_middlewares.py @@ -26,7 +26,7 @@ def middleware(self, spec): def app(self, middleware): return App(middleware=[middleware]) - @pytest.yield_fixture + @pytest.fixture def client(self, app): return TestClient(app) diff --git a/tests/integration/contrib/flask/test_flask_decorator.py b/tests/integration/contrib/flask/test_flask_decorator.py index 6e6c899c..95ab8641 100644 --- a/tests/integration/contrib/flask/test_flask_decorator.py +++ b/tests/integration/contrib/flask/test_flask_decorator.py @@ -26,7 +26,7 @@ def app(self): app.config['TESTING'] = True return app - @pytest.yield_fixture + @pytest.fixture def client(self, app): with app.test_client() as client: with app.app_context(): diff --git a/tests/integration/contrib/flask/test_flask_requests.py b/tests/integration/contrib/flask/test_flask_requests.py index 613f3168..ca57f0fd 100644 --- a/tests/integration/contrib/flask/test_flask_requests.py +++ b/tests/integration/contrib/flask/test_flask_requests.py @@ -1,4 +1,5 @@ -from six.moves.urllib.parse import urljoin +from urllib.parse import urljoin + from werkzeug.datastructures import EnvironHeaders, ImmutableMultiDict from openapi_core.contrib.flask import FlaskOpenAPIRequest diff --git a/tests/integration/contrib/flask/test_flask_views.py b/tests/integration/contrib/flask/test_flask_views.py index 2933e505..ddc5d1d1 100644 --- a/tests/integration/contrib/flask/test_flask_views.py +++ b/tests/integration/contrib/flask/test_flask_views.py @@ -21,7 +21,7 @@ def app(self): app.config['TESTING'] = True return app - @pytest.yield_fixture + @pytest.fixture def client(self, app): with app.test_client() as client: with app.app_context(): diff --git a/tests/integration/contrib/requests/conftest.py b/tests/integration/contrib/requests/conftest.py index fc62bfc8..c095aa59 100644 --- a/tests/integration/contrib/requests/conftest.py +++ b/tests/integration/contrib/requests/conftest.py @@ -1,8 +1,9 @@ +from io import BytesIO +from urllib.parse import urljoin, parse_qs + import pytest from requests.models import Request, Response from requests.structures import CaseInsensitiveDict -from six import BytesIO, b -from six.moves.urllib.parse import urljoin, parse_qs from urllib3.response import HTTPResponse @@ -26,7 +27,7 @@ def create_request(method, path, subdomain=None, query_string=''): def response_factory(): def create_response( data, status_code=200, content_type='application/json'): - fp = BytesIO(b(data)) + fp = BytesIO(bytes(data, 'latin-1')) raw = HTTPResponse(fp, preload_content=False) resp = Response() resp.headers = CaseInsensitiveDict({ diff --git a/tests/integration/contrib/test_django.py b/tests/integration/contrib/test_django.py index 7d608798..e23bfc19 100644 --- a/tests/integration/contrib/test_django.py +++ b/tests/integration/contrib/test_django.py @@ -1,7 +1,6 @@ import sys import pytest -from six import b from openapi_core.contrib.django import ( DjangoOpenAPIRequest, DjangoOpenAPIResponse, @@ -56,7 +55,7 @@ def request_factory(self): def response_factory(self): from django.http import HttpResponse - def create(content=b(''), status_code=None): + def create(content=b'', status_code=None): return HttpResponse(content, status=status_code) return create @@ -148,7 +147,7 @@ def test_stream_response(self, response_factory): openapi_response = DjangoOpenAPIResponse(response) - assert openapi_response.data == b('foo\nbar\nbaz\n') + assert openapi_response.data == b'foo\nbar\nbaz\n' assert openapi_response.status_code == response.status_code assert openapi_response.mimetype == response["Content-Type"] @@ -176,7 +175,7 @@ def test_response_validator_path_pattern( request = request_factory.get('/admin/auth/group/1/') request.resolver_match = resolve('/admin/auth/group/1/') openapi_request = DjangoOpenAPIRequest(request) - response = response_factory(b('Some item')) + response = response_factory(b'Some item') openapi_response = DjangoOpenAPIResponse(response) result = validator.validate(openapi_request, openapi_response) assert not result.errors diff --git a/tests/integration/schema/test_spec.py b/tests/integration/schema/test_spec.py index d402e180..6ae2319d 100644 --- a/tests/integration/schema/test_spec.py +++ b/tests/integration/schema/test_spec.py @@ -1,7 +1,6 @@ from __future__ import division import pytest from base64 import b64encode -from six import iteritems, text_type from openapi_core.shortcuts import create_spec from openapi_core.schema.servers import get_server_url @@ -18,7 +17,7 @@ class TestPetstore(object): def api_key_encoded(self): api_key_bytes = self.api_key.encode('utf8') api_key_bytes_enc = b64encode(api_key_bytes) - return text_type(api_key_bytes_enc, 'utf8') + return str(api_key_bytes_enc, 'utf8') @pytest.fixture def spec_uri(self): @@ -65,7 +64,7 @@ def test_spec(self, spec, spec_dict): security_spec = spec_dict.get('security', []) for idx, security_reqs in enumerate(security): security_reqs_spec = security_spec[idx] - for scheme_name, security_req in iteritems(security_reqs): + for scheme_name, security_req in security_reqs.items(): security_req == security_reqs_spec[scheme_name] assert get_spec_url(spec) == url @@ -77,13 +76,13 @@ def test_spec(self, spec, spec_dict): assert get_server_url(server) == url variables = server / 'variables' - for variable_name, variable in iteritems(variables): + for variable_name, variable in variables.items(): variable_spec = server_spec['variables'][variable_name] assert variable['default'] == variable_spec['default'] assert variable['enum'] == variable_spec.get('enum') paths = spec / 'paths' - for path_name, path in iteritems(paths): + for path_name, path in paths.items(): path_spec = spec_dict['paths'][path_name] assert path.getkey('summary') == path_spec.get('summary') assert path.getkey('description') == path_spec.get('description') @@ -97,7 +96,7 @@ def test_spec(self, spec, spec_dict): assert server.description == server_spec.get('description') variables = server.get('variables', {}) - for variable_name, variable in iteritems(variables): + for variable_name, variable in variables.items(): variable_spec = server_spec['variables'][variable_name] assert variable['default'] == variable_spec['default'] assert variable.getkey('enum') == variable_spec.get('enum') @@ -136,7 +135,7 @@ def test_spec(self, spec, spec_dict): 'description') variables = server.get('variables', {}) - for variable_name, variable in iteritems(variables): + for variable_name, variable in variables.items(): variable_spec = server_spec['variables'][variable_name] assert variable['default'] == variable_spec['default'] assert variable.getkey('enum') == variable_spec.get( @@ -147,13 +146,12 @@ def test_spec(self, spec, spec_dict): if security_spec is not None: for idx, security_reqs in enumerate(security): security_reqs_spec = security_spec[idx] - for scheme_name, security_req in iteritems( - security_reqs): + for scheme_name, security_req in security_reqs.items(): security_req == security_reqs_spec[scheme_name] responses = operation / 'responses' responses_spec = operation_spec.get('responses') - for http_status, response in iteritems(responses): + for http_status, response in responses.items(): response_spec = responses_spec[http_status] if not response_spec: @@ -168,7 +166,7 @@ def test_spec(self, spec, spec_dict): assert response.getkey('description') == description_spec headers = response.get('headers', {}) - for parameter_name, parameter in iteritems(headers): + for parameter_name, parameter in headers.items(): headers_spec = response_spec['headers'] parameter_spec = headers_spec[parameter_name] @@ -197,7 +195,7 @@ def test_spec(self, spec, spec_dict): if not content_spec: continue - for mimetype, media_type in iteritems(content): + for mimetype, media_type in content.items(): media_spec = parameter_spec['content'][mimetype] schema = media_type.get('schema') schema_spec = media_spec.get('schema') @@ -223,7 +221,7 @@ def test_spec(self, spec, spec_dict): continue content = response.get('content', {}) - for mimetype, media_type in iteritems(content): + for mimetype, media_type in content.items(): content_spec = response_spec['content'][mimetype] example_spec = content_spec.get('example') @@ -255,7 +253,7 @@ def test_spec(self, spec, spec_dict): request_body_spec.get('required') content = request_body / 'content' - for mimetype, media_type in iteritems(content): + for mimetype, media_type in content.items(): content_spec = request_body_spec['content'][mimetype] schema_spec = content_spec.get('schema') @@ -281,7 +279,7 @@ def test_spec(self, spec, spec_dict): return schemas = components.get('schemas', {}) - for schema_name, schema in iteritems(schemas): + for schema_name, schema in schemas.items(): schema_spec = spec_dict['components']['schemas'][schema_name] assert schema.getkey('readOnly') == schema_spec.get('readOnly') assert schema.getkey('writeOnly') == schema_spec.get('writeOnly') diff --git a/tests/integration/validation/test_petstore.py b/tests/integration/validation/test_petstore.py index 6dc8b7a1..2aa239c3 100644 --- a/tests/integration/validation/test_petstore.py +++ b/tests/integration/validation/test_petstore.py @@ -4,7 +4,6 @@ from base64 import b64encode from uuid import UUID from isodate.tzinfo import UTC -from six import text_type from openapi_core.casting.schemas.exceptions import CastError from openapi_core.deserializing.exceptions import DeserializeError @@ -38,7 +37,7 @@ class TestPetstore(object): def api_key_encoded(self): api_key_bytes = self.api_key.encode('utf8') api_key_bytes_enc = b64encode(api_key_bytes) - return text_type(api_key_bytes_enc, 'utf8') + return str(api_key_bytes_enc, 'utf8') @pytest.fixture(scope='module') def spec_uri(self): diff --git a/tests/integration/validation/test_security_override.py b/tests/integration/validation/test_security_override.py index 370012c1..1cd03b30 100644 --- a/tests/integration/validation/test_security_override.py +++ b/tests/integration/validation/test_security_override.py @@ -1,7 +1,6 @@ from base64 import b64encode import pytest -from six import text_type from openapi_core.shortcuts import create_spec from openapi_core.validation.exceptions import InvalidSecurity @@ -30,7 +29,7 @@ class TestSecurityOverride(object): def api_key_encoded(self): api_key_bytes = self.api_key.encode('utf8') api_key_bytes_enc = b64encode(api_key_bytes) - return text_type(api_key_bytes_enc, 'utf8') + return str(api_key_bytes_enc, 'utf8') def test_default(self, request_validator): args = {'api_key': self.api_key} diff --git a/tests/integration/validation/test_validators.py b/tests/integration/validation/test_validators.py index 3168d6f6..b5d2a5cf 100644 --- a/tests/integration/validation/test_validators.py +++ b/tests/integration/validation/test_validators.py @@ -1,7 +1,6 @@ from base64 import b64encode import json import pytest -from six import text_type from openapi_core.casting.schemas.exceptions import CastError from openapi_core.deserializing.exceptions import DeserializeError @@ -34,7 +33,7 @@ class TestRequestValidator(object): def api_key_encoded(self): api_key_bytes = self.api_key.encode('utf8') api_key_bytes_enc = b64encode(api_key_bytes) - return text_type(api_key_bytes_enc, 'utf8') + return str(api_key_bytes_enc, 'utf8') @pytest.fixture(scope='session') def spec_dict(self, factory): diff --git a/tests/unit/deserializing/test_media_types_deserializers.py b/tests/unit/deserializing/test_media_types_deserializers.py index 77d36e9d..e38c265f 100644 --- a/tests/unit/deserializing/test_media_types_deserializers.py +++ b/tests/unit/deserializing/test_media_types_deserializers.py @@ -1,7 +1,5 @@ import pytest -from six import b, u - from openapi_core.deserializing.exceptions import DeserializeError from openapi_core.deserializing.media_types.factories import ( MediaTypeDeserializersFactory, @@ -48,7 +46,7 @@ def test_urlencoded_form_simple(self, deserializer_factory): assert result == {'param1': 'test'} - @pytest.mark.parametrize('value', [b(''), u('')]) + @pytest.mark.parametrize('value', [b'', '']) def test_data_form_empty(self, deserializer_factory, value): mimetype = 'multipart/form-data' @@ -58,19 +56,19 @@ def test_data_form_empty(self, deserializer_factory, value): def test_data_form_simple(self, deserializer_factory): mimetype = 'multipart/form-data' - value = b( - 'Content-Type: multipart/form-data; boundary="' - '===============2872712225071193122=="\n' - 'MIME-Version: 1.0\n\n' - '--===============2872712225071193122==\n' - 'Content-Type: text/plain\nMIME-Version: 1.0\n' - 'Content-Disposition: form-data; name="param1"\n\ntest\n' - '--===============2872712225071193122==--\n' + value = ( + b'Content-Type: multipart/form-data; boundary="' + b'===============2872712225071193122=="\n' + b'MIME-Version: 1.0\n\n' + b'--===============2872712225071193122==\n' + b'Content-Type: text/plain\nMIME-Version: 1.0\n' + b'Content-Disposition: form-data; name="param1"\n\ntest\n' + b'--===============2872712225071193122==--\n' ) result = deserializer_factory(mimetype)(value) - assert result == {'param1': b('test')} + assert result == {'param1': b'test'} def test_custom_simple(self, deserializer_factory): custom_mimetype = 'application/custom' diff --git a/tests/unit/templating/test_responses_finders.py b/tests/unit/templating/test_responses_finders.py index 11b4fac8..3a8303cc 100644 --- a/tests/unit/templating/test_responses_finders.py +++ b/tests/unit/templating/test_responses_finders.py @@ -1,5 +1,6 @@ from __future__ import division -import mock +from unittest import mock + import pytest from openapi_core.spec.paths import SpecPath diff --git a/tests/unit/unmarshalling/test_unmarshal.py b/tests/unit/unmarshalling/test_unmarshal.py index ed987890..4b38d67f 100644 --- a/tests/unit/unmarshalling/test_unmarshal.py +++ b/tests/unit/unmarshalling/test_unmarshal.py @@ -302,9 +302,7 @@ def test_string_format_invalid_value(self, unmarshaller_factory): with pytest.raises( FormatterNotFoundError, - message=( - 'Formatter not found for custom format' - ), + match='Formatter not found for custom format', ): unmarshaller_factory(schema)(value) diff --git a/tests/unit/unmarshalling/test_validate.py b/tests/unit/unmarshalling/test_validate.py index b73c341e..e059d25c 100644 --- a/tests/unit/unmarshalling/test_validate.py +++ b/tests/unit/unmarshalling/test_validate.py @@ -1,6 +1,6 @@ import datetime +from unittest import mock -import mock import pytest from openapi_core.extensions.models.models import Model @@ -13,8 +13,6 @@ ) from openapi_core.unmarshalling.schemas.util import build_format_checker -from six import b, u - class TestSchemaValidate(object): @@ -77,7 +75,7 @@ def test_boolean(self, value, validator_factory): assert result is None - @pytest.mark.parametrize('value', [1, 3.14, u('true'), [True, False]]) + @pytest.mark.parametrize('value', [1, 3.14, 'true', [True, False]]) def test_boolean_invalid(self, value, validator_factory): spec = { 'type': 'boolean', @@ -111,7 +109,7 @@ def test_array(self, value, validator_factory): assert result is None - @pytest.mark.parametrize('value', [False, 1, 3.14, u('true'), (3, 4)]) + @pytest.mark.parametrize('value', [False, 1, 3.14, 'true', (3, 4)]) def test_array_invalid(self, value, validator_factory): spec = { 'type': 'array', @@ -132,7 +130,7 @@ def test_integer(self, value, validator_factory): assert result is None - @pytest.mark.parametrize('value', [False, 3.14, u('true'), [1, 2]]) + @pytest.mark.parametrize('value', [False, 3.14, 'true', [1, 2]]) def test_integer_invalid(self, value, validator_factory): spec = { 'type': 'integer', @@ -351,7 +349,7 @@ def test_number_multiple_of(self, value, validator_factory): assert result is None - @pytest.mark.parametrize('value', [u('true'), b('test')]) + @pytest.mark.parametrize('value', ['true', b'test']) def test_string(self, value, validator_factory): spec = { 'type': 'string', @@ -373,7 +371,7 @@ def test_string_invalid(self, value, validator_factory): validator_factory(schema).validate(value) @pytest.mark.parametrize('value', [ - b('true'), u('test'), False, 1, 3.14, [1, 3], + b'true', 'test', False, 1, 3.14, [1, 3], datetime.datetime(1989, 1, 2), ]) def test_string_format_date_invalid(self, value, validator_factory): @@ -387,7 +385,7 @@ def test_string_format_date_invalid(self, value, validator_factory): validator_factory(schema).validate(value) @pytest.mark.parametrize('value', [ - u('1989-01-02'), u('2018-01-02'), + '1989-01-02', '2018-01-02', ]) def test_string_format_date(self, value, validator_factory): spec = { @@ -401,7 +399,7 @@ def test_string_format_date(self, value, validator_factory): assert result is None @pytest.mark.parametrize('value', [ - u('12345678-1234-5678-1234-567812345678'), + '12345678-1234-5678-1234-567812345678', ]) def test_string_format_uuid(self, value, validator_factory): spec = { @@ -415,7 +413,7 @@ def test_string_format_uuid(self, value, validator_factory): assert result is None @pytest.mark.parametrize('value', [ - b('true'), u('true'), False, 1, 3.14, [1, 3], + b'true', 'true', False, 1, 3.14, [1, 3], datetime.date(2018, 1, 2), datetime.datetime(2018, 1, 2, 23, 59, 59), ]) def test_string_format_uuid_invalid(self, value, validator_factory): @@ -429,8 +427,8 @@ def test_string_format_uuid_invalid(self, value, validator_factory): validator_factory(schema).validate(value) @pytest.mark.parametrize('value', [ - b('true'), u('true'), False, 1, 3.14, [1, 3], - u('1989-01-02'), + b'true', 'true', False, 1, 3.14, [1, 3], + '1989-01-02', ]) def test_string_format_datetime_invalid(self, value, validator_factory): spec = { @@ -443,8 +441,8 @@ def test_string_format_datetime_invalid(self, value, validator_factory): validator_factory(schema).validate(value) @pytest.mark.parametrize('value', [ - u('1989-01-02T00:00:00Z'), - u('2018-01-02T23:59:59Z'), + '1989-01-02T00:00:00Z', + '2018-01-02T23:59:59Z', ]) @mock.patch( 'openapi_schema_validator._format.' @@ -467,8 +465,8 @@ def test_string_format_datetime_strict_rfc3339( assert result is None @pytest.mark.parametrize('value', [ - u('1989-01-02T00:00:00Z'), - u('2018-01-02T23:59:59Z'), + '1989-01-02T00:00:00Z', + '2018-01-02T23:59:59Z', ]) @mock.patch( 'openapi_schema_validator._format.' @@ -490,8 +488,8 @@ def test_string_format_datetime_isodate(self, value, validator_factory): assert result is None @pytest.mark.parametrize('value', [ - u('true'), False, 1, 3.14, [1, 3], u('1989-01-02'), - u('1989-01-02T00:00:00Z'), + 'true', False, 1, 3.14, [1, 3], '1989-01-02', + '1989-01-02T00:00:00Z', ]) def test_string_format_binary_invalid(self, value, validator_factory): spec = { @@ -504,7 +502,7 @@ def test_string_format_binary_invalid(self, value, validator_factory): validator_factory(schema).validate(value) @pytest.mark.parametrize('value', [ - b('stream'), b('text'), + b'stream', b'text', ]) def test_string_format_binary(self, value, validator_factory): spec = { @@ -518,7 +516,7 @@ def test_string_format_binary(self, value, validator_factory): assert result is None @pytest.mark.parametrize('value', [ - b('dGVzdA=='), u('dGVzdA=='), + b'dGVzdA==', 'dGVzdA==', ]) def test_string_format_byte(self, value, validator_factory): spec = { @@ -532,7 +530,7 @@ def test_string_format_byte(self, value, validator_factory): assert result is None @pytest.mark.parametrize('value', [ - u('tsssst'), b('tsssst'), b('tesddddsdsdst'), + 'tsssst', b'tsssst', b'tesddddsdsdst', ]) def test_string_format_byte_invalid(self, value, validator_factory): spec = { @@ -545,7 +543,7 @@ def test_string_format_byte_invalid(self, value, validator_factory): validator_factory(schema).validate(value) @pytest.mark.parametrize('value', [ - u('test'), b('stream'), datetime.date(1989, 1, 2), + 'test', b'stream', datetime.date(1989, 1, 2), datetime.datetime(1989, 1, 2, 0, 0, 0), ]) def test_string_format_unknown(self, value, validator_factory): @@ -559,7 +557,7 @@ def test_string_format_unknown(self, value, validator_factory): with pytest.raises(FormatterNotFoundError): validator_factory(schema).validate(value) - @pytest.mark.parametrize('value', [u(""), u("a"), u("ab")]) + @pytest.mark.parametrize('value', ["", "a", "ab"]) def test_string_min_length_invalid(self, value, validator_factory): spec = { 'type': 'string', @@ -570,7 +568,7 @@ def test_string_min_length_invalid(self, value, validator_factory): with pytest.raises(InvalidSchemaValue): validator_factory(schema).validate(value) - @pytest.mark.parametrize('value', [u("abc"), u("abcd")]) + @pytest.mark.parametrize('value', ["abc", "abcd"]) def test_string_min_length(self, value, validator_factory): spec = { 'type': 'string', @@ -582,7 +580,7 @@ def test_string_min_length(self, value, validator_factory): assert result is None - @pytest.mark.parametrize('value', [u(""), ]) + @pytest.mark.parametrize('value', ["", ]) def test_string_max_length_invalid_schema(self, value, validator_factory): spec = { 'type': 'string', @@ -593,7 +591,7 @@ def test_string_max_length_invalid_schema(self, value, validator_factory): with pytest.raises(InvalidSchemaValue): validator_factory(schema).validate(value) - @pytest.mark.parametrize('value', [u("ab"), u("abc")]) + @pytest.mark.parametrize('value', ["ab", "abc"]) def test_string_max_length_invalid(self, value, validator_factory): spec = { 'type': 'string', @@ -604,7 +602,7 @@ def test_string_max_length_invalid(self, value, validator_factory): with pytest.raises(InvalidSchemaValue): validator_factory(schema).validate(value) - @pytest.mark.parametrize('value', [u(""), u("a")]) + @pytest.mark.parametrize('value', ['', 'a']) def test_string_max_length(self, value, validator_factory): spec = { 'type': 'string', @@ -616,7 +614,7 @@ def test_string_max_length(self, value, validator_factory): assert result is None - @pytest.mark.parametrize('value', [u("foo"), u("bar")]) + @pytest.mark.parametrize('value', ['foo', 'bar']) def test_string_pattern_invalid(self, value, validator_factory): spec = { 'type': 'string', @@ -627,7 +625,7 @@ def test_string_pattern_invalid(self, value, validator_factory): with pytest.raises(InvalidSchemaValue): validator_factory(schema).validate(value) - @pytest.mark.parametrize('value', [u("bar"), u("foobar")]) + @pytest.mark.parametrize('value', ['bar', 'foobar']) def test_string_pattern(self, value, validator_factory): spec = { 'type': 'string', @@ -720,11 +718,11 @@ def test_object_no_one_of(self, value, validator_factory): @pytest.mark.parametrize('value', [ { - 'foo': u("FOO"), + 'foo': 'FOO', }, { - 'foo': u("FOO"), - 'bar': u("BAR"), + 'foo': 'FOO', + 'bar': 'BAR', }, ]) def test_unambiguous_one_of(self, value, validator_factory): @@ -991,10 +989,10 @@ def test_list_unique_items_invalid(self, value, validator_factory): 'someint': 123, }, { - 'somestr': u('content'), + 'somestr': 'content', }, { - 'somestr': u('content'), + 'somestr': 'content', 'someint': 123, }, ]) diff --git a/tests/unit/validation/test_request_shortcuts.py b/tests/unit/validation/test_request_shortcuts.py index 52d505b6..6e4de32c 100644 --- a/tests/unit/validation/test_request_shortcuts.py +++ b/tests/unit/validation/test_request_shortcuts.py @@ -1,4 +1,4 @@ -import mock +from unittest import mock import pytest diff --git a/tests/unit/validation/test_response_shortcuts.py b/tests/unit/validation/test_response_shortcuts.py index 0e3c0811..bcc47225 100644 --- a/tests/unit/validation/test_response_shortcuts.py +++ b/tests/unit/validation/test_response_shortcuts.py @@ -1,4 +1,4 @@ -import mock +from unittest import mock import pytest