Пример #1
0
 def test_allocate_ids_callback(_datastore_allocate_ids):
     options = _options.Options()
     batch = _api._AllocateIdsBatch(options)
     batch.futures = futures = [tasklets.Future(), tasklets.Future()]
     rpc = utils.future_result(mock.Mock(keys=["key1", "key2"], spec=("key",)))
     batch.allocate_ids_callback(rpc)
     results = [future.result() for future in futures]
     assert results == ["key1", "key2"]
Пример #2
0
 def test_allocate_ids_callback_w_exception(_datastore_allocate_ids):
     options = _options.Options()
     batch = _api._AllocateIdsBatch(options)
     batch.futures = futures = [tasklets.Future(), tasklets.Future()]
     error = Exception("spurious error")
     rpc = tasklets.Future()
     rpc.set_exception(error)
     batch.allocate_ids_callback(rpc)
     assert [future.exception() for future in futures] == [error, error]
Пример #3
0
 def test_idle_callback(_datastore_allocate_ids):
     options = _options.Options()
     batch = _api._AllocateIdsBatch(options)
     batch.add([
         key_module.Key("SomeKind", None)._key,
         key_module.Key("SomeKind", None)._key,
     ])
     key_pbs = [key.to_protobuf() for key in batch.keys]
     batch.idle_callback()
     _datastore_allocate_ids.assert_called_once_with(key_pbs,
                                                     retries=None,
                                                     timeout=None)
     rpc = _datastore_allocate_ids.return_value
     rpc.add_done_callback.assert_called_once_with(
         batch.allocate_ids_callback)
Пример #4
0
 def test_add():
     options = _options.Options()
     batch = _api._AllocateIdsBatch(options)
     futures = batch.add(["key1", "key2"])
     assert batch.keys == ["key1", "key2"]
     assert batch.futures == futures
Пример #5
0
 def test_constructor():
     options = _options.Options()
     batch = _api._AllocateIdsBatch(options)
     assert batch.options is options
     assert batch.keys == []
     assert batch.futures == []