def test_no_datastore_incomplete_key(Batch, global_cache): class SomeKind(model.Model): pass key = key_module.Key("SomeKind", None) entity = SomeKind(key=key) future = _api.put( model._entity_to_ds_entity(entity), _options.Options(use_datastore=False), ) with pytest.raises(TypeError): future.result()
def test_no_key_returned(Batch, global_cache): class SomeKind(model.Model): pass key = key_module.Key("SomeKind", 1) cache_key = _cache.global_cache_key(key._key) entity = SomeKind(key=key) batch = Batch.return_value batch.put.return_value = future_result(None) future = _api.put(model._entity_to_ds_entity(entity), _options.Options()) assert future.result() is None assert global_cache.get([cache_key]) == [None]
def get_beam_entity_from_ndb_model( model: datastore_services.TYPE_MODEL_SUBCLASS ) -> beam_datastore_types.Entity: """Returns an Apache Beam entity equivalent to the given NDB model. Args: model: datastore_services.Model. The NDB model. Returns: beam_datastore_types.Entity. The Apache Beam entity. """ # We use private _entity_to_ds_entity here because it provides # a functionality that we need and writing it ourselves would be # too complicated. return beam_datastore_types.Entity.from_client_entity( ndb_model._entity_to_ds_entity(model) # pylint: disable=protected-access )
def test_no_datastore(Batch, global_cache): class SomeKind(model.Model): pass key = key_module.Key("SomeKind", 1) cache_key = _cache.global_cache_key(key._key) entity = SomeKind(key=key) cache_value = model._entity_to_protobuf(entity).SerializeToString() batch = Batch.return_value batch.put.return_value = future_result(None) future = _api.put( model._entity_to_ds_entity(entity), _options.Options(use_datastore=False), ) assert future.result() is None assert global_cache.get([cache_key]) == [cache_value]