Esempio n. 1
0
def test_get_namespaces(dispose_of):
    from google.cloud.ndb.metadata import get_namespaces

    class AnyKind(ndb.Model):
        foo = ndb.IntegerProperty()

    entity1 = AnyKind(foo=1, namespace="CoolNamespace")
    entity1.put()
    dispose_of(entity1.key._key)

    entity2 = AnyKind(foo=2, namespace="MyNamespace")
    entity2.put()
    dispose_of(entity2.key._key)

    entity3 = AnyKind(foo=3, namespace="OtherNamespace")
    entity3.put()
    dispose_of(entity3.key._key)

    names = eventually(get_namespaces, _length_at_least(3))
    assert (all(name in names
                for name in ["CoolNamespace", "MyNamespace", "OtherNamespace"])
            != [])

    names = get_namespaces(start="L")
    assert (all(name in names
                for name in ["MyNamespace", "OtherNamspace"]) != [])

    names = get_namespaces(end="N")
    assert (all(name in names
                for name in ["CoolNamespace", "MyNamespace"]) != [])

    names = get_namespaces(start="D", end="N")
    assert all(name in names for name in ["MyNamespace"]) != []
Esempio n. 2
0
    def query_metadata():
        names = get_namespaces()
        assert all(
            name in names
            for name in ["CoolNamespace", "MyNamespace", "OtherNamespace"])

        names = get_namespaces(start="L")
        assert all(name in names
                   for name in ["MyNamespace", "OtherNamspace"]) != []

        names = get_namespaces(end="N")
        assert all(name in names
                   for name in ["CoolNamespace", "MyNamespace"]) != []

        names = get_namespaces(start="D", end="N")
        assert all(name in names for name in ["MyNamespace"]) != []
Esempio n. 3
0
def test_get_namespaces_with_end(Query, _datastore_query):
    future = tasklets.Future("fetch")
    future.set_result([])
    _datastore_query.fetch.return_value = future
    query = Query.return_value
    names = metadata.get_namespaces(end="z")
    assert names == []
    query.filter.assert_called_once()
Esempio n. 4
0
def test_get_namespaces(_datastore_query):
    future = tasklets.Future("fetch")
    future.set_result([])
    _datastore_query.fetch.return_value = future
    names = metadata.get_namespaces()
    assert names == []
Esempio n. 5
0
def test_get_namespaces():
    with pytest.raises(NotImplementedError):
        metadata.get_namespaces()
Esempio n. 6
0
def test_get_namespaces():
    with pytest.raises(NotImplementedError):
        metadata.get_namespaces()