Skip to content

Commit 48d1d1c

Browse files
committed
UUID string format tests
1 parent dadf075 commit 48d1d1c

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

tests/integration/data/v3.0/petstore.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,9 @@ components:
317317
required:
318318
- rootCause
319319
properties:
320+
correlationId:
321+
type: string
322+
format: uuid
320323
rootCause:
321324
type: string
322325
suberror:

tests/integration/test_petstore.py

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import pytest
3+
from uuid import UUID
34
from six import iteritems
45

56
from openapi_core.extensions.models.models import BaseModel
@@ -1154,11 +1155,13 @@ def test_post_tags_created_invalid_type(
11541155

11551156
code = 400
11561157
message = 'Bad request'
1158+
correlationId = UUID('a8098c1a-f86e-11da-bd1a-00112444be1e')
11571159
rootCause = 'Tag already exist'
11581160
additionalinfo = 'Tag Dog already exist'
11591161
data_json = {
11601162
'code': code,
11611163
'message': message,
1164+
'correlationId': str(correlationId),
11621165
'rootCause': rootCause,
11631166
'additionalinfo': additionalinfo,
11641167
}
@@ -1171,5 +1174,6 @@ def test_post_tags_created_invalid_type(
11711174
assert isinstance(response_result.data, BaseModel)
11721175
assert response_result.data.code == code
11731176
assert response_result.data.message == message
1177+
assert response_result.data.correlationId == correlationId
11741178
assert response_result.data.rootCause == rootCause
11751179
assert response_result.data.additionalinfo == additionalinfo

tests/unit/schema/test_schemas.py

+21
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import datetime
2+
import uuid
23

34
import mock
45
import pytest
@@ -416,6 +417,26 @@ def test_string_format_date(self, value):
416417

417418
assert result == value
418419

420+
@pytest.mark.parametrize('value', [
421+
uuid.UUID('{12345678-1234-5678-1234-567812345678}'),
422+
])
423+
def test_string_format_uuid(self, value):
424+
schema = Schema('string', schema_format='uuid')
425+
426+
result = schema.validate(value)
427+
428+
assert result == value
429+
430+
@pytest.mark.parametrize('value', [
431+
b('true'), u('true'), False, 1, 3.14, [1, 3],
432+
datetime.date(2018, 1, 2), datetime.datetime(2018, 1, 2, 23, 59, 59),
433+
])
434+
def test_string_format_uuid_invalid(self, value):
435+
schema = Schema('string', schema_format='uuid')
436+
437+
with pytest.raises(InvalidSchemaValue):
438+
schema.validate(value)
439+
419440
@pytest.mark.parametrize('value', [
420441
b('true'), u('true'), False, 1, 3.14, [1, 3],
421442
datetime.date(1989, 1, 2),

0 commit comments

Comments
 (0)