Example #1
0
def test_update(config):
    p = MongoProvider(config)
    init(p)

    new_feature = {
        'type': 'Feature',
        'geometry': {
            'type': 'Point',
            'coordinates': [0.0, 0.0]},
        'properties': {
            'name': 'Unit Test Island'}}

    p.create(new_feature)

    res = p.query(properties=[('name', 'Unit Test Island')])
    assert len(res['features']) == 1

    updated_feature = {
        'type': 'Feature',
        'geometry': {
            'type': 'Point',
            'coordinates': [0.0, 0.0]},
        'properties': {
            'name': 'Null Island'
        }
    }

    p.update(res['features'][0]['id'], updated_feature)

    # Should be changed
    results = p.get(res['features'][0]['id'])
    assert 'Null Island' in results['properties']['name']
    delete_by_name(p, 'Null Island')
Example #2
0
def test_update_safe_id(config):
    p = MongoProvider(config)
    init(p)

    new_feature = {
        'type': 'Feature',
        'geometry': {
            'type': 'Point',
            'coordinates': [0.0, 0.0]
        },
        'properties': {
            'name': 'Unit Test Island'
        }
    }

    p.create(new_feature)

    updated_feature = {
        'type': 'Feature',
        'geometry': {
            'type': 'Point',
            'coordinates': [0.0, 0.0]
        },
        'properties': {
            'name': 'Null Island',
        },
        'id': '123456789012345678901234'
    }

    res = p.query(properties=[('name', 'Unit Test Island')])
    assert len(res['features']) == 1
    p.update(res['features'][0]['id'], updated_feature)

    # Don't let the id change, should not exist
    with pytest.raises(ProviderItemNotFoundError):
        p.get('123456789012345678901234')

    # Should still be at the old id
    results = p.get(res['features'][0]['id'])
    assert 'Null Island' in results['properties']['name']
    delete_by_name(p, 'Null Island')