Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
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")
Ejemplo n.º 5
0
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
Ejemplo n.º 6
0
def test_get_nonexistent_key() -> None:
    model = SimpleModel.get_by_id("notfound")
    assert model is None