def test_deserialize(self): obj = jsonify.deserialize(FakeModel, MOCK_JSON) self.assertEqual(MOCK_JSON['k1'], obj.k1) self.assertEqual(MOCK_JSON['k2'], obj.k2) self.assertEqual(MOCK_JSON['k3'], obj.k3) self.assertEqual(date.parse(MOCK_JSON['k4']), obj.k4) self.assertListEqual(MOCK_JSON['k5'], obj.k5) self.assertDictEqual(MOCK_JSON['k6'], obj.k6)
def deserialize(obj_type, data): obj = obj_type() for k, v in six.iteritems(data): if isinstance(v, SERIALIZABLE_TYPES): v = date.parse(v) if date.valid(v) else v setattr(obj, k, v) return obj
def test_date_parse(self): offset = dateutil.tz.tzoffset(None, 3600) expected = datetime.datetime(2015, 1, 1, 12, 0, 1, tzinfo=offset) dt_str = "2015-01-01T12:00:01.000000+01:00" self.assertEqual(expected, date.parse(dt_str))