From b89d5c0e7d41d93b2ac680650c2dfef3c9ab7b92 Mon Sep 17 00:00:00 2001 From: Oliver Sauder Date: Thu, 28 Oct 2021 22:22:20 +0400 Subject: [PATCH] Migrate to syrupy snapshot testing --- example/tests/__snapshots__/test_errors.ambr | 133 ++++ example/tests/__snapshots__/test_openapi.ambr | 669 ++++++++++++++++++ example/tests/snapshots/__init__.py | 0 example/tests/snapshots/snap_test_errors.py | 107 --- example/tests/snapshots/snap_test_openapi.py | 667 ----------------- example/tests/test_errors.py | 18 +- example/tests/test_openapi.py | 10 +- requirements/requirements-testing.txt | 2 +- 8 files changed, 817 insertions(+), 789 deletions(-) create mode 100644 example/tests/__snapshots__/test_errors.ambr create mode 100644 example/tests/__snapshots__/test_openapi.ambr delete mode 100644 example/tests/snapshots/__init__.py delete mode 100644 example/tests/snapshots/snap_test_errors.py delete mode 100644 example/tests/snapshots/snap_test_openapi.py diff --git a/example/tests/__snapshots__/test_errors.ambr b/example/tests/__snapshots__/test_errors.ambr new file mode 100644 index 00000000..d025fd4e --- /dev/null +++ b/example/tests/__snapshots__/test_errors.ambr @@ -0,0 +1,133 @@ +# name: test_first_level_attribute_error + { + 'errors': [ + { + 'code': 'required', + 'detail': 'This field is required.', + 'source': { + 'pointer': '/data/attributes/headline', + }, + 'status': '400', + }, + ], + } +--- +# name: test_first_level_custom_attribute_error + { + 'errors': [ + { + 'detail': 'Too short', + 'source': { + 'pointer': '/data/attributes/body-text', + }, + 'title': 'Too Short title', + }, + ], + } +--- +# name: test_many_third_level_dict_errors + { + 'errors': [ + { + 'code': 'required', + 'detail': 'This field is required.', + 'source': { + 'pointer': '/data/attributes/comments/0/attachment/data', + }, + 'status': '400', + }, + { + 'code': 'required', + 'detail': 'This field is required.', + 'source': { + 'pointer': '/data/attributes/comments/0/body', + }, + 'status': '400', + }, + ], + } +--- +# name: test_relationship_errors_has_correct_pointers + { + 'errors': [ + { + 'code': 'incorrect_type', + 'detail': 'Incorrect type. Expected resource identifier object, received str.', + 'source': { + 'pointer': '/data/relationships/author', + }, + 'status': '400', + }, + ], + } +--- +# name: test_second_level_array_error + { + 'errors': [ + { + 'code': 'required', + 'detail': 'This field is required.', + 'source': { + 'pointer': '/data/attributes/comments/0/body', + }, + 'status': '400', + }, + ], + } +--- +# name: test_second_level_dict_error + { + 'errors': [ + { + 'code': 'required', + 'detail': 'This field is required.', + 'source': { + 'pointer': '/data/attributes/comment/body', + }, + 'status': '400', + }, + ], + } +--- +# name: test_third_level_array_error + { + 'errors': [ + { + 'code': 'required', + 'detail': 'This field is required.', + 'source': { + 'pointer': '/data/attributes/comments/0/attachments/0/data', + }, + 'status': '400', + }, + ], + } +--- +# name: test_third_level_custom_array_error + { + 'errors': [ + { + 'code': 'invalid', + 'detail': 'Too short data', + 'source': { + 'pointer': '/data/attributes/comments/0/attachments/0/data', + }, + 'status': '400', + }, + ], + } +--- +# name: test_third_level_dict_error + { + 'errors': [ + { + 'code': 'required', + 'detail': 'This field is required.', + 'source': { + 'pointer': '/data/attributes/comments/0/attachment/data', + }, + 'status': '400', + }, + ], + } +--- diff --git a/example/tests/__snapshots__/test_openapi.ambr b/example/tests/__snapshots__/test_openapi.ambr new file mode 100644 index 00000000..28044c74 --- /dev/null +++ b/example/tests/__snapshots__/test_openapi.ambr @@ -0,0 +1,669 @@ +# name: test_delete_request + ' + { + "description": "", + "operationId": "destroy/authors/{id}", + "parameters": [ + { + "description": "A unique integer value identifying this author.", + "in": "path", + "name": "id", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/vnd.api+json": { + "schema": { + "$ref": "#/components/schemas/onlymeta" + } + } + }, + "description": "[OK](https://jsonapi.org/format/#crud-deleting-responses-200)" + }, + "202": { + "content": { + "application/vnd.api+json": { + "schema": { + "$ref": "#/components/schemas/datum" + } + } + }, + "description": "Accepted for [asynchronous processing](https://jsonapi.org/recommendations/#asynchronous-processing)" + }, + "204": { + "description": "[no content](https://jsonapi.org/format/#crud-deleting-responses-204)" + }, + "401": { + "content": { + "application/vnd.api+json": { + "schema": { + "$ref": "#/components/schemas/failure" + } + } + }, + "description": "not authorized" + }, + "404": { + "content": { + "application/vnd.api+json": { + "schema": { + "$ref": "#/components/schemas/failure" + } + } + }, + "description": "[Resource does not exist](https://jsonapi.org/format/#crud-deleting-responses-404)" + } + }, + "tags": [ + "authors" + ] + } + ' +--- +# name: test_patch_request + ' + { + "description": "", + "operationId": "update/authors/{id}", + "parameters": [ + { + "description": "A unique integer value identifying this author.", + "in": "path", + "name": "id", + "required": true, + "schema": { + "type": "string" + } + } + ], + "requestBody": { + "content": { + "application/vnd.api+json": { + "schema": { + "properties": { + "data": { + "additionalProperties": false, + "properties": { + "attributes": { + "properties": { + "defaults": { + "default": "default", + "description": "help for defaults", + "maxLength": 20, + "minLength": 3, + "type": "string", + "writeOnly": true + }, + "email": { + "format": "email", + "maxLength": 254, + "type": "string" + }, + "name": { + "maxLength": 50, + "type": "string" + } + }, + "type": "object" + }, + "id": { + "$ref": "#/components/schemas/id" + }, + "links": { + "properties": { + "self": { + "$ref": "#/components/schemas/link" + } + }, + "type": "object" + }, + "relationships": { + "properties": { + "bio": { + "$ref": "#/components/schemas/reltoone" + }, + "comments": { + "$ref": "#/components/schemas/reltomany" + }, + "entries": { + "$ref": "#/components/schemas/reltomany" + }, + "first_entry": { + "$ref": "#/components/schemas/reltoone" + }, + "type": { + "$ref": "#/components/schemas/reltoone" + } + }, + "type": "object" + }, + "type": { + "$ref": "#/components/schemas/type" + } + }, + "required": [ + "type", + "id" + ], + "type": "object" + } + }, + "required": [ + "data" + ] + } + } + } + }, + "responses": { + "200": { + "content": { + "application/vnd.api+json": { + "schema": { + "properties": { + "data": { + "$ref": "#/components/schemas/Author" + }, + "included": { + "items": { + "$ref": "#/components/schemas/resource" + }, + "type": "array", + "uniqueItems": true + }, + "jsonapi": { + "$ref": "#/components/schemas/jsonapi" + }, + "links": { + "allOf": [ + { + "$ref": "#/components/schemas/links" + }, + { + "$ref": "#/components/schemas/pagination" + } + ], + "description": "Link members related to primary data" + } + }, + "required": [ + "data" + ], + "type": "object" + } + } + }, + "description": "update/authors/{id}" + }, + "401": { + "content": { + "application/vnd.api+json": { + "schema": { + "$ref": "#/components/schemas/failure" + } + } + }, + "description": "not authorized" + }, + "403": { + "content": { + "application/vnd.api+json": { + "schema": { + "$ref": "#/components/schemas/failure" + } + } + }, + "description": "[Forbidden](https://jsonapi.org/format/#crud-updating-responses-403)" + }, + "404": { + "content": { + "application/vnd.api+json": { + "schema": { + "$ref": "#/components/schemas/failure" + } + } + }, + "description": "[Related resource does not exist](https://jsonapi.org/format/#crud-updating-responses-404)" + }, + "409": { + "content": { + "application/vnd.api+json": { + "schema": { + "$ref": "#/components/schemas/failure" + } + } + }, + "description": "[Conflict]([Conflict](https://jsonapi.org/format/#crud-updating-responses-409)" + } + }, + "tags": [ + "authors" + ] + } + ' +--- +# name: test_path_with_id_parameter + ' + { + "description": "", + "operationId": "retrieve/authors/{id}/", + "parameters": [ + { + "description": "A unique integer value identifying this author.", + "in": "path", + "name": "id", + "required": true, + "schema": { + "type": "string" + } + }, + { + "$ref": "#/components/parameters/include" + }, + { + "$ref": "#/components/parameters/fields" + }, + { + "$ref": "#/components/parameters/sort" + }, + { + "description": "Which field to use when ordering the results.", + "in": "query", + "name": "sort", + "required": false, + "schema": { + "type": "string" + } + }, + { + "description": "A search term.", + "in": "query", + "name": "filter[search]", + "required": false, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/vnd.api+json": { + "schema": { + "properties": { + "data": { + "$ref": "#/components/schemas/AuthorDetail" + }, + "included": { + "items": { + "$ref": "#/components/schemas/resource" + }, + "type": "array", + "uniqueItems": true + }, + "jsonapi": { + "$ref": "#/components/schemas/jsonapi" + }, + "links": { + "allOf": [ + { + "$ref": "#/components/schemas/links" + }, + { + "$ref": "#/components/schemas/pagination" + } + ], + "description": "Link members related to primary data" + } + }, + "required": [ + "data" + ], + "type": "object" + } + } + }, + "description": "retrieve/authors/{id}/" + }, + "401": { + "content": { + "application/vnd.api+json": { + "schema": { + "$ref": "#/components/schemas/failure" + } + } + }, + "description": "not authorized" + }, + "404": { + "content": { + "application/vnd.api+json": { + "schema": { + "$ref": "#/components/schemas/failure" + } + } + }, + "description": "not found" + } + }, + "tags": [ + "authors" + ] + } + ' +--- +# name: test_path_without_parameters + ' + { + "description": "", + "operationId": "List/authors/", + "parameters": [ + { + "$ref": "#/components/parameters/include" + }, + { + "$ref": "#/components/parameters/fields" + }, + { + "$ref": "#/components/parameters/sort" + }, + { + "description": "A page number within the paginated result set.", + "in": "query", + "name": "page[number]", + "required": false, + "schema": { + "type": "integer" + } + }, + { + "description": "Number of results to return per page.", + "in": "query", + "name": "page[size]", + "required": false, + "schema": { + "type": "integer" + } + }, + { + "description": "Which field to use when ordering the results.", + "in": "query", + "name": "sort", + "required": false, + "schema": { + "type": "string" + } + }, + { + "description": "A search term.", + "in": "query", + "name": "filter[search]", + "required": false, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/vnd.api+json": { + "schema": { + "properties": { + "data": { + "items": { + "$ref": "#/components/schemas/AuthorList" + }, + "type": "array" + }, + "included": { + "items": { + "$ref": "#/components/schemas/resource" + }, + "type": "array", + "uniqueItems": true + }, + "jsonapi": { + "$ref": "#/components/schemas/jsonapi" + }, + "links": { + "allOf": [ + { + "$ref": "#/components/schemas/links" + }, + { + "$ref": "#/components/schemas/pagination" + } + ], + "description": "Link members related to primary data" + } + }, + "required": [ + "data" + ], + "type": "object" + } + } + }, + "description": "List/authors/" + }, + "401": { + "content": { + "application/vnd.api+json": { + "schema": { + "$ref": "#/components/schemas/failure" + } + } + }, + "description": "not authorized" + }, + "404": { + "content": { + "application/vnd.api+json": { + "schema": { + "$ref": "#/components/schemas/failure" + } + } + }, + "description": "not found" + } + }, + "tags": [ + "authors" + ] + } + ' +--- +# name: test_post_request + ' + { + "description": "", + "operationId": "create/authors/", + "parameters": [], + "requestBody": { + "content": { + "application/vnd.api+json": { + "schema": { + "properties": { + "data": { + "additionalProperties": false, + "properties": { + "attributes": { + "properties": { + "defaults": { + "default": "default", + "description": "help for defaults", + "maxLength": 20, + "minLength": 3, + "type": "string", + "writeOnly": true + }, + "email": { + "format": "email", + "maxLength": 254, + "type": "string" + }, + "name": { + "maxLength": 50, + "type": "string" + } + }, + "required": [ + "name", + "email" + ], + "type": "object" + }, + "id": { + "$ref": "#/components/schemas/id" + }, + "links": { + "properties": { + "self": { + "$ref": "#/components/schemas/link" + } + }, + "type": "object" + }, + "relationships": { + "properties": { + "bio": { + "$ref": "#/components/schemas/reltoone" + }, + "comments": { + "$ref": "#/components/schemas/reltomany" + }, + "entries": { + "$ref": "#/components/schemas/reltomany" + }, + "first_entry": { + "$ref": "#/components/schemas/reltoone" + }, + "type": { + "$ref": "#/components/schemas/reltoone" + } + }, + "type": "object" + }, + "type": { + "$ref": "#/components/schemas/type" + } + }, + "required": [ + "type" + ], + "type": "object" + } + }, + "required": [ + "data" + ] + } + } + } + }, + "responses": { + "201": { + "content": { + "application/vnd.api+json": { + "schema": { + "properties": { + "data": { + "$ref": "#/components/schemas/Author" + }, + "included": { + "items": { + "$ref": "#/components/schemas/resource" + }, + "type": "array", + "uniqueItems": true + }, + "jsonapi": { + "$ref": "#/components/schemas/jsonapi" + }, + "links": { + "allOf": [ + { + "$ref": "#/components/schemas/links" + }, + { + "$ref": "#/components/schemas/pagination" + } + ], + "description": "Link members related to primary data" + } + }, + "required": [ + "data" + ], + "type": "object" + } + } + }, + "description": "[Created](https://jsonapi.org/format/#crud-creating-responses-201). Assigned `id` and/or any other changes are in this response." + }, + "202": { + "content": { + "application/vnd.api+json": { + "schema": { + "$ref": "#/components/schemas/datum" + } + } + }, + "description": "Accepted for [asynchronous processing](https://jsonapi.org/recommendations/#asynchronous-processing)" + }, + "204": { + "description": "[Created](https://jsonapi.org/format/#crud-creating-responses-204) with the supplied `id`. No other changes from what was POSTed." + }, + "401": { + "content": { + "application/vnd.api+json": { + "schema": { + "$ref": "#/components/schemas/failure" + } + } + }, + "description": "not authorized" + }, + "403": { + "content": { + "application/vnd.api+json": { + "schema": { + "$ref": "#/components/schemas/failure" + } + } + }, + "description": "[Forbidden](https://jsonapi.org/format/#crud-creating-responses-403)" + }, + "404": { + "content": { + "application/vnd.api+json": { + "schema": { + "$ref": "#/components/schemas/failure" + } + } + }, + "description": "[Related resource does not exist](https://jsonapi.org/format/#crud-creating-responses-404)" + }, + "409": { + "content": { + "application/vnd.api+json": { + "schema": { + "$ref": "#/components/schemas/failure" + } + } + }, + "description": "[Conflict](https://jsonapi.org/format/#crud-creating-responses-409)" + } + }, + "tags": [ + "authors" + ] + } + ' +--- diff --git a/example/tests/snapshots/__init__.py b/example/tests/snapshots/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/example/tests/snapshots/snap_test_errors.py b/example/tests/snapshots/snap_test_errors.py deleted file mode 100644 index 09bc25ef..00000000 --- a/example/tests/snapshots/snap_test_errors.py +++ /dev/null @@ -1,107 +0,0 @@ -from snapshottest import Snapshot - -snapshots = Snapshot() - -snapshots["test_first_level_attribute_error 1"] = { - "errors": [ - { - "code": "required", - "detail": "This field is required.", - "source": {"pointer": "/data/attributes/headline"}, - "status": "400", - } - ] -} - -snapshots["test_first_level_custom_attribute_error 1"] = { - "errors": [ - { - "detail": "Too short", - "source": {"pointer": "/data/attributes/body-text"}, - "title": "Too Short title", - } - ] -} - -snapshots["test_many_third_level_dict_errors 1"] = { - "errors": [ - { - "code": "required", - "detail": "This field is required.", - "source": {"pointer": "/data/attributes/comments/0/attachment/data"}, - "status": "400", - }, - { - "code": "required", - "detail": "This field is required.", - "source": {"pointer": "/data/attributes/comments/0/body"}, - "status": "400", - }, - ] -} - -snapshots["test_relationship_errors_has_correct_pointers 1"] = { - "errors": [ - { - "code": "incorrect_type", - "detail": "Incorrect type. Expected resource identifier object, received str.", - "source": {"pointer": "/data/relationships/author"}, - "status": "400", - } - ] -} - -snapshots["test_second_level_array_error 1"] = { - "errors": [ - { - "code": "required", - "detail": "This field is required.", - "source": {"pointer": "/data/attributes/comments/0/body"}, - "status": "400", - } - ] -} - -snapshots["test_second_level_dict_error 1"] = { - "errors": [ - { - "code": "required", - "detail": "This field is required.", - "source": {"pointer": "/data/attributes/comment/body"}, - "status": "400", - } - ] -} - -snapshots["test_third_level_array_error 1"] = { - "errors": [ - { - "code": "required", - "detail": "This field is required.", - "source": {"pointer": "/data/attributes/comments/0/attachments/0/data"}, - "status": "400", - } - ] -} - -snapshots["test_third_level_custom_array_error 1"] = { - "errors": [ - { - "code": "invalid", - "detail": "Too short data", - "source": {"pointer": "/data/attributes/comments/0/attachments/0/data"}, - "status": "400", - } - ] -} - -snapshots["test_third_level_dict_error 1"] = { - "errors": [ - { - "code": "required", - "detail": "This field is required.", - "source": {"pointer": "/data/attributes/comments/0/attachment/data"}, - "status": "400", - } - ] -} diff --git a/example/tests/snapshots/snap_test_openapi.py b/example/tests/snapshots/snap_test_openapi.py deleted file mode 100644 index a0e6e78e..00000000 --- a/example/tests/snapshots/snap_test_openapi.py +++ /dev/null @@ -1,667 +0,0 @@ -from snapshottest import Snapshot - -snapshots = Snapshot() - -snapshots[ - "test_path_without_parameters 1" -] = """{ - "description": "", - "operationId": "List/authors/", - "parameters": [ - { - "$ref": "#/components/parameters/include" - }, - { - "$ref": "#/components/parameters/fields" - }, - { - "$ref": "#/components/parameters/sort" - }, - { - "description": "A page number within the paginated result set.", - "in": "query", - "name": "page[number]", - "required": false, - "schema": { - "type": "integer" - } - }, - { - "description": "Number of results to return per page.", - "in": "query", - "name": "page[size]", - "required": false, - "schema": { - "type": "integer" - } - }, - { - "description": "Which field to use when ordering the results.", - "in": "query", - "name": "sort", - "required": false, - "schema": { - "type": "string" - } - }, - { - "description": "A search term.", - "in": "query", - "name": "filter[search]", - "required": false, - "schema": { - "type": "string" - } - } - ], - "responses": { - "200": { - "content": { - "application/vnd.api+json": { - "schema": { - "properties": { - "data": { - "items": { - "$ref": "#/components/schemas/AuthorList" - }, - "type": "array" - }, - "included": { - "items": { - "$ref": "#/components/schemas/resource" - }, - "type": "array", - "uniqueItems": true - }, - "jsonapi": { - "$ref": "#/components/schemas/jsonapi" - }, - "links": { - "allOf": [ - { - "$ref": "#/components/schemas/links" - }, - { - "$ref": "#/components/schemas/pagination" - } - ], - "description": "Link members related to primary data" - } - }, - "required": [ - "data" - ], - "type": "object" - } - } - }, - "description": "List/authors/" - }, - "401": { - "content": { - "application/vnd.api+json": { - "schema": { - "$ref": "#/components/schemas/failure" - } - } - }, - "description": "not authorized" - }, - "404": { - "content": { - "application/vnd.api+json": { - "schema": { - "$ref": "#/components/schemas/failure" - } - } - }, - "description": "not found" - } - }, - "tags": [ - "authors" - ] -}""" - -snapshots[ - "test_path_with_id_parameter 1" -] = """{ - "description": "", - "operationId": "retrieve/authors/{id}/", - "parameters": [ - { - "description": "A unique integer value identifying this author.", - "in": "path", - "name": "id", - "required": true, - "schema": { - "type": "string" - } - }, - { - "$ref": "#/components/parameters/include" - }, - { - "$ref": "#/components/parameters/fields" - }, - { - "$ref": "#/components/parameters/sort" - }, - { - "description": "Which field to use when ordering the results.", - "in": "query", - "name": "sort", - "required": false, - "schema": { - "type": "string" - } - }, - { - "description": "A search term.", - "in": "query", - "name": "filter[search]", - "required": false, - "schema": { - "type": "string" - } - } - ], - "responses": { - "200": { - "content": { - "application/vnd.api+json": { - "schema": { - "properties": { - "data": { - "$ref": "#/components/schemas/AuthorDetail" - }, - "included": { - "items": { - "$ref": "#/components/schemas/resource" - }, - "type": "array", - "uniqueItems": true - }, - "jsonapi": { - "$ref": "#/components/schemas/jsonapi" - }, - "links": { - "allOf": [ - { - "$ref": "#/components/schemas/links" - }, - { - "$ref": "#/components/schemas/pagination" - } - ], - "description": "Link members related to primary data" - } - }, - "required": [ - "data" - ], - "type": "object" - } - } - }, - "description": "retrieve/authors/{id}/" - }, - "401": { - "content": { - "application/vnd.api+json": { - "schema": { - "$ref": "#/components/schemas/failure" - } - } - }, - "description": "not authorized" - }, - "404": { - "content": { - "application/vnd.api+json": { - "schema": { - "$ref": "#/components/schemas/failure" - } - } - }, - "description": "not found" - } - }, - "tags": [ - "authors" - ] -}""" - -snapshots[ - "test_post_request 1" -] = """{ - "description": "", - "operationId": "create/authors/", - "parameters": [], - "requestBody": { - "content": { - "application/vnd.api+json": { - "schema": { - "properties": { - "data": { - "additionalProperties": false, - "properties": { - "attributes": { - "properties": { - "defaults": { - "default": "default", - "description": "help for defaults", - "maxLength": 20, - "minLength": 3, - "type": "string", - "writeOnly": true - }, - "email": { - "format": "email", - "maxLength": 254, - "type": "string" - }, - "name": { - "maxLength": 50, - "type": "string" - } - }, - "required": [ - "name", - "email" - ], - "type": "object" - }, - "id": { - "$ref": "#/components/schemas/id" - }, - "links": { - "properties": { - "self": { - "$ref": "#/components/schemas/link" - } - }, - "type": "object" - }, - "relationships": { - "properties": { - "bio": { - "$ref": "#/components/schemas/reltoone" - }, - "comments": { - "$ref": "#/components/schemas/reltomany" - }, - "entries": { - "$ref": "#/components/schemas/reltomany" - }, - "first_entry": { - "$ref": "#/components/schemas/reltoone" - }, - "type": { - "$ref": "#/components/schemas/reltoone" - } - }, - "type": "object" - }, - "type": { - "$ref": "#/components/schemas/type" - } - }, - "required": [ - "type" - ], - "type": "object" - } - }, - "required": [ - "data" - ] - } - } - } - }, - "responses": { - "201": { - "content": { - "application/vnd.api+json": { - "schema": { - "properties": { - "data": { - "$ref": "#/components/schemas/Author" - }, - "included": { - "items": { - "$ref": "#/components/schemas/resource" - }, - "type": "array", - "uniqueItems": true - }, - "jsonapi": { - "$ref": "#/components/schemas/jsonapi" - }, - "links": { - "allOf": [ - { - "$ref": "#/components/schemas/links" - }, - { - "$ref": "#/components/schemas/pagination" - } - ], - "description": "Link members related to primary data" - } - }, - "required": [ - "data" - ], - "type": "object" - } - } - }, - "description": "[Created](https://jsonapi.org/format/#crud-creating-responses-201). Assigned `id` and/or any other changes are in this response." - }, - "202": { - "content": { - "application/vnd.api+json": { - "schema": { - "$ref": "#/components/schemas/datum" - } - } - }, - "description": "Accepted for [asynchronous processing](https://jsonapi.org/recommendations/#asynchronous-processing)" - }, - "204": { - "description": "[Created](https://jsonapi.org/format/#crud-creating-responses-204) with the supplied `id`. No other changes from what was POSTed." - }, - "401": { - "content": { - "application/vnd.api+json": { - "schema": { - "$ref": "#/components/schemas/failure" - } - } - }, - "description": "not authorized" - }, - "403": { - "content": { - "application/vnd.api+json": { - "schema": { - "$ref": "#/components/schemas/failure" - } - } - }, - "description": "[Forbidden](https://jsonapi.org/format/#crud-creating-responses-403)" - }, - "404": { - "content": { - "application/vnd.api+json": { - "schema": { - "$ref": "#/components/schemas/failure" - } - } - }, - "description": "[Related resource does not exist](https://jsonapi.org/format/#crud-creating-responses-404)" - }, - "409": { - "content": { - "application/vnd.api+json": { - "schema": { - "$ref": "#/components/schemas/failure" - } - } - }, - "description": "[Conflict](https://jsonapi.org/format/#crud-creating-responses-409)" - } - }, - "tags": [ - "authors" - ] -}""" - -snapshots[ - "test_patch_request 1" -] = """{ - "description": "", - "operationId": "update/authors/{id}", - "parameters": [ - { - "description": "A unique integer value identifying this author.", - "in": "path", - "name": "id", - "required": true, - "schema": { - "type": "string" - } - } - ], - "requestBody": { - "content": { - "application/vnd.api+json": { - "schema": { - "properties": { - "data": { - "additionalProperties": false, - "properties": { - "attributes": { - "properties": { - "defaults": { - "default": "default", - "description": "help for defaults", - "maxLength": 20, - "minLength": 3, - "type": "string", - "writeOnly": true - }, - "email": { - "format": "email", - "maxLength": 254, - "type": "string" - }, - "name": { - "maxLength": 50, - "type": "string" - } - }, - "type": "object" - }, - "id": { - "$ref": "#/components/schemas/id" - }, - "links": { - "properties": { - "self": { - "$ref": "#/components/schemas/link" - } - }, - "type": "object" - }, - "relationships": { - "properties": { - "bio": { - "$ref": "#/components/schemas/reltoone" - }, - "comments": { - "$ref": "#/components/schemas/reltomany" - }, - "entries": { - "$ref": "#/components/schemas/reltomany" - }, - "first_entry": { - "$ref": "#/components/schemas/reltoone" - }, - "type": { - "$ref": "#/components/schemas/reltoone" - } - }, - "type": "object" - }, - "type": { - "$ref": "#/components/schemas/type" - } - }, - "required": [ - "type", - "id" - ], - "type": "object" - } - }, - "required": [ - "data" - ] - } - } - } - }, - "responses": { - "200": { - "content": { - "application/vnd.api+json": { - "schema": { - "properties": { - "data": { - "$ref": "#/components/schemas/Author" - }, - "included": { - "items": { - "$ref": "#/components/schemas/resource" - }, - "type": "array", - "uniqueItems": true - }, - "jsonapi": { - "$ref": "#/components/schemas/jsonapi" - }, - "links": { - "allOf": [ - { - "$ref": "#/components/schemas/links" - }, - { - "$ref": "#/components/schemas/pagination" - } - ], - "description": "Link members related to primary data" - } - }, - "required": [ - "data" - ], - "type": "object" - } - } - }, - "description": "update/authors/{id}" - }, - "401": { - "content": { - "application/vnd.api+json": { - "schema": { - "$ref": "#/components/schemas/failure" - } - } - }, - "description": "not authorized" - }, - "403": { - "content": { - "application/vnd.api+json": { - "schema": { - "$ref": "#/components/schemas/failure" - } - } - }, - "description": "[Forbidden](https://jsonapi.org/format/#crud-updating-responses-403)" - }, - "404": { - "content": { - "application/vnd.api+json": { - "schema": { - "$ref": "#/components/schemas/failure" - } - } - }, - "description": "[Related resource does not exist](https://jsonapi.org/format/#crud-updating-responses-404)" - }, - "409": { - "content": { - "application/vnd.api+json": { - "schema": { - "$ref": "#/components/schemas/failure" - } - } - }, - "description": "[Conflict]([Conflict](https://jsonapi.org/format/#crud-updating-responses-409)" - } - }, - "tags": [ - "authors" - ] -}""" - -snapshots[ - "test_delete_request 1" -] = """{ - "description": "", - "operationId": "destroy/authors/{id}", - "parameters": [ - { - "description": "A unique integer value identifying this author.", - "in": "path", - "name": "id", - "required": true, - "schema": { - "type": "string" - } - } - ], - "responses": { - "200": { - "content": { - "application/vnd.api+json": { - "schema": { - "$ref": "#/components/schemas/onlymeta" - } - } - }, - "description": "[OK](https://jsonapi.org/format/#crud-deleting-responses-200)" - }, - "202": { - "content": { - "application/vnd.api+json": { - "schema": { - "$ref": "#/components/schemas/datum" - } - } - }, - "description": "Accepted for [asynchronous processing](https://jsonapi.org/recommendations/#asynchronous-processing)" - }, - "204": { - "description": "[no content](https://jsonapi.org/format/#crud-deleting-responses-204)" - }, - "401": { - "content": { - "application/vnd.api+json": { - "schema": { - "$ref": "#/components/schemas/failure" - } - } - }, - "description": "not authorized" - }, - "404": { - "content": { - "application/vnd.api+json": { - "schema": { - "$ref": "#/components/schemas/failure" - } - } - }, - "description": "[Resource does not exist](https://jsonapi.org/format/#crud-deleting-responses-404)" - } - }, - "tags": [ - "authors" - ] -}""" diff --git a/example/tests/test_errors.py b/example/tests/test_errors.py index 6b322d72..2267ec6e 100644 --- a/example/tests/test_errors.py +++ b/example/tests/test_errors.py @@ -79,7 +79,7 @@ def test_first_level_attribute_error(client, some_blog, snapshot): }, } } - snapshot.assert_match(perform_error_test(client, data)) + assert snapshot == perform_error_test(client, data) def test_first_level_custom_attribute_error(client, some_blog, snapshot): @@ -94,7 +94,7 @@ def test_first_level_custom_attribute_error(client, some_blog, snapshot): } } with override_settings(JSON_API_FORMAT_FIELD_NAMES="dasherize"): - snapshot.assert_match(perform_error_test(client, data)) + assert snapshot == perform_error_test(client, data) def test_second_level_array_error(client, some_blog, snapshot): @@ -110,7 +110,7 @@ def test_second_level_array_error(client, some_blog, snapshot): } } - snapshot.assert_match(perform_error_test(client, data)) + assert snapshot == perform_error_test(client, data) def test_second_level_dict_error(client, some_blog, snapshot): @@ -126,7 +126,7 @@ def test_second_level_dict_error(client, some_blog, snapshot): } } - snapshot.assert_match(perform_error_test(client, data)) + assert snapshot == perform_error_test(client, data) def test_third_level_array_error(client, some_blog, snapshot): @@ -142,7 +142,7 @@ def test_third_level_array_error(client, some_blog, snapshot): } } - snapshot.assert_match(perform_error_test(client, data)) + assert snapshot == perform_error_test(client, data) def test_third_level_custom_array_error(client, some_blog, snapshot): @@ -160,7 +160,7 @@ def test_third_level_custom_array_error(client, some_blog, snapshot): } } - snapshot.assert_match(perform_error_test(client, data)) + assert snapshot == perform_error_test(client, data) def test_third_level_dict_error(client, some_blog, snapshot): @@ -176,7 +176,7 @@ def test_third_level_dict_error(client, some_blog, snapshot): } } - snapshot.assert_match(perform_error_test(client, data)) + assert snapshot == perform_error_test(client, data) def test_many_third_level_dict_errors(client, some_blog, snapshot): @@ -192,7 +192,7 @@ def test_many_third_level_dict_errors(client, some_blog, snapshot): } } - snapshot.assert_match(perform_error_test(client, data)) + assert snapshot == perform_error_test(client, data) def test_relationship_errors_has_correct_pointers(client, some_blog, snapshot): @@ -210,4 +210,4 @@ def test_relationship_errors_has_correct_pointers(client, some_blog, snapshot): } } - snapshot.assert_match(perform_error_test(client, data)) + assert snapshot == perform_error_test(client, data) diff --git a/example/tests/test_openapi.py b/example/tests/test_openapi.py index d32a9367..5b881f8b 100644 --- a/example/tests/test_openapi.py +++ b/example/tests/test_openapi.py @@ -33,7 +33,7 @@ def test_path_without_parameters(snapshot): inspector.view = view operation = inspector.get_operation(path, method) - snapshot.assert_match(json.dumps(operation, indent=2, sort_keys=True)) + assert snapshot == json.dumps(operation, indent=2, sort_keys=True) def test_path_with_id_parameter(snapshot): @@ -47,7 +47,7 @@ def test_path_with_id_parameter(snapshot): inspector.view = view operation = inspector.get_operation(path, method) - snapshot.assert_match(json.dumps(operation, indent=2, sort_keys=True)) + assert snapshot == json.dumps(operation, indent=2, sort_keys=True) def test_post_request(snapshot): @@ -61,7 +61,7 @@ def test_post_request(snapshot): inspector.view = view operation = inspector.get_operation(path, method) - snapshot.assert_match(json.dumps(operation, indent=2, sort_keys=True)) + assert snapshot == json.dumps(operation, indent=2, sort_keys=True) def test_patch_request(snapshot): @@ -75,7 +75,7 @@ def test_patch_request(snapshot): inspector.view = view operation = inspector.get_operation(path, method) - snapshot.assert_match(json.dumps(operation, indent=2, sort_keys=True)) + assert snapshot == json.dumps(operation, indent=2, sort_keys=True) def test_delete_request(snapshot): @@ -89,7 +89,7 @@ def test_delete_request(snapshot): inspector.view = view operation = inspector.get_operation(path, method) - snapshot.assert_match(json.dumps(operation, indent=2, sort_keys=True)) + assert snapshot == json.dumps(operation, indent=2, sort_keys=True) @override_settings( diff --git a/requirements/requirements-testing.txt b/requirements/requirements-testing.txt index 5ac6e9c9..4d83cd28 100644 --- a/requirements/requirements-testing.txt +++ b/requirements/requirements-testing.txt @@ -5,4 +5,4 @@ pytest==6.2.5 pytest-cov==3.0.0 pytest-django==4.4.0 pytest-factoryboy==2.1.0 -snapshottest==0.6.0 +syrupy==1.4.7