def _get_entity(self): """ Get the cloud datastore representation of this entity. """ _log.debug('%s._get_entity()', type(self).__name__) self.__fix_strings() entity = googledatastore.Entity() attrs = self.__dict__ simple_attrs = dict() complex_attrs = dict() def process_entity(e): if isinstance(e, _BaseEntity): return e._get_entity() elif isinstance(e, list): return [process_entity(s) for s in e if s is not None] else: return e for key, val in attrs.iteritems(): if isinstance(val, _BaseEntity): complex_attrs[key] = val._get_entity() elif isinstance(val, list): complex_attrs[key] = [ process_entity(e) for e in val if e is not None ] elif val is not None: simple_attrs[key] = val add_properties(entity, simple_attrs, indexed=True) add_properties(entity, complex_attrs, indexed=False) return entity
def testPropertyValues(self): property_dict = collections.OrderedDict( a_string=u'a', a_blob='b', a_boolean=True, a_integer=1L, a_double=1.0, a_timestamp_microseconds=datetime.datetime.now(), a_key=datastore.Key(), a_entity=datastore.Entity(), many_integer=[1L, 2L, 3L]) entity = datastore.Entity() add_properties(entity, property_dict) d = dict((key, get_value(value)) for key, value in entity.properties.items()) self.maxDiff = None self.assertDictEqual(d, property_dict)
def testPropertyValues(self): blob_key = datastore.Value() blob_key.blob_key_value = 'blob-key' properties = collections.OrderedDict( a_string=u'a', a_blob='b', a_boolean=True, a_integer=1, a_double=1.0, a_timestamp_microseconds=datetime.datetime.now(), a_key=datastore.Key(), a_entity=datastore.Entity(), a_blob_key=blob_key, many_integer=[1, 2, 3]) entity = datastore.Entity() add_property_values(entity, **properties) d = get_property_values(entity) self.assertDictEqual(d, properties)
def _CreateEntity(name, value): entity = datastore.Entity() path = entity.key.path_element.add() path.kind = _PERSISTENT_OBJECT_KIND path.name = name pickled_value_property = entity.property.add() pickled_value_property.name = _VALUE_PROPERTY_NAME pickled_value_property.value.indexed = False pickled_value_property.value.blob_value = value return entity
def testPropertyValues(self): blob_key = datastore.Value() blob_key.blob_key_value = 'blob-key' property_dict = collections.OrderedDict( a_string=u'a', a_blob='b', a_boolean=True, a_integer=1, a_long=2L, a_double=1.0, a_timestamp_microseconds=datetime.datetime.now(), a_key=datastore.Key(), a_entity=datastore.Entity(), a_blob_key=blob_key, many_integer=[1, 2, 3]) entity = datastore.Entity() helper.add_properties(entity, property_dict) d = dict((prop.name, helper.get_value(prop.value)) for prop in entity.property) self.assertDictEqual(d, property_dict)
def to_proto(self): entity = datastore.Entity() entity.key.path.extend(default_todo_list.key.path) if self.id: add_key_path(entity.key, 'Todo', self.id) else: add_key_path(entity.key, 'Todo') add_properties(entity, {'text': self.text, 'done': self.done, 'created': self.created}) return entity
def to_proto(self): entity = datastore.Entity() entity.key.path_element.extend(default_todo_list.key.path_element) if self.id: add_key_path(entity.key, 'Todo', self.id) else: add_key_path(entity.key, 'Todo') add_property_values(entity, text=self.text, done=self.done, created=self.created) return entity
def testSetPropertyOverwrite(self): entity = datastore.Entity() set_property(entity.properties, 'a', 1, exclude_from_indexes=True) set_property(entity.properties, 'a', 'a') self.assertEquals('a', get_value(entity.properties['a'])) self.assertEquals(False, entity.properties['a'].exclude_from_indexes)
def testSetPropertyIndexed(self): entity = datastore.Entity() set_property(entity.properties, 'a', 1) self.assertEquals(False, entity.properties['a'].exclude_from_indexes) set_property(entity.properties, 'a', 1, exclude_from_indexes=True) self.assertEquals(True, entity.properties['a'].exclude_from_indexes)
def testAddPropertyValuesBlindlyAdd(self): entity = datastore.Entity() add_properties(entity, {'a': 1}) add_properties(entity, {'a': 2}) self.assertEquals(2, len(entity.property))
def testAddPropertyValuesBlindlyAdd(self): entity = datastore.Entity() add_property_values(entity, a=1) add_property_values(entity, a=2) self.assertEquals(2, len(entity.property))