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

chore: splitting and improving tests, enabling codecov failure #38

Merged
merged 2 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,5 @@ jobs:
- uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
fail_ci_if_error: true
danut-t marked this conversation as resolved.
Show resolved Hide resolved
fail_ci_if_error: false
token: ${{ secrets.CODECOV_TOKEN }}
18 changes: 11 additions & 7 deletions openapi_tester/schema_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@
UrlStaticSchemaLoader,
)
from openapi_tester.response_handler_factory import ResponseHandlerFactory
from openapi_tester.utils import lazy_combinations, normalize_schema_section
from openapi_tester.utils import (
lazy_combinations,
normalize_schema_section,
serialize_schema_section_data,
)
from openapi_tester.validators import (
validate_enum,
validate_format,
Expand Down Expand Up @@ -554,8 +558,8 @@ def test_openapi_object(
f"{VALIDATE_MISSING_KEY_ERROR.format(missing_key=key, http_message=test_config.http_message)}"
"\n\nReference:"
f"\n\n{test_config.reference} > {key}"
f"\n\n{test_config.http_message.capitalize()} body:\n {json.dumps(data, indent=4)}"
f"\nSchema section:\n {json.dumps(properties, indent=4)}"
f"\n\n{test_config.http_message.capitalize()} body:\n {serialize_schema_section_data(data=data)}"
f"\nSchema section:\n {serialize_schema_section_data(data=properties)}"
"\n\nHint: Remove the key from your OpenAPI docs, or"
f" include it in your API {test_config.http_message}"
)
Expand All @@ -566,17 +570,17 @@ def test_openapi_object(
f"{VALIDATE_EXCESS_KEY_ERROR.format(excess_key=key, http_message=test_config.http_message)}"
"\n\nReference:"
f"\n\n{test_config.reference} > {key}"
f"\n\n{test_config.http_message.capitalize()} body:\n {json.dumps(data, indent=4)}"
f"\n\nSchema section:\n {json.dumps(properties, indent=4, default=str)}"
f"\n\n{test_config.http_message.capitalize()} body:\n {serialize_schema_section_data(data=data)}"
f"\n\nSchema section:\n {serialize_schema_section_data(data=properties)}"
"\n\nHint: Remove the key from your API"
f" {test_config.http_message}, or include it in your OpenAPI docs"
)
if key in write_only_properties:
raise DocumentationError(
f"{VALIDATE_WRITE_ONLY_RESPONSE_KEY_ERROR.format(write_only_key=key)}\n\nReference:"
f"\n\n{test_config.reference} > {key}"
f"\n\n{test_config.http_message.capitalize()} body:\n {json.dumps(data, indent=4)}"
f"\nSchema section:\n {json.dumps(properties, indent=4)}"
f"\n\n{test_config.http_message.capitalize()} body:\n {serialize_schema_section_data(data=data)}"
f"\nSchema section:\n {serialize_schema_section_data(data=properties)}"
f"\n\nHint: Remove the key from your API {test_config.http_message}, or"
' remove the "WriteOnly" restriction'
)
Expand Down
5 changes: 5 additions & 0 deletions openapi_tester/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from __future__ import annotations

import json
from copy import deepcopy
from itertools import chain, combinations
from typing import TYPE_CHECKING
Expand Down Expand Up @@ -55,6 +56,10 @@ def normalize_schema_section(schema_section: dict[str, Any]) -> dict[str, Any]:
return output


def serialize_schema_section_data(data: dict[str, Any]) -> str:
return json.dumps(data, indent=4, default=str)


def lazy_combinations(options_list: Sequence[dict[str, Any]]) -> Iterator[dict]:
"""
Lazily evaluate possible combinations.
Expand Down
278 changes: 0 additions & 278 deletions tests/test_errors.py

This file was deleted.

Loading
Loading