def testUnknownProperty(self): class A(ndb.Model): a = ndb.StringProperty() inst = A(a='abc') inst.put() datastore_utils.DeletePropertyValue(inst, 'b') inst.put() inst = A.get_by_id(inst.key.id()) self.assertIsNotNone(inst.a)
def testRequiredField(self): # Initial schema but this time with a required property class A(ndb.Model): a = ndb.StringProperty() b = ndb.StringProperty(required=True) # Create an entity using the initial schema inst = A(a='abc', b='def') inst.put() # Delete the property and save the entity utils.DeletePropertyValue(inst, 'b') # Property required but no longer has a value. with self.assertRaises(Exception): inst.put()
def testDatetimeAutoNowAdd(self): # Initial schema class A(ndb.Model): a = ndb.StringProperty() b = ndb.DateTimeProperty(auto_now_add=True) # Create an entity using the initial schema inst = A(a='abc') inst.put() # Delete the property and save the entity utils.DeletePropertyValue(inst, 'b') inst.put() self.assertTrue(utils.HasProperty(inst, 'b')) self.assertIsNotNone(inst.b)
def testRepeatedProperty(self): # Initial schema class A(ndb.Model): a = ndb.StringProperty() b = ndb.StringProperty(repeated=True) # Create an entity using the initial schema inst = A(a='abc', b=['def']) inst.put() self.assertIsNotNone(inst.b) # Delete the property and save the entity utils.DeletePropertyValue(inst, 'b') inst.put() inst = A.get_by_id(inst.key.id()) # The old data is gone self.assertEqual([], inst.b)
def testDeleteValue(self): # Initial schema class A(ndb.Model): a = ndb.StringProperty() b = ndb.StringProperty() # Create an entity using the initial schema inst = A(a='abc', b='def') inst.put() self.assertIsNotNone(inst.b) # Delete the property and save the entity datastore_utils.DeletePropertyValue(inst, 'b') inst.put() inst = A.get_by_id(inst.key.id()) # The old data is gone :) self.assertIsNone(inst.b)