def test_put_model_matches_point_query() -> None: model = SimpleModel(id="test", str_prop="asdf") key = model.put() get_resp = SimpleModel.get_by_id("test") assert get_resp == model assert model.key == key
def test_get_or_insert_then_update() -> None: model = SimpleModel.get_or_insert("test", int_prop=10) assert model is not None model.int_prop = 20 model.put() sanity_check = SimpleModel.get_by_id("test") assert sanity_check == model
def test_get_existing_by_id( ndb_stub: datastore_stub.LocalDatastoreStub) -> None: model = SimpleModel( id="test", str_prop="asdf", ) ndb_stub._insert_model(model) model_res = SimpleModel.get_by_id("test") assert model_res == model
def test_query_for_key_prop_filter() -> None: SimpleModel(id="test").put() SimpleModel(id="test1").put() SimpleModel(id="test2").put() KeyPropertyModel(id="test", model_ref=ndb.Key(SimpleModel, "test")).put() resp = KeyPropertyModel.query( KeyPropertyModel.model_ref == ndb.Key(SimpleModel, "test")).fetch() assert len(resp) == 1 assert resp[0] == KeyPropertyModel.get_by_id("test") assert resp[0].model_ref.get() == SimpleModel.get_by_id("test")
def test_delete_model(ndb_stub: datastore_stub.LocalDatastoreStub) -> None: model = SimpleModel( id="test", str_prop="asdf", ) ndb_stub._insert_model(model) key = ndb.Key(SimpleModel, "test") key.delete() assert SimpleModel.get_by_id("test") is None
def test_get_nonexistent_key() -> None: model = SimpleModel.get_by_id("notfound") assert model is None