Esempio n. 1
0
async def test_geo_not_exist_members(redis):
    res = await redis.geoadd('geodata', 13.361389, 38.115556, 'Palermo')
    assert res == 1

    res = await redis.geoadd(
        'geodata',
        15.087269, 37.502669, 'Catania',
        12.424315, 37.802105, 'Marsala'
    )
    assert res == 2

    res = await redis.geohash(
        'geodata', 'NotExistMember'
    )
    assert res == [None]

    res = await redis.geodist('geodata', 'NotExistMember', 'Catania')
    assert res is None

    res = await redis.geopos(
        'geodata', 'Palermo', 'NotExistMember', 'Catania'
    )
    assert res == [
        GeoPoint(
            longitude=13.36138933897018433,
            latitude=38.11555639549629859
        ),
        None,
        GeoPoint(longitude=15.087267458438873, latitude=37.50266842333162)
    ]
Esempio n. 2
0
async def test_georadiusbymember(redis):
    res = await redis.geoadd('geodata', 13.361389, 38.115556, 'Palermo',
                             15.087269, 37.502669, 'Catania')
    assert res == 2

    res = await redis.georadiusbymember('geodata',
                                        'Palermo',
                                        200,
                                        'km',
                                        with_dist=True,
                                        encoding='utf-8')
    assert res == [
        GeoMember(member='Palermo', dist=0.0, coord=None, hash=None),
        GeoMember(member='Catania', dist=166.2742, coord=None, hash=None)
    ]
    res = await redis.georadiusbymember('geodata',
                                        'Palermo',
                                        200,
                                        'km',
                                        encoding='utf-8')
    assert res == ['Palermo', 'Catania']

    res = await redis.georadiusbymember('geodata',
                                        'Palermo',
                                        200,
                                        'km',
                                        with_dist=True,
                                        with_coord=True,
                                        encoding='utf-8')
    assert res == [
        GeoMember(member='Palermo',
                  dist=0.0,
                  hash=None,
                  coord=GeoPoint(13.361389338970184, 38.1155563954963)),
        GeoMember(member='Catania',
                  dist=166.2742,
                  hash=None,
                  coord=GeoPoint(15.087267458438873, 37.50266842333162))
    ]

    res = await redis.georadiusbymember('geodata',
                                        'Palermo',
                                        200,
                                        'km',
                                        with_dist=True,
                                        with_coord=True,
                                        with_hash=True,
                                        encoding='utf-8')
    assert res == [
        GeoMember(member='Palermo',
                  dist=0.0,
                  hash=3479099956230698,
                  coord=GeoPoint(13.361389338970184, 38.1155563954963)),
        GeoMember(member='Catania',
                  dist=166.2742,
                  hash=3479447370796909,
                  coord=GeoPoint(15.087267458438873, 37.50266842333162))
    ]
Esempio n. 3
0
async def test_georadiusbymember_binary(redis):
    res = await redis.geoadd("geodata", 13.361389, 38.115556, "Palermo",
                             15.087269, 37.502669, "Catania")
    assert res == 2

    res = await redis.georadiusbymember("geodata",
                                        "Palermo",
                                        200,
                                        "km",
                                        with_dist=True)
    assert res == [
        GeoMember(member=b"Palermo", dist=0.0, coord=None, hash=None),
        GeoMember(member=b"Catania", dist=166.2742, coord=None, hash=None),
    ]

    res = await redis.georadiusbymember("geodata",
                                        "Palermo",
                                        200,
                                        "km",
                                        with_dist=True,
                                        with_coord=True)
    assert res == [
        GeoMember(
            member=b"Palermo",
            dist=0.0,
            hash=None,
            coord=GeoPoint(13.361389338970184, 38.1155563954963),
        ),
        GeoMember(
            member=b"Catania",
            dist=166.2742,
            hash=None,
            coord=GeoPoint(15.087267458438873, 37.50266842333162),
        ),
    ]

    res = await redis.georadiusbymember("geodata",
                                        "Palermo",
                                        200,
                                        "km",
                                        with_dist=True,
                                        with_coord=True,
                                        with_hash=True)
    assert res == [
        GeoMember(
            member=b"Palermo",
            dist=0.0,
            hash=3479099956230698,
            coord=GeoPoint(13.361389338970184, 38.1155563954963),
        ),
        GeoMember(
            member=b"Catania",
            dist=166.2742,
            hash=3479447370796909,
            coord=GeoPoint(15.087267458438873, 37.50266842333162),
        ),
    ]
Esempio n. 4
0
async def test_geopos(redis):
    res = await redis.geoadd('geodata', 13.361389, 38.115556, 'Palermo',
                             15.087269, 37.502669, 'Catania')
    assert res == 2

    res = await redis.geopos('geodata', 'Palermo')
    assert res == [
        GeoPoint(longitude=13.36138933897018433, latitude=38.11555639549629859)
    ]

    res = await redis.geopos('geodata', 'Catania', 'Palermo')
    assert res == [
        GeoPoint(longitude=15.087267458438873, latitude=37.50266842333162),
        GeoPoint(longitude=13.36138933897018433, latitude=38.11555639549629859)
    ]
Esempio n. 5
0
def fake_entity(fake_entity_cls):
    return fake_entity_cls(
        fake_id='fake',
        fake2_id='fake2',
        data=[
            GeoMember(
                member=b'm1',
                dist=0.0003,
                hash=None,
                coord=GeoPoint(6.000002324581146, 4.999999830436074),
            ),
            GeoMember(
                member=b'm2',
                dist=0.0003,
                hash=None,
                coord=GeoPoint(6.000002324581146, 4.999999830436074),
            ),
        ],
    )
Esempio n. 6
0
async def test_geo_not_exist_members(redis):
    res = await redis.geoadd("geodata", 13.361389, 38.115556, "Palermo")
    assert res == 1

    res = await redis.geoadd(
        "geodata", 15.087269, 37.502669, "Catania", 12.424315, 37.802105, "Marsala"
    )
    assert res == 2

    res = await redis.geohash("geodata", "NotExistMember")
    assert res == [None]

    res = await redis.geodist("geodata", "NotExistMember", "Catania")
    assert res is None

    res = await redis.geopos("geodata", "Palermo", "NotExistMember", "Catania")
    assert res == [
        GeoPoint(longitude=13.36138933897018433, latitude=38.11555639549629859),
        None,
        GeoPoint(longitude=15.087267458438873, latitude=37.50266842333162),
    ]
Esempio n. 7
0
async def test_should_exclude_all_attributes_from_indexes(repository):
    await repository.memory_data_source.delete('fakegeo:fake')
    client = repository.fallback_data_source.client
    key = client.key('fakegeo:fake', 'fake')
    entity = datastore.Entity(key=key)
    entity.update({'latitude': 1, 'longitude': 1, 'member': 'fake'})
    client.put(entity)

    assert not client.get(key).exclude_from_indexes
    entity = FakeGeoSpatialEntity(
        id='fake',
        data=GeoMember(member='fake',
                       dist=None,
                       hash=None,
                       coord=GeoPoint(1, 1)),
    )

    await repository.add(entity)

    assert client.get(key).exclude_from_indexes == set(
        FakeGeoSpatialRepository.exclude_from_indexes)
Esempio n. 8
0
async def test_georadius_binary(redis):
    res = await redis.geoadd(
        'geodata',
        13.361389, 38.115556, 'Palermo', 15.087269, 37.502669, 'Catania'
    )
    assert res == 2

    res = await redis.georadius(
        'geodata', 15, 37, 200, 'km'
    )
    assert res == [b'Palermo', b'Catania']

    res = await redis.georadius(
        'geodata', 15, 37, 200, 'km', count=1
    )
    assert res == [b'Catania']

    res = await redis.georadius(
        'geodata', 15, 37, 200, 'km', sort='ASC'
    )
    assert res == [b'Catania', b'Palermo']

    res = await redis.georadius(
        'geodata', 15, 37, 200, 'km', with_dist=True
    )
    assert res == [
        GeoMember(member=b'Palermo', dist=190.4424, coord=None, hash=None),
        GeoMember(member=b'Catania', dist=56.4413, coord=None, hash=None)
    ]

    res = await redis.georadius(
        'geodata', 15, 37, 200, 'km',
        with_dist=True, with_coord=True
    )
    assert res == [
        GeoMember(
            member=b'Palermo', dist=190.4424, hash=None,
            coord=GeoPoint(
                longitude=13.36138933897018433, latitude=38.11555639549629859
            )
        ),
        GeoMember(
            member=b'Catania', dist=56.4413, hash=None,
            coord=GeoPoint(
                longitude=15.087267458438873, latitude=37.50266842333162
            ),
        )
    ]

    res = await redis.georadius(
        'geodata', 15, 37, 200, 'km',
        with_dist=True, with_coord=True, with_hash=True
    )
    assert res == [
        GeoMember(
            member=b'Palermo', dist=190.4424, hash=3479099956230698,
            coord=GeoPoint(
                longitude=13.36138933897018433, latitude=38.11555639549629859
            )
        ),
        GeoMember(
            member=b'Catania', dist=56.4413, hash=3479447370796909,
            coord=GeoPoint(
                longitude=15.087267458438873, latitude=37.50266842333162
            ),
        )
    ]

    res = await redis.georadius(
        'geodata', 15, 37, 200, 'km',
        with_coord=True, with_hash=True
    )
    assert res == [
        GeoMember(
            member=b'Palermo', dist=None, hash=3479099956230698,
            coord=GeoPoint(
                longitude=13.36138933897018433, latitude=38.11555639549629859
            )
        ),
        GeoMember(
            member=b'Catania', dist=None, hash=3479447370796909,
            coord=GeoPoint(
                longitude=15.087267458438873, latitude=37.50266842333162
            ),
        )
    ]

    res = await redis.georadius(
        'geodata', 15, 37, 200, 'km', with_coord=True
    )
    assert res == [
        GeoMember(
            member=b'Palermo', dist=None, hash=None,
            coord=GeoPoint(
                longitude=13.36138933897018433, latitude=38.11555639549629859
            )
        ),
        GeoMember(
            member=b'Catania', dist=None, hash=None,
            coord=GeoPoint(
                longitude=15.087267458438873, latitude=37.50266842333162
            ),
        )
    ]

    res = await redis.georadius(
        'geodata', 15, 37, 200, 'km', count=1, sort='DESC',
        with_hash=True
    )
    assert res == [
        GeoMember(
            member=b'Palermo', dist=None, hash=3479099956230698, coord=None
        )
    ]
Esempio n. 9
0
async def test_georadius_binary(redis):
    res = await redis.geoadd(
        "geodata", 13.361389, 38.115556, "Palermo", 15.087269, 37.502669, "Catania"
    )
    assert res == 2

    res = await redis.georadius("geodata", 15, 37, 200, "km")
    assert res == [b"Palermo", b"Catania"]

    res = await redis.georadius("geodata", 15, 37, 200, "km", count=1)
    assert res == [b"Catania"]

    res = await redis.georadius("geodata", 15, 37, 200, "km", sort="ASC")
    assert res == [b"Catania", b"Palermo"]

    res = await redis.georadius("geodata", 15, 37, 200, "km", with_dist=True)
    assert res == [
        GeoMember(member=b"Palermo", dist=190.4424, coord=None, hash=None),
        GeoMember(member=b"Catania", dist=56.4413, coord=None, hash=None),
    ]

    res = await redis.georadius(
        "geodata", 15, 37, 200, "km", with_dist=True, with_coord=True
    )
    assert res == [
        GeoMember(
            member=b"Palermo",
            dist=190.4424,
            hash=None,
            coord=GeoPoint(
                longitude=13.36138933897018433, latitude=38.11555639549629859
            ),
        ),
        GeoMember(
            member=b"Catania",
            dist=56.4413,
            hash=None,
            coord=GeoPoint(longitude=15.087267458438873, latitude=37.50266842333162),
        ),
    ]

    res = await redis.georadius(
        "geodata", 15, 37, 200, "km", with_dist=True, with_coord=True, with_hash=True
    )
    assert res == [
        GeoMember(
            member=b"Palermo",
            dist=190.4424,
            hash=3479099956230698,
            coord=GeoPoint(
                longitude=13.36138933897018433, latitude=38.11555639549629859
            ),
        ),
        GeoMember(
            member=b"Catania",
            dist=56.4413,
            hash=3479447370796909,
            coord=GeoPoint(longitude=15.087267458438873, latitude=37.50266842333162),
        ),
    ]

    res = await redis.georadius(
        "geodata", 15, 37, 200, "km", with_coord=True, with_hash=True
    )
    assert res == [
        GeoMember(
            member=b"Palermo",
            dist=None,
            hash=3479099956230698,
            coord=GeoPoint(
                longitude=13.36138933897018433, latitude=38.11555639549629859
            ),
        ),
        GeoMember(
            member=b"Catania",
            dist=None,
            hash=3479447370796909,
            coord=GeoPoint(longitude=15.087267458438873, latitude=37.50266842333162),
        ),
    ]

    res = await redis.georadius("geodata", 15, 37, 200, "km", with_coord=True)
    assert res == [
        GeoMember(
            member=b"Palermo",
            dist=None,
            hash=None,
            coord=GeoPoint(
                longitude=13.36138933897018433, latitude=38.11555639549629859
            ),
        ),
        GeoMember(
            member=b"Catania",
            dist=None,
            hash=None,
            coord=GeoPoint(longitude=15.087267458438873, latitude=37.50266842333162),
        ),
    ]

    res = await redis.georadius(
        "geodata", 15, 37, 200, "km", count=1, sort="DESC", with_hash=True
    )
    assert res == [
        GeoMember(member=b"Palermo", dist=None, hash=3479099956230698, coord=None)
    ]