def deserialize(obj_type, data): obj = obj_type() for k, v in six.iteritems(data): if isinstance(v, SERIALIZABLE_TYPES): v = date_util.parse(v) if date_util.valid(v) else v setattr(obj, k, v) return obj
def test_deserialize(self): obj = json_util.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_util.parse(MOCK_JSON["k4"]), obj.k4) self.assertListEqual(MOCK_JSON["k5"], obj.k5) self.assertDictEqual(MOCK_JSON["k6"], obj.k6)
def test_deserialize(self): obj = json_util.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_util.parse(MOCK_JSON['k4']), obj.k4) self.assertListEqual(MOCK_JSON['k5'], obj.k5) self.assertDictEqual(MOCK_JSON['k6'], obj.k6)
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_util.parse(dt_str))