|
1 | 1 | import datetime |
2 | 2 | import uuid |
3 | 3 |
|
| 4 | +from isodate.tzinfo import UTC, FixedOffset |
4 | 5 | import pytest |
5 | 6 |
|
6 | 7 | from openapi_core.schema.media_types.models import MediaType |
@@ -199,13 +200,30 @@ def test_string_format_date(self, unmarshaller_factory): |
199 | 200 |
|
200 | 201 | assert result == datetime.date(2018, 1, 2) |
201 | 202 |
|
202 | | - def test_string_format_datetime(self, unmarshaller_factory): |
| 203 | + def test_string_format_datetime_invalid(self, unmarshaller_factory): |
| 204 | + schema = Schema('string', schema_format='date-time') |
| 205 | + value = '2018-01-02T00:00:00' |
| 206 | + |
| 207 | + with pytest.raises(InvalidSchemaValue): |
| 208 | + unmarshaller_factory(schema)(value) |
| 209 | + |
| 210 | + def test_string_format_datetime_utc(self, unmarshaller_factory): |
203 | 211 | schema = Schema('string', schema_format='date-time') |
204 | 212 | value = '2018-01-02T00:00:00Z' |
205 | 213 |
|
206 | 214 | result = unmarshaller_factory(schema)(value) |
207 | 215 |
|
208 | | - assert result == datetime.datetime(2018, 1, 2, 0, 0) |
| 216 | + tzinfo = UTC |
| 217 | + assert result == datetime.datetime(2018, 1, 2, 0, 0, tzinfo=tzinfo) |
| 218 | + |
| 219 | + def test_string_format_datetime_tz(self, unmarshaller_factory): |
| 220 | + schema = Schema('string', schema_format='date-time') |
| 221 | + value = '2020-04-01T12:00:00+02:00' |
| 222 | + |
| 223 | + result = unmarshaller_factory(schema)(value) |
| 224 | + |
| 225 | + tzinfo = FixedOffset(2) |
| 226 | + assert result == datetime.datetime(2020, 4, 1, 12, 0, 0, tzinfo=tzinfo) |
209 | 227 |
|
210 | 228 | def test_string_format_custom(self, unmarshaller_factory): |
211 | 229 | formatted = 'x-custom' |
@@ -408,6 +426,18 @@ def test_number_format_double(self, unmarshaller_factory): |
408 | 426 |
|
409 | 427 | assert result == 1.2 |
410 | 428 |
|
| 429 | + def test_object_nullable(self, unmarshaller_factory): |
| 430 | + schema = Schema( |
| 431 | + 'object', |
| 432 | + properties={ |
| 433 | + 'foo': Schema('object', nullable=True), |
| 434 | + }, |
| 435 | + ) |
| 436 | + value = {'foo': None} |
| 437 | + result = unmarshaller_factory(schema)(value) |
| 438 | + |
| 439 | + assert result == {'foo': None} |
| 440 | + |
411 | 441 | def test_schema_any_one_of(self, unmarshaller_factory): |
412 | 442 | schema = Schema(one_of=[ |
413 | 443 | Schema('string'), |
|
0 commit comments