Exemplo n.º 1
0
def test_get_representations_of_kind(dispose_of):
    from google.cloud.ndb.metadata import get_representations_of_kind

    class AnyKind(ndb.Model):
        foo = ndb.IntegerProperty()
        bar = ndb.StringProperty()
        baz = ndb.IntegerProperty()
        qux = ndb.StringProperty()

    entity1 = AnyKind(foo=1, bar="x", baz=3, qux="y")
    entity1.put()
    dispose_of(entity1.key._key)

    representations = eventually(
        lambda: get_representations_of_kind("AnyKind"), _length_at_least(4))

    assert representations == {
        "bar": ["STRING"],
        "baz": ["INT64"],
        "foo": ["INT64"],
        "qux": ["STRING"],
    }

    representations = get_representations_of_kind("AnyKind", start="c")
    assert representations == {"foo": ["INT64"], "qux": ["STRING"]}

    representations = get_representations_of_kind("AnyKind", end="e")
    assert representations == {"bar": ["STRING"], "baz": ["INT64"]}

    representations = get_representations_of_kind("AnyKind",
                                                  start="c",
                                                  end="p")
    assert representations == {"foo": ["INT64"]}
Exemplo n.º 2
0
def test_get_representations_of_kind_with_end(Query, _datastore_query):
    future = tasklets.Future("fetch")
    future.set_result([])
    _datastore_query.fetch.return_value = future
    query = Query.return_value
    reps = metadata.get_representations_of_kind("AnyKind", end="z")
    assert reps == {}
    query.filter.assert_called_once()
Exemplo n.º 3
0
    def query_metadata():
        representations = get_representations_of_kind("AnyKind")
        assert representations == {
            "bar": ["STRING"],
            "baz": ["INT64"],
            "foo": ["INT64"],
            "qux": ["STRING"],
        }

        representations = get_representations_of_kind("AnyKind", start="c")
        assert representations == {"foo": ["INT64"], "qux": ["STRING"]}

        representations = get_representations_of_kind("AnyKind", end="e")
        assert representations == {"bar": ["STRING"], "baz": ["INT64"]}

        representations = get_representations_of_kind("AnyKind",
                                                      start="c",
                                                      end="p")
        assert representations == {"foo": ["INT64"]}
Exemplo n.º 4
0
def test_get_representations_of_kind_with_results(_datastore_query):
    class MyProp:
        property_name = "myprop"
        property_representation = "STR"

    myprop = MyProp()
    future = tasklets.Future("fetch")
    future.set_result([myprop])
    _datastore_query.fetch.return_value = future
    reps = metadata.get_representations_of_kind("MyModel")
    assert reps == {"myprop": "STR"}
Exemplo n.º 5
0
def test_get_representations_of_kind_empty_end(_datastore_query):
    future = tasklets.Future("fetch")
    future.set_result([])
    _datastore_query.fetch.return_value = future
    reps = metadata.get_representations_of_kind("AnyKind", end="")
    assert reps == {}
Exemplo n.º 6
0
def test_get_representations_of_kind():
    with pytest.raises(NotImplementedError):
        metadata.get_representations_of_kind()
Exemplo n.º 7
0
def test_get_representations_of_kind():
    with pytest.raises(NotImplementedError):
        metadata.get_representations_of_kind()