def testSetPropertyIndexed(self): property = datastore.Property() set_property(property, 'a', 1) self.assertEquals(False, property.value.HasField('indexed')) set_property(property, 'a', 1, indexed=True) self.assertEquals(False, property.value.HasField('indexed')) self.assertEquals(True, property.value.indexed) set_property(property, 'a', 1, indexed=False) self.assertEquals(True, property.value.HasField('indexed')) self.assertEquals(False, property.value.indexed)
def cbquery(self, camid, field): camkey = datastore.Key() path = camkey.path_element.add() path.kind = 'PSCams' path.name = camid req = datastore.LookupRequest() req.key.extend([camkey]) resp = datastore.lookup(req) if resp.found: pscam = resp.found[0].entity password_property = datastore.Property() password_property.name = field for prop in pscam.property: if prop.name == field: val = prop.value.string_value result = [camid, val] else: result = [camid, field] return result
def checkDB(self, gitkit_user): req = datastore.BeginTransactionRequest() resp = datastore.begin_transaction(req) tx = resp.transaction req = datastore.LookupRequest() key = datastore.Key() path = key.path_element.add() path.kind = 'PSUsers' path.name = gitkit_user.user_id req.key.extend([key]) req.read_options.transaction = tx resp = datastore.lookup(req) req = datastore.CommitRequest() req.transaction = tx if resp.missing: user = req.mutation.insert.add() user.key.CopyFrom(key) userid_property = user.property.add() userid_property.name = 'userid' userid_property.value.string_value = gitkit_user.user_id display_name_property = user.property.add() display_name_property.name = 'display_name' display_name_property.value.string_value = gitkit_user.name photo_url_property = user.property.add() photo_url_property.name = 'photo_url' if gitkit_user.photo_url: photo_url_property.value.string_value = gitkit_user.photo_url else: photo_url_property.value.string_value = "/images/home/slider/slide1/cloud1.png" email_property = user.property.add() email_property.name = 'email' email_property.value.string_value = gitkit_user.email last_login_property = user.property.add() last_login_property.name = 'last_login' last_login_property.value.timestamp_microseconds_value = long( time.time() * 1e6) elif resp.found: user = resp.found[0].entity last_login_property = datastore.Property() last_login_property.name = 'last_login' for prop in user.property: if prop.name == 'last_login': prop.value.timestamp_microseconds_value = long( time.time() * 1e6) req.mutation.update.extend([user]) resp = datastore.commit(req) return None
def testSetPropertyOverwrite(self): property = datastore.Property() set_property(property, 'a', 1, indexed=False) set_property(property, 'a', 'a') self.assertEquals('a', get_value(property.value)) self.assertEquals(True, property.value.indexed)
def testSetPropertyOverwrite(self): property = datastore.Property() set_property(property, 'a', 1) set_property(property, 'a', 'a') self.assertEquals(1, len(property.value))