def test_query(config):
    p = ElasticsearchProvider(config)

    fields = p.get_fields()
    assert len(fields) == 37
    assert fields['scalerank'] == 'long'
    assert fields['changed'] == 'float'
    assert fields['ls_name'] == 'string'

    results = p.query()
    assert len(results['features']) == 10
    assert results['numberMatched'] == 242
    assert results['numberReturned'] == 10
    assert results['features'][0]['id'] == 6691831
    assert results['features'][0]['properties']['nameascii'] == 'Vatican City'

    results = p.query(properties=[('nameascii', 'Vatican City')])
    assert len(results['features']) == 4
    assert results['numberMatched'] == 4
    assert results['numberReturned'] == 4

    results = p.query(limit=1)
    assert len(results['features']) == 1
    assert results['features'][0]['id'] == 6691831

    results = p.query(startindex=2, limit=1)
    assert len(results['features']) == 1
    assert results['features'][0]['id'] == 3168070

    results = p.query(sortby=[{'property': 'nameascii', 'order': 'A'}])
    assert results['features'][0]['properties']['nameascii'] == 'Abidjan'

    results = p.query(sortby=[{'property': 'nameascii', 'order': 'D'}])
    assert results['features'][0]['properties']['nameascii'] == 'Zagreb'

    results = p.query(sortby=[{'property': 'scalerank', 'order': 'A'}])
    assert results['features'][0]['properties']['scalerank'] == 0

    results = p.query(sortby=[{'property': 'scalerank', 'order': 'D'}])
    assert results['features'][0]['properties']['scalerank'] == 8

    assert len(results['features'][0]['properties']) == 37

    results = p.query(sortby=[{
        'property': 'nameascii',
        'order': 'D'
    }],
                      limit=10001)
    assert results['features'][0]['properties']['nameascii'] == 'Zagreb'
    assert len(results['features']) == 242
    assert results['numberMatched'] == 242
    assert results['numberReturned'] == 242

    config['properties'] = ['nameascii']
    p = ElasticsearchProvider(config)
    results = p.query()
    assert len(results['features'][0]['properties']) == 1
def test_post_cql_json_intersects_query(config, intersects):
    """Testing cql json query for an intersects object"""
    p = ElasticsearchProvider(config)

    results = p.query(limit=100, filterq=intersects)

    assert len(results['features']) == 2
def test_post_cql_json_and_query(config, _and):
    """Testing cql json query for an and object"""
    p = ElasticsearchProvider(config)

    results = p.query(limit=1000, filterq=_and)

    assert len(results['features']) == 77
def test_post_cql_json_eq_query(config, eq):
    """Testing cql json query for an eq object"""
    p = ElasticsearchProvider(config)

    results = p.query(limit=500, filterq=eq)

    assert len(results['features']) == 235
Exemple #5
0
def test_get(config):
    p = ElasticsearchProvider(config)
    results = p.get('404')
    assert results is None

    result = p.get('3413829')
    assert result['id'] == 3413829
    assert result['properties']['ls_name'] == 'Reykjavik'
def test_post_cql_json_between_gte_query(config, between_lower):
    """Testing cql json query for a between object"""
    p = ElasticsearchProvider(config)

    results = p.query(limit=500, filterq=between_lower)

    assert len(results['features']) == 237
    assert results['numberMatched'] == 237
    assert results['numberReturned'] == 237

    for item in results['features']:
        assert 10000 <= item["properties"]["pop_max"]
Exemple #7
0
def test_query(config):
    p = ElasticsearchProvider(config)
    results = p.query()
    assert len(results['features']) == 10
    assert results['numberMatched'] == 242
    assert results['numberReturned'] == 10
    assert results['features'][0]['id'] == 6691831
    assert results['features'][0]['properties']['nameascii'] == 'Vatican City'

    results = p.query(properties=[('nameascii', 'Vatican City')])
    assert len(results['features']) == 4
    assert results['numberMatched'] == 4
    assert results['numberReturned'] == 4

    results = p.query(limit=1)
    assert len(results['features']) == 1
    assert results['features'][0]['id'] == 6691831

    results = p.query(startindex=2, limit=1)
    assert len(results['features']) == 1
    assert results['features'][0]['id'] == 1559804

    results = p.query(sortby=[{'property': 'nameascii', 'order': 'A'}])
    assert results['features'][0]['properties']['nameascii'] == 'Abidjan'

    results = p.query(sortby=[{'property': 'nameascii', 'order': 'D'}])
    assert results['features'][0]['properties']['nameascii'] == 'Zagreb'

    results = p.query(sortby=[{'property': 'scalerank', 'order': 'A'}])
    assert results['features'][0]['properties']['scalerank'] == 0

    results = p.query(sortby=[{'property': 'scalerank', 'order': 'D'}])
    assert results['features'][0]['properties']['scalerank'] == 8

    assert len(results['features'][0]['properties']) == 37

    config['properties'] = ['nameascii']
    p = ElasticsearchProvider(config)
    results = p.query()
    assert len(results['features'][0]['properties']) == 1
def test_query(config):
    p = ElasticsearchProvider(config)
    results = p.query()
    assert len(results['features']) == 10
    assert results['numberMatched'] == 242
    assert results['numberReturned'] == 10
    assert results['features'][0]['ID'] == 6691831
    assert results['features'][0]['properties']['nameascii'] == 'Vatican City'

    results = p.query(properties=[('nameascii', 'Vatican City')])
    assert len(results['features']) == 4
    assert results['numberMatched'] == 4
    assert results['numberReturned'] == 4

    results = p.query(limit=1)
    assert len(results['features']) == 1
    assert results['features'][0]['ID'] == 6691831

    results = p.query(startindex=2, limit=1)
    assert len(results['features']) == 1
    assert results['features'][0]['ID'] == 1559804
def test_get_not_existing_item_raise_exception(config):
    """Testing query for a not existing object"""
    p = ElasticsearchProvider(config)
    with pytest.raises(ProviderItemNotFoundError):
        p.get('404')
def test_query(config):
    p = ElasticsearchProvider(config)

    fields = p.get_fields()
    assert len(fields) == 37
    assert fields['scalerank']['type'] == 'long'
    assert fields['changed']['type'] == 'number'
    assert fields['changed']['format'] == 'float'
    assert fields['ls_name']['type'] == 'string'

    results = p.query()
    assert len(results['features']) == 10
    assert results['numberMatched'] == 242
    assert results['numberReturned'] == 10
    assert results['features'][0]['id'] == 6691831
    assert results['features'][0]['properties']['nameascii'] == 'Vatican City'

    results = p.query(properties=[('nameascii', 'Vatican City')])
    assert len(results['features']) == 1
    assert results['numberMatched'] == 1
    assert results['numberReturned'] == 1

    results = p.query(limit=1)
    assert len(results['features']) == 1
    assert results['features'][0]['id'] == 6691831

    results = p.query(startindex=2, limit=1)
    assert len(results['features']) == 1
    assert results['features'][0]['id'] == 3042030

    results = p.query(sortby=[{'property': 'nameascii', 'order': '+'}])
    assert results['features'][0]['properties']['nameascii'] == 'Abidjan'

    results = p.query(sortby=[{'property': 'nameascii', 'order': '-'}])
    assert results['features'][0]['properties']['nameascii'] == 'Zagreb'

    results = p.query(sortby=[{'property': 'scalerank', 'order': '+'}])
    assert results['features'][0]['properties']['scalerank'] == 0

    results = p.query(sortby=[{'property': 'scalerank', 'order': '-'}])
    assert results['features'][0]['properties']['scalerank'] == 8

    assert len(results['features'][0]['properties']) == 37

    results = p.query(sortby=[{'property': 'nameascii', 'order': '-'}],
                      limit=10001)
    assert results['features'][0]['properties']['nameascii'] == 'Zagreb'
    assert len(results['features']) == 242
    assert results['numberMatched'] == 242
    assert results['numberReturned'] == 242

    results = p.query(select_properties=['nameascii'])
    assert len(results['features'][0]['properties']) == 2

    results = p.query(select_properties=['nameascii', 'scalerank'])
    assert len(results['features'][0]['properties']) == 3

    results = p.query(skip_geometry=True)
    assert results['features'][0]['geometry'] is None

    config['properties'] = ['nameascii']
    p = ElasticsearchProvider(config)
    results = p.query()
    assert len(results['features'][0]['properties']) == 1