示例#1
0
    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)
示例#2
0
  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()
示例#3
0
  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)
示例#4
0
  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)
示例#5
0
    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)