Пример #1
0
def test_query_count_async_not_found(
    ndb_stub: datastore_stub.LocalDatastoreStub, ) -> None:
    model = SimpleModel(id="test", str_prop="asdf")
    model.put()

    count = SimpleModel.query().filter(
        SimpleModel.str_prop == "foo").count_async()
    assert count.get_result() == 0
Пример #2
0
def test_put_model_no_id() -> None:
    model1 = SimpleModel(str_prop="asdf")
    model2 = SimpleModel(str_prop="hjkl")
    model1.put()
    model2.put()

    stored = SimpleModel.query().fetch()
    assert stored == [model1, model2]
    assert stored[0].key.id() == 1
    assert stored[1].key.id() == 2
Пример #3
0
def test_ancestor_query() -> None:
    parent_model = SimpleModel(id="parent", str_prop="parent_model")
    parent_model.put()

    child_model = ChildModel(id="child",
                             parent=parent_model.key,
                             str_prop="child_model")
    child_model.put()

    child_query = ChildModel.query(ancestor=parent_model.key).fetch()
    assert child_query == [child_model]
Пример #4
0
def test_query_with_None() -> None:
    m1 = SimpleModel(str_prop="asdf", int_prop=10)
    m2 = SimpleModel(str_prop="aaaa", int_prop=None)
    m1.put()
    m2.put()

    resp1 = SimpleModel.query(
        SimpleModel.int_prop != None).fetch()  # noqa: E711
    assert resp1 == [m1]

    resp2 = SimpleModel.query(
        SimpleModel.int_prop == None).fetch()  # noqa: E711
    assert resp2 == [m2]
Пример #5
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
Пример #6
0
def test_put_model_matches_key_get() -> None:
    model = SimpleModel(id="test", str_prop="asdf")
    key = model.put()

    get_resp = key.get()
    assert get_resp == model
Пример #7
0
def test_put_model() -> None:
    model = SimpleModel(id="test", str_prop="asdf")
    key = model.put()

    assert key == model.key