Ejemplo n.º 1
0
 def test_insert_new_key_already_present(self):
   EntityX(id=1, parent=self.parent).put()
   data = EntityX(id=1, parent=self.parent)
   new_key = ndb.Key('EntityX', 2, parent=self.parent)
   actual = monotonic.insert(data, lambda: new_key)
   expected = ndb.Key('EntityX', 2, parent=self.parent)
   self.assertEqual(expected, actual)
Ejemplo n.º 2
0
 def test_insert_new_key_already_present_twice(self):
   EntityX(id=1, parent=self.parent).put()
   EntityX(id=2, parent=self.parent).put()
   data = EntityX(id=1, parent=self.parent)
   new_keys = [
     ndb.Key('EntityX', 2, parent=self.parent),
     ndb.Key('EntityX', 3, parent=self.parent),
   ]
   actual = monotonic.insert(data, lambda: new_keys.pop(0))
   self.assertEqual([], new_keys)
   expected = ndb.Key('EntityX', 3, parent=self.parent)
   self.assertEqual(expected, actual)
Ejemplo n.º 3
0
 def test_insert_new_key_already_present_twice_fail_after(self):
   EntityX(id=1, parent=self.parent).put()
   EntityX(id=2, parent=self.parent).put()
   EntityX(id=3, parent=self.parent).put()
   data = EntityX(id=1, parent=self.parent)
   new_keys = [
     ndb.Key('EntityX', 2, parent=self.parent),
     ndb.Key('EntityX', 3, parent=self.parent),
   ]
   actual = monotonic.insert(
       data, lambda: new_keys.pop(0) if new_keys else None)
   self.assertEqual([], new_keys)
   self.assertEqual(None, actual)
Ejemplo n.º 4
0
  def test_insert_transaction_failure(self):
    EntityX(id=1, parent=self.parent).put()
    calls = []
    def transaction(*args, **kwargs):
      calls.append(1)
      if len(calls) < 2:
        raise txn.CommitError()
      return old_transaction(*args, **kwargs)

    old_transaction = self.mock(txn, 'transaction', transaction)

    actual = monotonic.insert(EntityX(id=2, parent=self.parent))
    expected = ndb.Key('EntityX', 2, parent=self.parent)
    self.assertEqual(expected, actual)
    self.assertEqual([1, 1], calls)
Ejemplo n.º 5
0
 def test_insert_new_key(self):
   data = EntityX(id=1, parent=self.parent)
   actual = monotonic.insert(data, self.fail)
   expected = ndb.Key('EntityX', 1, parent=self.parent)
   self.assertEqual(expected, actual)
Ejemplo n.º 6
0
 def test_insert_already_present(self):
   EntityX(id=1, parent=self.parent).put()
   data = EntityX(id=1, parent=self.parent)
   actual = monotonic.insert(data, None)
   self.assertEqual(None, actual)
Ejemplo n.º 7
0
 def test_insert_already_present(self):
     EntityX(id=1, parent=self.parent).put()
     data = EntityX(id=1, parent=self.parent)
     actual = monotonic.insert(data, None)
     self.assertEqual(None, actual)
Ejemplo n.º 8
0
 def test_insert(self):
     data = EntityX(id=1, parent=self.parent)
     actual = monotonic.insert(data, None)
     expected = ndb.Key('EntityX', 1, parent=self.parent)
     self.assertEqual(expected, actual)