def _get_value_for_json_to_model(prop, v): """json to model.""" logging.info('_get_value_for_json_to_model: %s, vaue: %s', repr(prop), repr(v)) if isinstance(prop, (ndb.DateTimeProperty, ndb.DateProperty, ndb.TimeProperty)): return from_epoch(v) if isinstance(prop, ndb.KeyProperty): return ndb.Key(urlsafe=v) if isinstance(prop, (ndb.StructuredProperty, ndb.LocalStructuredProperty)): return _json_to_model(prop._modelclass, v) if isinstance(prop, (ndb.IntegerProperty, ndb.StringProperty, ndb.TextProperty)): return v logging.fatal('unsupported property type: %s', prop)
def test_convert_from_to(self): """Time convert routines.""" a = from_epoch(1390576468) b = to_epoch(a) self.assertEqual(b, 1390576468)