|
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' |
|
0 commit comments