forked from snok/drf-openapi-tester
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: splitting and improving tests
- Loading branch information
Matias Cardenas
committed
May 4, 2024
1 parent
750743b
commit 7f2a582
Showing
3 changed files
with
269 additions
and
264 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import pytest | ||
|
||
from openapi_tester import SchemaTester | ||
from openapi_tester.config import OpenAPITestConfig | ||
from openapi_tester.exceptions import DocumentationError | ||
|
||
|
||
def test_missing_response_key_error(): | ||
expected_error_message = ( | ||
'The following property was found in the schema definition, but is missing from the response data: "one"' | ||
"\n\nReference:\n\nPOST /endpoint > response > one" | ||
'\n\nResponse body:\n {\n "two": 2\n}' | ||
'\nSchema section:\n {\n "one": {\n "type": "int"\n }\n}' | ||
"\n\nHint: Remove the key from your OpenAPI docs, or include it in your API response" | ||
) | ||
tester = SchemaTester() | ||
with pytest.raises(DocumentationError, match=expected_error_message): | ||
tester.test_openapi_object( | ||
{"required": ["one"], "properties": {"one": {"type": "int"}}}, | ||
{"two": 2}, | ||
OpenAPITestConfig(reference="POST /endpoint > response"), | ||
) | ||
|
||
|
||
def test_missing_schema_key_error(): | ||
expected_error_message = ( | ||
'The following property was found in the response data, but is missing from the schema definition: "two"' | ||
"\n\nReference:" | ||
"\n\nPOST /endpoint > response > two" | ||
'\n\nResponse body:\n {\n "one": 1,\n "two": 2\n}' | ||
'\n\nSchema section:\n {\n "one": {\n "type": "int"\n }\n}' | ||
"\n\nHint: Remove the key from your API response, or include it in your OpenAPI docs" | ||
) | ||
tester = SchemaTester() | ||
with pytest.raises(DocumentationError, match=expected_error_message): | ||
tester.test_openapi_object( | ||
{"required": ["one"], "properties": {"one": {"type": "int"}}}, | ||
{"one": 1, "two": 2}, | ||
OpenAPITestConfig(reference="POST /endpoint > response"), | ||
) | ||
|
||
|
||
def test_key_in_write_only_properties_error(): | ||
expected_error_message = ( | ||
'The following property was found in the response, but is documented as being "writeOnly": "one"' | ||
"\n\nReference:" | ||
"\n\nPOST /endpoint > response > one" | ||
'\n\nResponse body:\n {\n "one": 1\n}' | ||
'\nSchema section:\n {\n "one": {\n "type": "int",\n "writeOnly": true\n }\n}' | ||
'\n\nHint: Remove the key from your API response, or remove the "WriteOnly" restriction' | ||
) | ||
tester = SchemaTester() | ||
with pytest.raises(DocumentationError, match=expected_error_message): | ||
tester.test_openapi_object( | ||
{"properties": {"one": {"type": "int", "writeOnly": True}}}, | ||
{"one": 1}, | ||
OpenAPITestConfig(reference="POST /endpoint > response"), | ||
) |
Oops, something went wrong.