コード例 #1
0
  def testChangeSchema_PolyModel(self):

    # Initial schema
    class Base(polymodel.PolyModel):
      a = ndb.StringProperty()
      b = ndb.StringProperty(required=True)

    class A(Base):
      pass

    # Create an entity using the initial schema
    inst = A(a='abc', b='def')
    inst.put()

    # Revised schema
    class Base(polymodel.PolyModel):  # pylint: disable=function-redefined
      a = ndb.StringProperty()

    class A(Base):  # pylint: disable=function-redefined
      pass

    # Retrieve and save the old instance
    inst = A.get_by_id(inst.key.id())
    inst.put()

    # The old data is still there :(
    self.assertIsNotNone(inst.b)

    # Delete the property and save the entity
    utils.DeleteProperty(inst, 'b')
    inst.put()
    inst = A.get_by_id(inst.key.id())

    # The old data is gone :)
    self.assertIsNone(inst.b)
コード例 #2
0
  def testChangeSchema_RequiredField(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()

    # Revised schema without the required property
    class A(ndb.Model):  # pylint: disable=function-redefined
      a = ndb.StringProperty()

    # Retrieve and save the old instance
    inst = A.get_by_id(inst.key.id())
    inst.put()

    # The old data is still there :(
    self.assertIsNotNone(inst.b)

    # Delete the property and save the entity
    utils.DeleteProperty(inst, 'b')
    inst.put()
    inst = A.get_by_id(inst.key.id())

    # The old data is gone :)
    self.assertIsNone(inst.b)
コード例 #3
0
    def testUnknownProperty(self):
        class A(ndb.Model):
            a = ndb.StringProperty()

        inst = A(a='abc')
        inst.put()

        datastore_utils.DeleteProperty(inst, 'b')
        inst.put()
        inst = A.get_by_id(inst.key.id())

        self.assertIsNotNone(inst.a)
コード例 #4
0
  def testSameSchema_DoesntDeleteProperty(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()

    # Delete the property and save the entity
    utils.DeleteProperty(inst, 'b')
    inst.put()

    # Create a new instance and verify that the 'b' hasn't disappeared
    new = A(a='abc', b='def')
    new.put()
    self.assertTrue(utils.HasProperty(new, 'b'))
コード例 #5
0
  def testSameSchema_RepeatedProperty(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.DeleteProperty(inst, 'b')
    inst.put()
    inst = A.get_by_id(inst.key.id())

    # The old data is...kinda gone :|
    self.assertEqual([], inst.b)
コード例 #6
0
  def testSameSchema(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
    utils.DeleteProperty(inst, 'b')
    inst.put()
    inst = A.get_by_id(inst.key.id())

    # The old data is gone :)
    self.assertIsNone(inst.b)
コード例 #7
0
    def testDedupe_NoCount(self):
        datastore_utils.DeleteProperty(self.event_2, 'count')

        self.event_1.Dedupe(self.event_2)

        self.assertEqual(2, self.event_1.count)