tests: update the tests for OP#12 (validate schema -> schema) and finalize the required openapi.json#56
Conversation
…alized the required openapi.json Signed-off-by: Artifizer <artifizer@gmail.com>
|
Important Review skippedReview was skipped as selected files did not have any reviewable changes. 💤 Files selected but had no reviewable changes (1)
You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughTwo new API endpoints are introduced for validation operations: Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~28 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
tests/test_op12_schema_vs_schema_validation.py (1)
1572-1582:⚠️ Potential issue | 🟠 Major
/validate-entitypayload usesgts_idinstead ofentity_id.This request likely won’t match the new ValidateEntityRequest contract (and is inconsistent with other tests). It should send
entity_id.✅ Fix request field name
- .with_json({ - "gts_id": ( + .with_json({ + "entity_id": ( "gts.x.test12.badcascade.field.v1~" "x.test12._.medium.v1~x.test12._.bad_large.v1~" ) })🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/test_op12_schema_vs_schema_validation.py` around lines 1572 - 1582, Test payload for the "/validate-entity" request is using "gts_id" instead of the expected "entity_id"; update the RunRequest call in the test "validate level 3 schema should fail" so the JSON body uses "entity_id" key (matching the ValidateEntityRequest contract and other tests), i.e., replace the "gts_id" field with "entity_id" in the .with_json({...}) for the RunRequest to ensure the request matches the validator.
🧹 Nitpick comments (2)
tests/openapi.json (1)
492-545: Define response schemas for/validate-schemaand/validate-entity.Tests assert
body.okandbody.entity_type, but the OpenAPI responses are generic objects. Consider adding explicit response schemas so the spec matches observed behavior.📘 Suggested schema additions
"/validate-schema": { "post": { ... "responses": { "200": { "description": "Successful Response", "content": { "application/json": { "schema": { - "type": "object", - "title": "Response Validate Schema Validate Schema Post" + "$ref": "#/components/schemas/ValidateSchemaResponse" } } } }, ... "/validate-entity": { "post": { ... "responses": { "200": { "description": "Successful Response", "content": { "application/json": { "schema": { - "type": "object", - "title": "Response Validate Entity Validate Entity Post" + "$ref": "#/components/schemas/ValidateEntityResponse" } } } }, ... "components": { "schemas": { + "ValidateSchemaResponse": { + "type": "object", + "required": ["ok"], + "properties": { + "ok": { "type": "boolean" } + }, + "title": "ValidateSchemaResponse" + }, + "ValidateEntityResponse": { + "type": "object", + "required": ["ok", "entity_type"], + "properties": { + "ok": { "type": "boolean" }, + "entity_type": { + "type": "string", + "enum": ["schema", "instance"] + } + }, + "title": "ValidateEntityResponse" + }, "ValidateSchemaRequest": { ... }, "ValidateEntityRequest": { ... }Also applies to: 536-545, 850-875
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/openapi.json` around lines 492 - 545, The OpenAPI responses for the POST endpoints "/validate-schema" (operationId: validate_schema_validate_schema_post) and "/validate-entity" (operationId: validate_entity_validate_entity_post) use generic object schemas but tests expect fields like body.ok and body.entity_type; update the spec by adding explicit response schemas under components/schemas (e.g., ValidateSchemaResponse and ValidateEntityResponse) and reference them in the "200" response for each operation so the response schema includes the required properties (ok: boolean, entity_type: string, plus any other fields the handlers return). Ensure the new schema names are referenced from the "responses" -> "200" -> "content" -> "application/json" -> "schema" for both endpoints and adjust titles if needed.tests/test_op12_schema_vs_schema_validation.py (1)
229-290: Annotate class-levelteststepsasClassVarto satisfy RUF012.Ruff flags mutable class attributes; consider annotating
teststepsasClassVar(or moving to instance scope). This pattern repeats across the new test classes.♻️ Example adjustment
+from typing import ClassVar + class TestCaseTestOp12SchemaValidation_CloseOpenModel(HttpRunner): ... - teststeps = [ + teststeps: ClassVar[list[Step]] = [ Step( RunRequest("register open base schema") ...🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/test_op12_schema_vs_schema_validation.py` around lines 229 - 290, The class-level mutable variable teststeps should be annotated as typing.ClassVar to satisfy RUF012; update the test classes that define teststeps (the variable named teststeps in the shown test class and the other new test classes) to import ClassVar from typing and change the definition to something like: teststeps: ClassVar[list[Step]] = [...] (or use typing.List[Step] if needed for your Python version), or alternatively move the teststeps definition into instance scope (e.g., setUp) if you prefer not to use ClassVar.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@tests/test_op12_schema_vs_schema_validation.py`:
- Around line 1572-1582: Test payload for the "/validate-entity" request is
using "gts_id" instead of the expected "entity_id"; update the RunRequest call
in the test "validate level 3 schema should fail" so the JSON body uses
"entity_id" key (matching the ValidateEntityRequest contract and other tests),
i.e., replace the "gts_id" field with "entity_id" in the .with_json({...}) for
the RunRequest to ensure the request matches the validator.
---
Nitpick comments:
In `@tests/openapi.json`:
- Around line 492-545: The OpenAPI responses for the POST endpoints
"/validate-schema" (operationId: validate_schema_validate_schema_post) and
"/validate-entity" (operationId: validate_entity_validate_entity_post) use
generic object schemas but tests expect fields like body.ok and
body.entity_type; update the spec by adding explicit response schemas under
components/schemas (e.g., ValidateSchemaResponse and ValidateEntityResponse) and
reference them in the "200" response for each operation so the response schema
includes the required properties (ok: boolean, entity_type: string, plus any
other fields the handlers return). Ensure the new schema names are referenced
from the "responses" -> "200" -> "content" -> "application/json" -> "schema" for
both endpoints and adjust titles if needed.
In `@tests/test_op12_schema_vs_schema_validation.py`:
- Around line 229-290: The class-level mutable variable teststeps should be
annotated as typing.ClassVar to satisfy RUF012; update the test classes that
define teststeps (the variable named teststeps in the shown test class and the
other new test classes) to import ClassVar from typing and change the definition
to something like: teststeps: ClassVar[list[Step]] = [...] (or use
typing.List[Step] if needed for your Python version), or alternatively move the
teststeps definition into instance scope (e.g., setUp) if you prefer not to use
ClassVar.
Signed-off-by: Artifizer <artifizer@gmail.com>
Summary by CodeRabbit
New Features
/validate-schemaPOST endpoint to validate schemas with a required schema ID parameter/validate-entityPOST endpoint to validate entities with a required entity ID parameterTests