schemathesis 4.0.6__py3-none-any.whl → 4.0.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,6 +4,9 @@ import re
4
4
  from functools import lru_cache
5
5
  from typing import TYPE_CHECKING, Any, BinaryIO, TextIO
6
6
 
7
+ from schemathesis.core import media_types
8
+ from schemathesis.core.transport import Response
9
+
7
10
  if TYPE_CHECKING:
8
11
  import yaml
9
12
 
@@ -63,3 +66,14 @@ def deserialize_yaml(stream: str | bytes | TextIO | BinaryIO) -> Any:
63
66
  import yaml
64
67
 
65
68
  return yaml.load(stream, get_yaml_loader())
69
+
70
+
71
+ def deserialize_response(response: Response, content_type: str) -> Any:
72
+ if media_types.is_yaml(content_type):
73
+ encoding = response.encoding or "utf-8"
74
+ return deserialize_yaml(response.content.decode(encoding))
75
+ if media_types.is_json(content_type):
76
+ return response.json()
77
+ raise NotImplementedError(
78
+ f"Unsupported Content-Type: {content_type!r}. Supported types are: application/yaml, application/json."
79
+ )
@@ -55,7 +55,7 @@ def is_json(value: str) -> bool:
55
55
 
56
56
  def is_yaml(value: str) -> bool:
57
57
  """Detect whether the content type is YAML-compatible."""
58
- return value in ("text/yaml", "text/x-yaml", "application/x-yaml", "text/vnd.yaml")
58
+ return value in ("text/yaml", "text/x-yaml", "application/x-yaml", "text/vnd.yaml", "application/yaml")
59
59
 
60
60
 
61
61
  def is_plain_text(value: str) -> bool:
@@ -29,7 +29,7 @@ from requests.exceptions import InvalidHeader
29
29
  from requests.structures import CaseInsensitiveDict
30
30
  from requests.utils import check_header_validity
31
31
 
32
- from schemathesis.core import NOT_SET, NotSet, Specification, media_types
32
+ from schemathesis.core import NOT_SET, NotSet, Specification, deserialization, media_types
33
33
  from schemathesis.core.compat import RefResolutionError
34
34
  from schemathesis.core.errors import InternalError, InvalidSchema, LoaderError, LoaderErrorKind, OperationNotFound
35
35
  from schemathesis.core.failures import Failure, FailureGroup, MalformedJson
@@ -617,17 +617,30 @@ class BaseOpenAPISchema(BaseSchema):
617
617
  formatted_content_types = [f"\n- `{content_type}`" for content_type in all_media_types]
618
618
  message = f"The following media types are documented in the schema:{''.join(formatted_content_types)}"
619
619
  failures.append(MissingContentType(operation=operation.label, message=message, media_types=all_media_types))
620
- content_type = None
620
+ # Default content type
621
+ content_type = "application/json"
621
622
  else:
622
623
  content_type = content_types[0]
623
- if content_type and not media_types.is_json(content_type):
624
- _maybe_raise_one_or_more(failures)
625
- return None
626
624
  try:
627
- data = response.json()
625
+ data = deserialization.deserialize_response(response, content_type)
628
626
  except JSONDecodeError as exc:
629
627
  failures.append(MalformedJson.from_exception(operation=operation.label, exc=exc))
630
628
  _maybe_raise_one_or_more(failures)
629
+ return None
630
+ except NotImplementedError:
631
+ # If the content type is not supported, we cannot validate it
632
+ _maybe_raise_one_or_more(failures)
633
+ return None
634
+ except Exception as exc:
635
+ failures.append(
636
+ Failure(
637
+ operation=operation.label,
638
+ title="Content deserialization error",
639
+ message=f"Failed to deserialize response content:\n\n {exc}",
640
+ )
641
+ )
642
+ _maybe_raise_one_or_more(failures)
643
+ return None
631
644
  with self._validating_response(scopes) as resolver:
632
645
  try:
633
646
  jsonschema.validate(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: schemathesis
3
- Version: 4.0.6
3
+ Version: 4.0.7
4
4
  Summary: Property-based testing framework for Open API and GraphQL based apps
5
5
  Project-URL: Documentation, https://schemathesis.readthedocs.io/en/stable/
6
6
  Project-URL: Changelog, https://github.com/schemathesis/schemathesis/blob/master/CHANGELOG.md
@@ -50,7 +50,7 @@ schemathesis/core/__init__.py,sha256=j862XBH5dXhxsrDg9mE7n4cSSfol0EHdY0ru1d27tCc
50
50
  schemathesis/core/compat.py,sha256=9BWCrFoqN2sJIaiht_anxe8kLjYMR7t0iiOkXqLRUZ8,1058
51
51
  schemathesis/core/control.py,sha256=IzwIc8HIAEMtZWW0Q0iXI7T1niBpjvcLlbuwOSmy5O8,130
52
52
  schemathesis/core/curl.py,sha256=yuaCe_zHLGwUjEeloQi6W3tOA3cGdnHDNI17-5jia0o,1723
53
- schemathesis/core/deserialization.py,sha256=ygIj4fNaOd0mJ2IvTsn6bsabBt_2AbSLCz-z9UqfpdQ,2406
53
+ schemathesis/core/deserialization.py,sha256=qjXUPaz_mc1OSgXzTUSkC8tuVR8wgVQtb9g3CcAF6D0,2951
54
54
  schemathesis/core/errors.py,sha256=KuFLy5ZOGn8KlD4ai5HK_WFlB3fJ2rSKwV1yD4fn4BU,16295
55
55
  schemathesis/core/failures.py,sha256=MYyRnom-XeUEuBmq2ffdz34xhxmpSHWaQunfHtliVsY,8932
56
56
  schemathesis/core/fs.py,sha256=ItQT0_cVwjDdJX9IiI7EnU75NI2H3_DCEyyUjzg_BgI,472
@@ -58,7 +58,7 @@ schemathesis/core/hooks.py,sha256=qhbkkRSf8URJ4LKv2wmKRINKpquUOgxQzWBHKWRWo3Q,47
58
58
  schemathesis/core/lazy_import.py,sha256=aMhWYgbU2JOltyWBb32vnWBb6kykOghucEzI_F70yVE,470
59
59
  schemathesis/core/loaders.py,sha256=SQQ-8m64-D2FaOgvwKZLyTtLJuzP3RPo7Ud2BERK1c0,3404
60
60
  schemathesis/core/marks.py,sha256=SH7jsVuNRJjx2gZN9Ze5MY01u7FJiHeO0iruzKi5rm4,2135
61
- schemathesis/core/media_types.py,sha256=vV0CEu34sDoZWXvu4R1Y1HosxVS4YXZV8iTov8fU3X0,2148
61
+ schemathesis/core/media_types.py,sha256=ThdAikBttdRD1RB9-83rMmtG_z-BdW8xidUxzhgdUqI,2168
62
62
  schemathesis/core/rate_limit.py,sha256=7tg9Znk11erTfw8-ANutjEmu7hbfUHZx_iEdkoaP174,1757
63
63
  schemathesis/core/registries.py,sha256=T4jZB4y3zBHdeSgQc0pRbgSeMblvO-6z4I3zmzIfTi0,811
64
64
  schemathesis/core/result.py,sha256=d449YvyONjqjDs-A5DAPgtAI96iT753K8sU6_1HLo2Q,461
@@ -134,7 +134,7 @@ schemathesis/specs/openapi/media_types.py,sha256=F5M6TKl0s6Z5X8mZpPsWDEdPBvxclKR
134
134
  schemathesis/specs/openapi/parameters.py,sha256=BevME4DWLQ-OFvc_7fREMjj99VAbVNxVb5i8OEX6Pfs,14453
135
135
  schemathesis/specs/openapi/patterns.py,sha256=cBj8W4wn7VLJd4nABaIH5f502-zBDiqljxLgPWUn-50,15609
136
136
  schemathesis/specs/openapi/references.py,sha256=40YcDExPLR2B8EOwt-Csw-5MYFi2xj_DXf91J0Pc9d4,8855
137
- schemathesis/specs/openapi/schemas.py,sha256=TIKj9dnCHkBdBofgt0UH4fMByklv5ijy-JAc8i9_D5Y,51415
137
+ schemathesis/specs/openapi/schemas.py,sha256=4bL-nOFOykfOGHbkmUor9MnCqhAzW5S5oIQbL36wvVc,51972
138
138
  schemathesis/specs/openapi/security.py,sha256=6UWYMhL-dPtkTineqqBFNKca1i4EuoTduw-EOLeE0aQ,7149
139
139
  schemathesis/specs/openapi/serialization.py,sha256=VdDLmeHqxlWM4cxQQcCkvrU6XurivolwEEaT13ohelA,11972
140
140
  schemathesis/specs/openapi/utils.py,sha256=ER4vJkdFVDIE7aKyxyYatuuHVRNutytezgE52pqZNE8,900
@@ -157,8 +157,8 @@ schemathesis/transport/prepare.py,sha256=iiB8KTAqnnuqjWzblIPiGVdkGIF7Yr1SAEz-KZz
157
157
  schemathesis/transport/requests.py,sha256=rziZTrZCVMAqgy6ldB8iTwhkpAsnjKSgK8hj5Sq3ThE,10656
158
158
  schemathesis/transport/serialization.py,sha256=igUXKZ_VJ9gV7P0TUc5PDQBJXl_s0kK9T3ljGWWvo6E,10339
159
159
  schemathesis/transport/wsgi.py,sha256=KoAfvu6RJtzyj24VGB8e-Iaa9smpgXJ3VsM8EgAz2tc,6152
160
- schemathesis-4.0.6.dist-info/METADATA,sha256=qhqeHLsnB9ltBzTHOeqyd1aZElO-XGs2HTMs_2PYA6k,8471
161
- schemathesis-4.0.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
162
- schemathesis-4.0.6.dist-info/entry_points.txt,sha256=hiK3un-xfgPdwj9uj16YVDtTNpO128bmk0U82SMv8ZQ,152
163
- schemathesis-4.0.6.dist-info/licenses/LICENSE,sha256=2Ve4J8v5jMQAWrT7r1nf3bI8Vflk3rZVQefiF2zpxwg,1121
164
- schemathesis-4.0.6.dist-info/RECORD,,
160
+ schemathesis-4.0.7.dist-info/METADATA,sha256=FwIP6I23WtilfbZgzNA4ZSs8FnGWexKmi08G1m5h8Co,8471
161
+ schemathesis-4.0.7.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
162
+ schemathesis-4.0.7.dist-info/entry_points.txt,sha256=hiK3un-xfgPdwj9uj16YVDtTNpO128bmk0U82SMv8ZQ,152
163
+ schemathesis-4.0.7.dist-info/licenses/LICENSE,sha256=2Ve4J8v5jMQAWrT7r1nf3bI8Vflk3rZVQefiF2zpxwg,1121
164
+ schemathesis-4.0.7.dist-info/RECORD,,