Esempio n. 1
0
 def _callback_coord_each(
     coord, coord_index, feature_index, multi_feature_index, geometry_index
 ):
     nonlocal pivot, angle
     initial_angle = rhumb_bearing(GeoPoint(pivot), GeoPoint(coord))
     final_angle = initial_angle + angle
     distance = rhumb_distance(GeoPoint(pivot), GeoPoint(coord))
     new_coords = get_coord(rhumb_destination(GeoPoint(pivot), distance, final_angle))
     coord[0] = new_coords[0]
     coord[1] = new_coords[1]
Esempio n. 2
0
 def _callback_coord_each(
     coord, coord_index, feature_index, multi_feature_index, geometry_index
 ):
     nonlocal factor, origin
     original_distance = rhumb_distance(GeoPoint(origin), GeoPoint(coord))
     bearing = rhumb_bearing(GeoPoint(origin), GeoPoint(coord))
     new_distance = original_distance * factor
     new_coord = get_coord(rhumb_destination(GeoPoint(origin), new_distance, bearing))
     coord[0] = new_coord[0]
     coord[1] = new_coord[1]
     if len(coord) == 3:
         coord[2] = coord[2] * factor
Esempio n. 3
0
def test_map_delete_private(app, db):
    m = Map('foo', bbox=[1, 1, 1, 1])
    db.session.add(m)
    db.session.commit()

    token = m.gen_token()
    resp = _get_map(app, m.uuid, token)
    assert (resp.status_code == 200)

    with app.test_client() as client:
        point = GeoFeature(geometry=GeoPoint([1, 1]))
        f = Feature(point)
        m.features.append(f)
        db.session.add(m)
        db.session.commit()

        url = '/api/maps/{}'.format(m.uuid)
        resp = client.delete(url)
        assert (resp.status_code == 401
                )  # TODO: should be 404 for private maps

        headers = {'X-MAP': m.uuid, 'X-TOKEN': token}
        resp = client.delete(url, headers=headers)
        assert (resp.status_code == 204)

    assert (not Map.get(m.uuid))
    resp = _get_map(app, m.uuid, token)
    assert (resp.status_code == 404)
Esempio n. 4
0
 def _callback_coord_each(coord, coord_index, feature_index,
                          multi_feature_index, geometry_index):
     nonlocal distance, direction, units, z_translation
     new_coords = get_coord(
         rhumb_destination(GeoPoint(coord), distance, direction,
                           {"units": units}))
     coord[0] = new_coords[0]
     coord[1] = new_coords[1]
     if z_translation and len(coord) == 3:
         coord[2] += z_translation
Esempio n. 5
0
def test_live(app, db):
    with app.test_client() as client:
        m = Map('foo', bbox=[1, 1, 1, 1])
        db.session.add(m)
        db.session.commit()
        uuid = m.uuid.hex

        from app.live import socketio
        socketio_client = socketio.test_client(app, flask_test_client=client)
        socketio_client.emit('join', uuid)
        assert socketio_client.is_connected()

        r = socketio_client.get_received()
        assert (len(r) == 1)
        assert (r[0]['name'] == 'message')
        assert (r[0]['args'] == 'user joined')

        m.name = 'bar'
        db.session.add(m)
        db.session.commit()

        r = socketio_client.get_received()
        assert (len(r) == 1)
        assert (r[0]['name'] == 'map-updated')

        point = GeoFeature(geometry=GeoPoint([1, 1]))
        f = Feature(point)
        db.session.add(m)
        m.features.append(f)
        db.session.commit()

        r = socketio_client.get_received()
        assert (len(r) == 1)
        assert (r[0]['name'] == 'feature-created')

        f.style = {'color': 'red'}
        db.session.add(f)
        db.session.commit()

        r = socketio_client.get_received()
        assert (len(r) == 1)
        assert (r[0]['name'] == 'feature-updated')

        db.session.delete(m)
        db.session.commit()

        r = socketio_client.get_received()
        assert (len(r) == 2)
        assert (r[0]['name'] == 'map-deleted')
        assert (r[1]['name'] == 'feature-deleted')
Esempio n. 6
0
def test_feature(app, db):
    assert (_count_maps(app) == 0)
    name = 'foo'
    uuid, token = _create_map(app, {'name': name, 'bbox': [1, 1, 1, 1]})
    assert (_count_maps(app) == 0)

    # add feature
    with app.test_client() as client:
        url = '/api/maps/{}/features'.format(uuid)
        json = GeoFeature(geometry=GeoPoint([1, 1]))
        headers = {'X-MAP': uuid, 'X-TOKEN': token}
        resp = client.post(url, json=json, headers=headers)
        assert (resp.status_code == 201)

    resp = _update_map(app, uuid, token, {'published': True})
    assert (resp.json['published'])

    assert (_count_maps(app) == 1)