attr errors hashable fix

This commit is contained in:
Artur Maciag 2019-06-18 12:39:07 +01:00
parent 78ede74825
commit c9b2d8c4f8
15 changed files with 50 additions and 46 deletions

View file

@ -1,13 +1,13 @@
from openapi_core.schema.exceptions import OpenAPIMappingError
import attr import attr
from openapi_core.schema.exceptions import OpenAPIMappingError
class OpenAPIContentError(OpenAPIMappingError): class OpenAPIContentError(OpenAPIMappingError):
pass pass
@attr.s @attr.s(hash=True)
class MimeTypeNotFound(OpenAPIContentError): class MimeTypeNotFound(OpenAPIContentError):
mimetype = attr.ib() mimetype = attr.ib()
availableMimetypes = attr.ib() availableMimetypes = attr.ib()

View file

@ -18,4 +18,4 @@ class Content(dict):
if fnmatch.fnmatch(mimetype, key): if fnmatch.fnmatch(mimetype, key):
return value return value
raise MimeTypeNotFound(mimetype, self.keys()) raise MimeTypeNotFound(mimetype, list(self.keys()))

View file

@ -1,19 +1,21 @@
from openapi_core.schema.exceptions import OpenAPIMappingError
import attr import attr
from openapi_core.schema.exceptions import OpenAPIMappingError
class OpenAPIMediaTypeError(OpenAPIMappingError): class OpenAPIMediaTypeError(OpenAPIMappingError):
pass pass
@attr.s
@attr.s(hash=True)
class InvalidMediaTypeValue(OpenAPIMediaTypeError): class InvalidMediaTypeValue(OpenAPIMediaTypeError):
original_exception = attr.ib() original_exception = attr.ib()
def __str__(self): def __str__(self):
return "Mimetype invalid: {0}".format(self.original_exception) return "Mimetype invalid: {0}".format(self.original_exception)
@attr.s
@attr.s(hash=True)
class InvalidContentType(OpenAPIMediaTypeError): class InvalidContentType(OpenAPIMediaTypeError):
mimetype = attr.ib() mimetype = attr.ib()

View file

@ -1,13 +1,13 @@
from openapi_core.schema.exceptions import OpenAPIMappingError
import attr import attr
from openapi_core.schema.exceptions import OpenAPIMappingError
class OpenAPIOperationError(OpenAPIMappingError): class OpenAPIOperationError(OpenAPIMappingError):
pass pass
@attr.s @attr.s(hash=True)
class InvalidOperation(OpenAPIOperationError): class InvalidOperation(OpenAPIOperationError):
path_pattern = attr.ib() path_pattern = attr.ib()
http_method = attr.ib() http_method = attr.ib()

View file

@ -1,13 +1,13 @@
from openapi_core.schema.exceptions import OpenAPIMappingError
import attr import attr
from openapi_core.schema.exceptions import OpenAPIMappingError
class OpenAPIParameterError(OpenAPIMappingError): class OpenAPIParameterError(OpenAPIMappingError):
pass pass
@attr.s @attr.s(hash=True)
class MissingParameter(OpenAPIParameterError): class MissingParameter(OpenAPIParameterError):
name = attr.ib() name = attr.ib()
@ -15,7 +15,7 @@ class MissingParameter(OpenAPIParameterError):
return "Missing parameter (without default value): {0}".format(self.name) return "Missing parameter (without default value): {0}".format(self.name)
@attr.s @attr.s(hash=True)
class MissingRequiredParameter(OpenAPIParameterError): class MissingRequiredParameter(OpenAPIParameterError):
name = attr.ib() name = attr.ib()
@ -23,7 +23,7 @@ class MissingRequiredParameter(OpenAPIParameterError):
return "Missing required parameter: {0}".format(self.name) return "Missing required parameter: {0}".format(self.name)
@attr.s @attr.s(hash=True)
class EmptyParameterValue(OpenAPIParameterError): class EmptyParameterValue(OpenAPIParameterError):
name = attr.ib() name = attr.ib()
@ -31,7 +31,7 @@ class EmptyParameterValue(OpenAPIParameterError):
return "Value of parameter cannot be empty: {0}".format(self.name) return "Value of parameter cannot be empty: {0}".format(self.name)
@attr.s @attr.s(hash=True)
class InvalidParameterValue(OpenAPIParameterError): class InvalidParameterValue(OpenAPIParameterError):
name = attr.ib() name = attr.ib()
original_exception = attr.ib() original_exception = attr.ib()

View file

@ -1,13 +1,13 @@
from openapi_core.schema.exceptions import OpenAPIMappingError
import attr import attr
from openapi_core.schema.exceptions import OpenAPIMappingError
class OpenAPIRequestBodyError(OpenAPIMappingError): class OpenAPIRequestBodyError(OpenAPIMappingError):
pass pass
@attr.s @attr.s(hash=True)
class MissingRequestBody(OpenAPIRequestBodyError): class MissingRequestBody(OpenAPIRequestBodyError):
request = attr.ib() request = attr.ib()

View file

@ -1,13 +1,13 @@
from openapi_core.schema.exceptions import OpenAPIMappingError
import attr import attr
from openapi_core.schema.exceptions import OpenAPIMappingError
class OpenAPIResponseError(OpenAPIMappingError): class OpenAPIResponseError(OpenAPIMappingError):
pass pass
@attr.s @attr.s(hash=True)
class InvalidResponse(OpenAPIResponseError): class InvalidResponse(OpenAPIResponseError):
http_status = attr.ib() http_status = attr.ib()
responses = attr.ib() responses = attr.ib()
@ -16,7 +16,7 @@ class InvalidResponse(OpenAPIResponseError):
return "Unknown response http status: {0}".format(str(self.http_status)) return "Unknown response http status: {0}".format(str(self.http_status))
@attr.s @attr.s(hash=True)
class MissingResponseContent(OpenAPIResponseError): class MissingResponseContent(OpenAPIResponseError):
response = attr.ib() response = attr.ib()

View file

@ -1,13 +1,13 @@
from openapi_core.schema.exceptions import OpenAPIMappingError
import attr import attr
from openapi_core.schema.exceptions import OpenAPIMappingError
class OpenAPISchemaError(OpenAPIMappingError): class OpenAPISchemaError(OpenAPIMappingError):
pass pass
@attr.s @attr.s(hash=True)
class NoValidSchema(OpenAPISchemaError): class NoValidSchema(OpenAPISchemaError):
value = attr.ib() value = attr.ib()
@ -15,7 +15,7 @@ class NoValidSchema(OpenAPISchemaError):
return "No valid schema found for value: {0}".format(self.value) return "No valid schema found for value: {0}".format(self.value)
@attr.s @attr.s(hash=True)
class UndefinedItemsSchema(OpenAPISchemaError): class UndefinedItemsSchema(OpenAPISchemaError):
type = attr.ib() type = attr.ib()
@ -23,7 +23,7 @@ class UndefinedItemsSchema(OpenAPISchemaError):
return "Null value for schema type {0}".format(self.type) return "Null value for schema type {0}".format(self.type)
@attr.s @attr.s(hash=True)
class InvalidSchemaValue(OpenAPISchemaError): class InvalidSchemaValue(OpenAPISchemaError):
msg = attr.ib() msg = attr.ib()
value = attr.ib() value = attr.ib()
@ -32,7 +32,8 @@ class InvalidSchemaValue(OpenAPISchemaError):
def __str__(self): def __str__(self):
return self.msg.format(value=self.value, type=self.type) return self.msg.format(value=self.value, type=self.type)
@attr.s
@attr.s(hash=True)
class InvalidCustomFormatSchemaValue(InvalidSchemaValue): class InvalidCustomFormatSchemaValue(InvalidSchemaValue):
original_exception = attr.ib() original_exception = attr.ib()
@ -40,14 +41,15 @@ class InvalidCustomFormatSchemaValue(InvalidSchemaValue):
return self.msg.format(value=self.value, type=self.type, exception=self.original_exception) return self.msg.format(value=self.value, type=self.type, exception=self.original_exception)
@attr.s @attr.s(hash=True)
class UndefinedSchemaProperty(OpenAPISchemaError): class UndefinedSchemaProperty(OpenAPISchemaError):
extra_props = attr.ib() extra_props = attr.ib()
def __str__(self): def __str__(self):
return "Extra unexpected properties found in schema: {0}".format(self.extra_props) return "Extra unexpected properties found in schema: {0}".format(self.extra_props)
@attr.s
@attr.s(hash=True)
class InvalidSchemaProperty(OpenAPISchemaError): class InvalidSchemaProperty(OpenAPISchemaError):
property_name = attr.ib() property_name = attr.ib()
original_exception = attr.ib() original_exception = attr.ib()
@ -55,7 +57,8 @@ class InvalidSchemaProperty(OpenAPISchemaError):
def __str__(self): def __str__(self):
return "Invalid schema property {0}: {1}".format(self.property_name, self.original_exception) return "Invalid schema property {0}: {1}".format(self.property_name, self.original_exception)
@attr.s
@attr.s(hash=True)
class MissingSchemaProperty(OpenAPISchemaError): class MissingSchemaProperty(OpenAPISchemaError):
property_name = attr.ib() property_name = attr.ib()
@ -63,7 +66,7 @@ class MissingSchemaProperty(OpenAPISchemaError):
return "Missing schema property: {0}".format(self.property_name) return "Missing schema property: {0}".format(self.property_name)
@attr.s @attr.s(hash=True)
class NoOneOfSchema(OpenAPISchemaError): class NoOneOfSchema(OpenAPISchemaError):
type = attr.ib() type = attr.ib()
@ -71,7 +74,7 @@ class NoOneOfSchema(OpenAPISchemaError):
return "Exactly one valid schema type {0} should be valid, None found.".format(self.type) return "Exactly one valid schema type {0} should be valid, None found.".format(self.type)
@attr.s @attr.s(hash=True)
class MultipleOneOfSchema(OpenAPISchemaError): class MultipleOneOfSchema(OpenAPISchemaError):
type = attr.ib() type = attr.ib()
@ -79,11 +82,10 @@ class MultipleOneOfSchema(OpenAPISchemaError):
return "Exactly one schema type {0} should be valid, more than one found".format(self.type) return "Exactly one schema type {0} should be valid, more than one found".format(self.type)
class UnmarshallerError(Exception): class UnmarshallerError(OpenAPIMappingError):
pass pass
@attr.s
class UnmarshallerStrictTypeError(UnmarshallerError): class UnmarshallerStrictTypeError(UnmarshallerError):
value = attr.ib() value = attr.ib()
types = attr.ib() types = attr.ib()

View file

@ -1,13 +1,13 @@
from openapi_core.schema.exceptions import OpenAPIMappingError
import attr import attr
from openapi_core.schema.exceptions import OpenAPIMappingError
class OpenAPIServerError(OpenAPIMappingError): class OpenAPIServerError(OpenAPIMappingError):
pass pass
@attr.s @attr.s(hash=True)
class InvalidServer(OpenAPIServerError): class InvalidServer(OpenAPIServerError):
full_url_pattern = attr.ib() full_url_pattern = attr.ib()

View file

@ -40,5 +40,5 @@ class TestLinks(object):
@pytest.mark.parametrize("request_body", request_body_list) @pytest.mark.parametrize("request_body", request_body_list)
def test_iteritems(self, link_factory, request_body, server): def test_iteritems(self, link_factory, request_body, server):
link = link_factory(request_body, server) link = link_factory(request_body, server)
for par_name in link.parameters.keys(): for par_name in link.parameters:
assert link[par_name] == link.parameters[par_name] assert link[par_name] == link.parameters[par_name]

View file

@ -15,7 +15,7 @@ class TestSchemas(object):
return Operation('get', '/path', {}, parameters=parameters) return Operation('get', '/path', {}, parameters=parameters)
def test_iteritems(self, operation): def test_iteritems(self, operation):
for name in operation.parameters.keys(): for name in operation.parameters:
assert operation[name] == operation.parameters[name] assert operation[name] == operation.parameters[name]

View file

@ -16,6 +16,6 @@ class TestPaths(object):
@property @property
def test_iteritems(self, path): def test_iteritems(self, path):
for http_method in path.operations.keys(): for http_method in path.operations:
assert path[http_method] ==\ assert path[http_method] ==\
path.operations[http_method] path.operations[http_method]

View file

@ -16,6 +16,6 @@ class TestRequestBodies(object):
@property @property
def test_iteritems(self, request_body): def test_iteritems(self, request_body):
for mimetype in request_body.content.keys(): for mimetype in request_body.content:
assert request_body[mimetype] ==\ assert request_body[mimetype] ==\
request_body.content[mimetype] request_body.content[mimetype]

View file

@ -27,7 +27,7 @@ class TestSchemaIteritems(object):
@property @property
def test_valid(self, schema): def test_valid(self, schema):
for name in schema.properties.keys(): for name in schema.properties:
assert schema[name] == schema.properties[name] assert schema[name] == schema.properties[name]

View file

@ -32,7 +32,7 @@ class TestSpecs(object):
return Spec(servers, paths) return Spec(servers, paths)
def test_iteritems(self, spec): def test_iteritems(self, spec):
for path_name in spec.paths.keys(): for path_name in spec.paths:
assert spec[path_name] ==\ assert spec[path_name] ==\
spec.paths[path_name] spec.paths[path_name]