From 48d1d1c8ae13b6d21adf1f05e480eb2473b0f216 Mon Sep 17 00:00:00 2001 From: Artur Maciag Date: Tue, 26 Feb 2019 10:37:49 +0000 Subject: [PATCH] UUID string format tests --- tests/integration/data/v3.0/petstore.yaml | 3 +++ tests/integration/test_petstore.py | 4 ++++ tests/unit/schema/test_schemas.py | 21 +++++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/tests/integration/data/v3.0/petstore.yaml b/tests/integration/data/v3.0/petstore.yaml index 2dc3083..733c587 100644 --- a/tests/integration/data/v3.0/petstore.yaml +++ b/tests/integration/data/v3.0/petstore.yaml @@ -317,6 +317,9 @@ components: required: - rootCause properties: + correlationId: + type: string + format: uuid rootCause: type: string suberror: diff --git a/tests/integration/test_petstore.py b/tests/integration/test_petstore.py index d7fd1a0..f1068c1 100644 --- a/tests/integration/test_petstore.py +++ b/tests/integration/test_petstore.py @@ -1,5 +1,6 @@ import json import pytest +from uuid import UUID from six import iteritems from openapi_core.extensions.models.models import BaseModel @@ -1154,11 +1155,13 @@ class TestPetstore(object): code = 400 message = 'Bad request' + correlationId = UUID('a8098c1a-f86e-11da-bd1a-00112444be1e') rootCause = 'Tag already exist' additionalinfo = 'Tag Dog already exist' data_json = { 'code': code, 'message': message, + 'correlationId': str(correlationId), 'rootCause': rootCause, 'additionalinfo': additionalinfo, } @@ -1171,5 +1174,6 @@ class TestPetstore(object): assert isinstance(response_result.data, BaseModel) assert response_result.data.code == code assert response_result.data.message == message + assert response_result.data.correlationId == correlationId assert response_result.data.rootCause == rootCause assert response_result.data.additionalinfo == additionalinfo diff --git a/tests/unit/schema/test_schemas.py b/tests/unit/schema/test_schemas.py index fb9675e..47f4011 100644 --- a/tests/unit/schema/test_schemas.py +++ b/tests/unit/schema/test_schemas.py @@ -1,4 +1,5 @@ import datetime +import uuid import mock import pytest @@ -416,6 +417,26 @@ class TestSchemaValidate(object): assert result == value + @pytest.mark.parametrize('value', [ + uuid.UUID('{12345678-1234-5678-1234-567812345678}'), + ]) + def test_string_format_uuid(self, value): + schema = Schema('string', schema_format='uuid') + + result = schema.validate(value) + + assert result == value + + @pytest.mark.parametrize('value', [ + b('true'), u('true'), False, 1, 3.14, [1, 3], + datetime.date(2018, 1, 2), datetime.datetime(2018, 1, 2, 23, 59, 59), + ]) + def test_string_format_uuid_invalid(self, value): + schema = Schema('string', schema_format='uuid') + + with pytest.raises(InvalidSchemaValue): + schema.validate(value) + @pytest.mark.parametrize('value', [ b('true'), u('true'), False, 1, 3.14, [1, 3], datetime.date(1989, 1, 2),