def test_valid_outputs(self):
     field = fields.DateTime()
     self._dump_equal(field, datetime(2001, 1, 1, 13, 00),
                      '2001-01-01T13:00:00')
     self._dump_equal(field,
                      datetime(2001, 1, 1, 13, 00, tzinfo=timezone.utc),
                      '2001-01-01T13:00:00+00:00')
 def test_invalid_inputs(self):
     field = fields.DateTime()
     self._load_raises(field, '', ['Datetime has wrong format.'])
     self._load_raises(field, 'abc', ['Datetime has wrong format.'])
     self._load_raises(field, '2001-13-01', ['Datetime has wrong format.'])
     self._load_raises(field, '2001-01-32', ['Datetime has wrong format.'])
     # self._load_raises(field, '2001-01-01T99:00', ['Datetime has wrong format.'])
     self._load_raises(field, 20010120, ['Datetime has wrong format.'])
     self._load_raises(field, date(2001, 1, 1),
                       ['Expected a datetime but got a date.'])
 def test_valid_inputs_with_default_timezone(self):
     field = fields.DateTime(default_timezone=timezone.utc)
     self._load_equal(field, '2001-01-01',
                      datetime(2001, 1, 1, tzinfo=timezone.utc))
     self._load_equal(field, '2001-01-01 13:00',
                      datetime(2001, 1, 1, 13, 00, tzinfo=timezone.utc))
     self._load_equal(field, '2001-01-01T13:00',
                      datetime(2001, 1, 1, 13, 00, tzinfo=timezone.utc))
     self._load_equal(field, '2001-01-01T13:00Z',
                      datetime(2001, 1, 1, 13, 00, tzinfo=timezone.utc))
     self._load_equal(field, '2001-01-01T13:00+00:00',
                      datetime(2001, 1, 1, 13, 00, tzinfo=timezone.utc))
     self._load_equal(field, datetime(2001, 1, 1, 13, 00),
                      datetime(2001, 1, 1, 13, 00, tzinfo=timezone.utc))
     self._load_equal(field,
                      datetime(2001, 1, 1, 13, 00, tzinfo=timezone.utc),
                      datetime(2001, 1, 1, 13, 00, tzinfo=timezone.utc))
 def test_valid_inputs(self):
     field = fields.DateTime()
     self._load_equal(field, '2001-01-01', datetime(2001, 1, 1))
     self._load_equal(field, '2001-01-01 13:00',
                      datetime(2001, 1, 1, 13, 00))
     self._load_equal(field, '2001-01-01T13:00:01',
                      datetime(2001, 1, 1, 13, 0, 1))
     self._load_equal(field, '2001-01-01T13:00:01.001',
                      datetime(2001, 1, 1, 13, 0, 1, 1000))
     self._load_equal(field, '2001-01-01T13:00Z',
                      datetime(2001, 1, 1, 13, 00))
     self._load_equal(field, '2001-01-01T13:00+00:00',
                      datetime(2001, 1, 1, 13, 00))
     self._load_equal(field, datetime(2001, 1, 1, 13, 00),
                      datetime(2001, 1, 1, 13, 00))
     self._load_equal(field,
                      datetime(2001, 1, 1, 13, 00, tzinfo=timezone.utc),
                      datetime(2001, 1, 1, 13, 00))
 def test_invalid_outputs(self):
     field = fields.DateTime()
     self._dump_raises(field, '2001-01-01T13:00:00',
                       "'str' object has no attribute 'isoformat'")
     self._dump_raises(field, 123,
                       "'int' object has no attribute 'isoformat'")