Skip to content

Commit

Permalink
schemathesis tests: Cleanup after openapi fixes
Browse files Browse the repository at this point in the history
Change-Id: Idead524bc3c4715a93d6a48b682d09cc50c89c82
  • Loading branch information
rene-slowenski-checkmk committed Nov 3, 2023
1 parent 1ac38ae commit 3f3923f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 87 deletions.
97 changes: 22 additions & 75 deletions tests/schemathesis_openapi/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,33 +37,26 @@ def hook_before_load_schema( # pylint: disable=too-many-branches

# SCHEMA modifications
require_properties(raw_schema, "InputRuleObject", ["raw_value", "conditions"], "CMK-TODO")
require_properties(raw_schema, "LicenseSettings", ["settings"], "CMK-14100")

require_properties(raw_schema, "UpdateContactGroup", ["attributes"], "CMK-14291")
require_properties(raw_schema, "UpdateHostGroup", ["attributes"], "CMK-14291")
require_properties(raw_schema, "UpdateServiceGroup", ["attributes"], "CMK-14291")

require_properties(raw_schema, "CheckboxWithStrValue", ["state"], "CMK-TODO", merge=False)
require_properties(
raw_schema, "NotificationBulkingCheckbox", ["state"], "CMK-TODO", merge=False
)

update_property(raw_schema, "BulkDeleteHost", "entries", {"minItems": 1}, "CMK-14259")

update_property(
raw_schema,
"TimeAllowedRange",
"start",
{"pattern": "^\\d\\d:\\d\\d(:\\d\\d)?$"},
"CMK-14314",
"HostOrServiceCondition",
"match_on",
{"items": {"type": "string", "minLength": 1}},
"CMK-15035",
)
update_property(
raw_schema,
"TimeAllowedRange",
"end",
{"pattern": "^\\d\\d:\\d\\d(:\\d\\d)?$"},
"CMK-14314",
require_properties(raw_schema, "HostOrServiceCondition", ["operator", "match_on"], "CMK-15035")
require_properties(
raw_schema, "TagConditionScalarSchemaBase", ["key", "operator", "value"], "CMK-15035"
)
require_properties(
raw_schema, "TagConditionConditionSchemaBase", ["key", "operator", "value"], "CMK-15035"
)
require_properties(raw_schema, "LabelCondition", ["operator"], "CMK-15035")

# NOTE: CMK-12182 is mostly done, but fixing InputPassword was apparently overlooked
update_property(
Expand All @@ -74,14 +67,6 @@ def hook_before_load_schema( # pylint: disable=too-many-branches
"CMK-12182",
)

update_property(
raw_schema,
"InputHostTagGroup",
"ident",
{"pattern": "^[a-zA-Z_]+[-0-9a-zA-Z_]$"},
"CMK-14263",
)

update_property(
raw_schema,
"HostExtensionsEffectiveAttributes",
Expand All @@ -97,28 +82,6 @@ def hook_before_load_schema( # pylint: disable=too-many-branches
"CMK-TODO",
)

update_property(
raw_schema,
"HostExtensions",
"effective_attributes",
{"nullable": True},
"CMK-14110",
)
update_property(
raw_schema,
"NetworkScanResult",
"start",
{"nullable": True},
"CMK-14261",
)
update_property(
raw_schema,
"NetworkScanResult",
"end",
{"nullable": True},
"CMK-14261",
)

update_property(
raw_schema,
"CreateFolder",
Expand Down Expand Up @@ -269,10 +232,6 @@ def hook_before_load_schema( # pylint: disable=too-many-branches
path,
)
responses.update(problem_response("404", "Not found"))
if "CMK-12421" in settings.suppressed_issues:
paths["/domain-types/activation_run/actions/activate-changes/invoke"]["post"][
"responses"
].update(problem_response("204", "No Content"))

# ignore some endpoints (via deprecating them) to avoid failures during parametrization
for path, methods in {
Expand Down Expand Up @@ -332,7 +291,6 @@ def hook_after_call( # pylint: disable=too-many-branches
valid_body=False,
body={},
set_body={"links": []},
ticket_id="CMK-14101",
)
else:
fix_response(
Expand All @@ -348,15 +306,6 @@ def hook_after_call( # pylint: disable=too-many-branches
},
ticket_id="INVALID-JSON",
)
fix_response(
case,
response,
method="GET",
path="/domain-types/audit_log/collections/all",
status_code=200,
set_body={"links": []},
ticket_id="CMK-14403",
)

# generic: empty response Content-Type
fix_response(
Expand Down Expand Up @@ -414,19 +363,6 @@ def hook_after_call( # pylint: disable=too-many-branches
)

# invalid status: 500 instead of 400
fix_response(
case,
response,
method="POST|PUT",
path="/objects/bi_aggregation/{aggregation_id}",
status_code=500,
traceback=".*\nKeyError:.*",
valid_body=True,
set_status_code=400,
update_headers={"Content-Type": "{problem}"},
set_body={"title": "Bad Request", "status": 400, "detail": "Bad Request"},
ticket_id="CMK-14416",
)
fix_response(
case,
response,
Expand Down Expand Up @@ -485,5 +421,16 @@ def hook_after_call( # pylint: disable=too-many-branches
)

# invalid status: 500 instead of 404
fix_response(
case,
response,
method="DELETE",
path="/objects/bi_pack/{pack_id}",
status_code=500,
body={"detail": "The requested pack_id does not exist"},
set_status_code=400,
update_body={"title": "Bad Request", "status": 404},
ticket_id="CMK-14991",
)

# invalid status: 500 instead of 409
14 changes: 2 additions & 12 deletions tests/schemathesis_openapi/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,15 @@
suppressed_issues.update(
{
"CMK-12182", # mostly done, but fixing InputPassword was apparently overlooked
# "CMK-12421", # NOTE: problem with redirects in Schemathesis, need to investigate!
"CMK-13216",
"CMK-14100",
"CMK-14101",
"CMK-14110",
"CMK-14259",
"CMK-14261",
"CMK-14263",
"CMK-14273",
"CMK-14291",
"CMK-14314", # follow-up of CMK-12235
"CMK-14366", # follow-up of CMK-12261
# "CMK-14375",
# "CMK-14375.1",
# "CMK-14375.2",
"CMK-14381",
"CMK-14403",
"CMK-14416",
"CMK-TODO",
"CMK-14991",
"CMK-15035",
}
)
for issue in set(getenv("TEST_OPENAPI_ALLOW", "").upper().split(",")):
Expand Down

0 comments on commit 3f3923f

Please sign in to comment.